interface

AuthStore

Persistence required by auth-enabled collections.

Properties

PropertyTypeDescription
SetPasswordHashfunc(context.Context, schema.Collection, string, []byte, bool) errorSetPasswordHash replaces a user-controlled password and atomically revokes every session and API key for that user.
ChangePasswordHashfunc(context.Context, schema.Collection, string, []byte, []byte) errorChangePasswordHash replaces a password only while its exact stored hash is the hash verified by the caller. A successful change revokes every session and API key. Exact hash comparison also fences hard-delete/same-ID credential recreation because bcrypt salts make each incarnation unique.
UpgradePasswordHashfunc(context.Context, schema.Collection, string, []byte, []byte) errorUpgradePasswordHash raises the hash work factor after a successful login without revoking otherwise-valid sessions. The exact-hash compare-and-set prevents a slow bcrypt upgrade from overwriting a concurrent reset.
FindAuthCredentialfunc(context.Context, schema.Collection, string) (AuthCredential, error)The FindAuthCredential value.
RecordFailedLoginfunc(context.Context, schema.StableID, string, time.Time, int, time.Duration) (AuthCredential, error)The RecordFailedLogin value.
ResetLoginAttemptsfunc(context.Context, schema.StableID, string, time.Time) (bool, error)The ResetLoginAttempts value.
CreateSessionfunc(context.Context, AuthSession, []byte) errorCreateSession atomically verifies the exact password hash observed by password authentication before persisting the new bearer session.
RotateSessionfunc(context.Context, string, AuthSession, time.Time) errorThe RotateSession value.
DeleteSessionfunc(context.Context, string) errorThe DeleteSession value.
DeleteUserSessionfunc(context.Context, schema.StableID, string, string) errorThe DeleteUserSession value.
DeleteUserSessionsfunc(context.Context, schema.StableID, string) errorThe DeleteUserSessions value.
FindSessionfunc(context.Context, string, time.Time) (AuthSession, error)The FindSession value.
FindSessionByIDfunc(context.Context, string, time.Time) (AuthSession, error)FindSessionByID resolves an unexpired session by its public ID. It lets a short-lived capability name its session without carrying the token.
ListSessionsfunc(context.Context, schema.StableID, string, time.Time) ([]AuthSession, error)The ListSessions value.
CreateAuthTokenfunc(context.Context, AuthToken) errorThe CreateAuthToken value.
ResetPasswordWithTokenfunc(context.Context, schema.StableID, string, []byte, time.Time) (string, error)The ResetPasswordWithToken value.
VerifyEmailWithTokenfunc(context.Context, schema.StableID, string, time.Time) (string, error)The VerifyEmailWithToken value.
CreateAPIKeyfunc(context.Context, AuthAPIKey, string, time.Time) errorCreateAPIKey inserts the key only while the authorizing session remains active. Password replacement serializes through the same credential row and cannot leave a late-created key behind.
FindAPIKeyfunc(context.Context, string, time.Time) (AuthAPIKey, error)The FindAPIKey value.
TouchAPIKeyfunc(context.Context, string, time.Time) errorThe TouchAPIKey value.
ListAPIKeysfunc(context.Context, schema.StableID, string, time.Time) ([]AuthAPIKey, error)The ListAPIKeys value.
DeleteAPIKeyfunc(context.Context, schema.StableID, string, string) errorThe DeleteAPIKey value.
AllowAuthAttemptfunc(context.Context, string, time.Time, time.Duration, int) (bool, error)The AllowAuthAttempt value.

How it works

Implementations must make failed-attempt updates and session rotation atomic across processes. Password hashes and token digests are private state and never enter document values, hooks, manifests, or protocol responses. AuthTransaction and AuthBootstrapTransaction bind credential creation to content transactions.

Full signature

type AuthStore interface { // SetPasswordHash replaces a user-controlled password and atomically revokes // every session and API key for that user. SetPasswordHash(context.Context, schema.Collection, string, []byte, bool) error // ChangePasswordHash replaces a password only while its exact stored hash is // the hash verified by the caller. A successful change revokes every session // and API key. Exact hash comparison also fences hard-delete/same-ID // credential recreation because bcrypt salts make each incarnation unique. ChangePasswordHash(context.Context, schema.Collection, string, []byte, []byte) error // UpgradePasswordHash raises the hash work factor after a successful login // without revoking otherwise-valid sessions. The exact-hash compare-and-set // prevents a slow bcrypt upgrade from overwriting a concurrent reset. UpgradePasswordHash(context.Context, schema.Collection, string, []byte, []byte) error FindAuthCredential(context.Context, schema.Collection, string) (AuthCredential, error) RecordFailedLogin( context.Context, schema.StableID, string, time.Time, int, time.Duration, ) (AuthCredential, error) ResetLoginAttempts(context.Context, schema.StableID, string, time.Time) (bool, error) // CreateSession atomically verifies the exact password hash observed by // password authentication before persisting the new bearer session. CreateSession(context.Context, AuthSession, []byte) error RotateSession(context.Context, string, AuthSession, time.Time) error DeleteSession(context.Context, string) error DeleteUserSession(context.Context, schema.StableID, string, string) error DeleteUserSessions(context.Context, schema.StableID, string) error FindSession(context.Context, string, time.Time) (AuthSession, error) // FindSessionByID resolves an unexpired session by its public ID. It lets a // short-lived capability name its session without carrying the token. FindSessionByID(context.Context, string, time.Time) (AuthSession, error) ListSessions(context.Context, schema.StableID, string, time.Time) ([]AuthSession, error) CreateAuthToken(context.Context, AuthToken) error ResetPasswordWithToken(context.Context, schema.StableID, string, []byte, time.Time) (string, error) VerifyEmailWithToken(context.Context, schema.StableID, string, time.Time) (string, error) // CreateAPIKey inserts the key only while the authorizing session remains // active. Password replacement serializes through the same credential row // and therefore cannot leave a late-created key behind. CreateAPIKey(context.Context, AuthAPIKey, string, time.Time) error FindAPIKey(context.Context, string, time.Time) (AuthAPIKey, error) TouchAPIKey(context.Context, string, time.Time) error ListAPIKeys(context.Context, schema.StableID, string, time.Time) ([]AuthAPIKey, error) DeleteAPIKey(context.Context, schema.StableID, string, string) error AllowAuthAttempt(context.Context, string, time.Time, time.Duration, int) (bool, error) }

Source store/store.go:727