session

package
v1.0.0-alpha.21 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const UserAgentFingerprintKey = "fingerprint"

UserAgentFingerprintKey is the user_agents.info JSON key for the browser fingerprint (UserAgent.ID).

Variables

This section is empty.

Functions

func AppendFactor

func AppendFactor(sess *domain.Session, factor domain.AuthFactor)

AppendFactor replaces an existing factor of the same class or appends a new one. Factors are normalized on the way in (NormalizeSessionFactor), so a promoted enrollment lands as a passkey factor and never coexists with a login factor for the same class.

func ClassMembers

func ClassMembers(t domain.AuthCheckType) []domain.AuthCheckType

ClassMembers lists the check types competing in t's class (see domain.AuthCheckType.Class), for loser cleanup after a promotion.

func DecodeAuthChecks

func DecodeAuthChecks(
	checkType domain.AuthCheckType,
	id string,
	lastChallengedAt, lastFailedAt, verifiedAt time.Time,
	failureCount uint16,
	challenge, factor json.RawMessage,
) ([]domain.AuthCheck, error)

DecodeAuthChecks builds domain auth checks from a stored checks row.

func ExchangeTTL

func ExchangeTTL(ttl time.Duration) time.Duration

ExchangeTTL returns ttl when positive, otherwise SessionAnonymousTTL.

func HasRealSessionToken

func HasRealSessionToken(previousTokenID string) bool

HasRealSessionToken reports whether previousTokenID names a persisted token that should be revoked after rotation. Empty means the session has no token yet (sessions.token_id is NULL until CreateSessionToken links one).

func HashHandoffToken

func HashHandoffToken(plain string) []byte

HashHandoffToken returns the SHA-256 digest stored on auth_attempts.handoff_token.

func NormalizeSessionFactor

func NormalizeSessionFactor(check domain.AuthCheck) domain.AuthCheck

NormalizeSessionFactor maps a promoted enrollment factor to the passkey class. Sessions record HOW the user authenticated; the ceremony-level distinction between registering and asserting a credential stays on the attempt.

func PickLastVerifiedByType

func PickLastVerifiedByType(attemptChecks, sessionChecks []StoredCheck) map[domain.AuthCheckType]StoredCheck

PickLastVerifiedByType merges attempt and session verified checks, keeping the newest LastVerifiedAt per factor class (attempt wins ties that are strictly after).

func RunExchange

func RunExchange(ctx context.Context, store ExchangeStore, projectID, handoffToken string, ttl time.Duration) (*domain.Session, error)

RunExchange performs handoff-token exchange: validate attempt, resolve or create the target session, promote verified checks, rotate the session token, and delete the attempt. Dialects supply SQL via ExchangeStore.

func UserAgentFromStoredInfo

func UserAgentFromStoredInfo(info map[string]any) *domain.UserAgent

UserAgentFromStoredInfo reconstructs a UserAgent from the user_agents.info map.

func ValidateHandoffAttempt

func ValidateHandoffAttempt(attempt *domain.AuthAttempt) error

ValidateHandoffAttempt rejects missing, expired, or incomplete handoff state.

Types

type ExchangeStore

type ExchangeStore interface {
	GetAuthAttemptByHandoffToken(ctx context.Context, projectID string, handoffTokenHash []byte) (*domain.AuthAttempt, error)
	GetSessionByID(ctx context.Context, projectID, sessionID string) (*domain.Session, error)
	InsertSession(ctx context.Context, session *domain.Session) error
	LoadVerifiedChecks(ctx context.Context, projectID, id string, onAttempt bool) ([]StoredCheck, error)
	ApplyExchange(ctx context.Context, projectID, sessionID string, last map[domain.AuthCheckType]StoredCheck) error
	UserIDFromLastVerifiedChecks(ctx context.Context, projectID string, last map[domain.AuthCheckType]StoredCheck) (*string, error)
	UpdateSessionAfterExchange(ctx context.Context, projectID, sessionID string, userID *string, ttl time.Duration) error
	DeleteAuthAttempt(ctx context.Context, projectID, attemptID string) error
	CreateSessionToken(ctx context.Context, session *domain.Session, previousTokenID string) error
}

ExchangeStore is the dialect IO surface used by RunExchange.

type StoredCheck

type StoredCheck struct {
	ID             string
	Type           domain.AuthCheckType
	LastVerifiedAt time.Time
	OnAttempt      bool
}

StoredCheck is a verified check row used while merging attempt and session factors during Exchange.

Jump to

Keyboard shortcuts

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