Help us shape the future of Go! Take the 2026 Go Developer Survey

session

package
v2.17.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserSessionSourceLocal     = "local"
	UserSessionSourceOidc      = "oidc"
	UserSessionSourceFederated = "federated"
	UserSessionSourcePasskey   = "passkey"

	// 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 (s *SessionService) DeleteExpiredSessions(ctx context.Context, revokedRetention time.Duration) (int64, error)

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, 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             *user.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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL