Documentation
¶
Index ¶
- Constants
- func RevokeAllUserSessionsExceptInDB(ctx context.Context, db *gorm.DB, userID, exceptSessionID string) error
- func ValidateActive(userSession *UserSession) error
- type SessionService
- func (s *SessionService) CreateFederatedSession(ctx context.Context, userID string, expiresAt time.Time, credentialID string) (*UserSession, error)
- func (s *SessionService) CreateSession(ctx context.Context, userID string, expiresAt time.Time, meta auth.SessionMeta) (*UserSession, string, error)
- func (s *SessionService) DeleteExpiredSessions(ctx context.Context, revokedRetention time.Duration) (int64, error)
- func (s *SessionService) GetSessionByID(ctx context.Context, sessionID string) (*UserSession, error)
- func (s *SessionService) RevokeAllUserSessionsExcept(ctx context.Context, userID, exceptSessionID string) error
- func (s *SessionService) RevokeSession(ctx context.Context, sessionID string) error
- func (s *SessionService) RotateRefreshToken(ctx context.Context, sessionID string, refreshJTI string, ...) (*UserSession, string, error)
- type UserSession
Constants ¶
View Source
const ( UserSessionSourceLocal = "local" UserSessionSourceOidc = "oidc" UserSessionSourceFederated = "federated" UserSessionSourcePasskey = "passkey" )
View Source
const ( // PasskeyMFAMethod and RecoveryCodeMFAMethod name the second factor a login // completed with, recorded on the session for auditing. PasskeyMFAMethod = "passkey" RecoveryCodeMFAMethod = "recovery_code" )
Variables ¶
This section is empty.
Functions ¶
func RevokeAllUserSessionsExceptInDB ¶
func RevokeAllUserSessionsExceptInDB(ctx context.Context, db *gorm.DB, userID, exceptSessionID string) error
RevokeAllUserSessionsExceptInDB revokes sessions using the supplied transaction or database handle.
func ValidateActive ¶
func ValidateActive(userSession *UserSession) error
ValidateActive verifies that a persisted user session can still authorize requests.
Types ¶
type SessionService ¶
type SessionService struct {
// contains filtered or unexported fields
}
func NewSessionService ¶
func NewSessionService(db *database.DB) *SessionService
func (*SessionService) CreateFederatedSession ¶
func (s *SessionService) CreateFederatedSession(ctx context.Context, userID string, expiresAt time.Time, credentialID string) (*UserSession, error)
func (*SessionService) CreateSession ¶
func (s *SessionService) CreateSession(ctx context.Context, userID string, expiresAt time.Time, meta auth.SessionMeta) (*UserSession, string, error)
func (*SessionService) DeleteExpiredSessions ¶
func (*SessionService) GetSessionByID ¶
func (s *SessionService) GetSessionByID(ctx context.Context, sessionID string) (*UserSession, error)
func (*SessionService) RevokeAllUserSessionsExcept ¶
func (s *SessionService) RevokeAllUserSessionsExcept(ctx context.Context, userID, exceptSessionID string) error
RevokeAllUserSessionsExcept revokes every active session for userID, leaving exceptSessionID active. Pass "" to revoke all sessions.
func (*SessionService) RevokeSession ¶
func (s *SessionService) RevokeSession(ctx context.Context, sessionID string) error
func (*SessionService) RotateRefreshToken ¶
func (s *SessionService) RotateRefreshToken(ctx context.Context, sessionID string, refreshJTI string, meta auth.SessionMeta) (*UserSession, string, error)
type UserSession ¶ added in v2.8.1
type UserSession struct {
database.BaseModel
UserID string `json:"userId" gorm:"column:user_id;not null;index"`
User *common.User `json:"user,omitempty" gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE"`
RefreshTokenHash string `json:"-" gorm:"column:refresh_token_hash;not null;uniqueIndex"`
UserAgent *string `json:"userAgent,omitempty" gorm:"column:user_agent"`
IPAddress *string `json:"ipAddress,omitempty" gorm:"column:ip_address"`
Source string `json:"source,omitempty" gorm:"column:source"`
// FederatedCredentialID links federated sessions to their credential row;
// the FK (ON DELETE SET NULL) lives in the SQL migrations.
FederatedCredentialID *string `json:"federatedCredentialId,omitempty" gorm:"column:federated_credential_id;index"`
LastUsedAt time.Time `json:"lastUsedAt" gorm:"column:last_used_at;not null"`
ExpiresAt time.Time `json:"expiresAt" gorm:"column:expires_at;not null;index"`
RevokedAt *time.Time `json:"revokedAt,omitempty" gorm:"column:revoked_at"`
MFAMethod *string `json:"mfaMethod,omitempty" gorm:"column:mfa_method"`
MFAVerifiedAt *time.Time `json:"mfaVerifiedAt,omitempty" gorm:"column:mfa_verified_at"`
}
func (UserSession) TableName ¶ added in v2.8.1
func (UserSession) TableName() string
Click to show internal directories.
Click to hide internal directories.