Documentation
¶
Overview ¶
Package sqlite implements theauth storage on a caller-owned *sql.DB using the pure Go modernc.org/sqlite driver.
The caller owns the database and its pragmas: foreign keys must be on for every connection, and busy_timeout plus WAL mode are strongly advised. Schema is managed either by the host (via Migrations and RenderMigrations) or by this package (via Migrate).
Index ¶
- Constants
- Variables
- func Migrate(ctx context.Context, db *sql.DB, opts ...Option) error
- func Migrations() fs.FS
- type AuditChainBreak
- type AuditChainResult
- type DBTX
- type Migration
- type Option
- type Store
- func (s *Store) APITokenByHash(ctx context.Context, hash []byte) (*theauth.APIToken, error)
- func (s *Store) APITokenByID(ctx context.Context, id theauth.ULID) (*theauth.APIToken, error)
- func (s *Store) APITokensByAgentID(ctx context.Context, agentID theauth.ULID) ([]theauth.APIToken, error)
- func (s *Store) APITokensByOwner(ctx context.Context, ownerID theauth.ULID) ([]theauth.APIToken, error)
- func (s *Store) AccountStateByUserID(ctx context.Context, userID theauth.ULID) (theauth.AccountState, error)
- func (s *Store) AddGroupMembers(ctx context.Context, groupID theauth.ULID, userIDs []theauth.ULID) error
- func (s *Store) AdvanceTOTPStep(ctx context.Context, userID theauth.ULID, step int64) (bool, error)
- func (s *Store) AgentByClientID(ctx context.Context, clientID string) (*theauth.Agent, error)
- func (s *Store) AgentByID(ctx context.Context, id theauth.ULID) (*theauth.Agent, error)
- func (s *Store) AgentCredentialsByAgentID(ctx context.Context, agentID theauth.ULID) ([]theauth.AgentCredential, error)
- func (s *Store) AgentsByOwner(ctx context.Context, owner theauth.AgentOwner) ([]theauth.Agent, error)
- func (s *Store) AppendSessionAuthMethods(ctx context.Context, id theauth.ULID, methods []string, at time.Time) ([]string, time.Time, error)
- func (s *Store) ApproveToolApproval(ctx context.Context, id, approver string, now time.Time) (bool, error)
- func (s *Store) AtomicRotateJWKS(ctx context.Context, retireKIDs []string, demoteKID, promoteKID string, ...) error
- func (s *Store) BackchannelRequestByID(ctx context.Context, authReqID string) (theauth.BackchannelRequest, error)
- func (s *Store) ChainSupported() bool
- func (s *Store) ClaimDeviceCode(ctx context.Context, hash []byte, now time.Time) (*theauth.DeviceCode, error)
- func (s *Store) ConfirmTOTPSecret(ctx context.Context, userID theauth.ULID, at time.Time) error
- func (s *Store) ConsumeAuthorizationCode(ctx context.Context, code string) (*theauth.AuthorizationCode, error)
- func (s *Store) ConsumeDeviceAuthorization(ctx context.Context, id theauth.ULID, now time.Time) (bool, error)
- func (s *Store) ConsumeMagicLink(ctx context.Context, tokenHash []byte) (*theauth.MagicLink, error)
- func (s *Store) ConsumePasswordResetToken(ctx context.Context, tokenHash []byte) (*theauth.PasswordResetToken, error)
- func (s *Store) ConsumePushedRequest(ctx context.Context, requestURI string) ([]byte, error)
- func (s *Store) ConsumeRecoveryCode(ctx context.Context, userID theauth.ULID, code string, at time.Time) error
- func (s *Store) ConsumeSessionLink(ctx context.Context, tokenHash []byte, now time.Time) (*theauth.SessionLink, error)
- func (s *Store) ConsumeToolApproval(ctx context.Context, id, agentID, action, resource string, now time.Time) (bool, error)
- func (s *Store) CountUnusedRecoveryCodes(ctx context.Context, userID theauth.ULID) (int, error)
- func (s *Store) CountUsers(ctx context.Context) (int, error)
- func (s *Store) CountUsersWithPermissionInOrg(ctx context.Context, orgID theauth.ULID, perm string) (int, error)
- func (s *Store) CreateMagicLink(ctx context.Context, ml theauth.MagicLink) error
- func (s *Store) CreatePasswordResetToken(ctx context.Context, t theauth.PasswordResetToken) error
- func (s *Store) CreateSession(ctx context.Context, sess theauth.Session) (theauth.Session, error)
- func (s *Store) CreateSessionLink(ctx context.Context, l theauth.SessionLink) error
- func (s *Store) CreateSessionWithAuthLevel(ctx context.Context, sess theauth.Session) (theauth.Session, error)
- func (s *Store) CreateUser(ctx context.Context, u theauth.User) (theauth.User, error)
- func (s *Store) DecideDeviceAuthorization(ctx context.Context, id theauth.ULID, status string, userID theauth.ULID, ...) (bool, error)
- func (s *Store) DecideDeviceCode(ctx context.Context, userCode string, d theauth.DeviceDecision, now time.Time) error
- func (s *Store) DelegationGrantByID(ctx context.Context, id theauth.ULID) (*theauth.DelegationGrant, error)
- func (s *Store) DelegationGrantByUserAgentResource(ctx context.Context, userID, agentID theauth.ULID, resource string) (*theauth.DelegationGrant, error)
- func (s *Store) DelegationGrantsByAgentID(ctx context.Context, agentID theauth.ULID) ([]theauth.DelegationGrant, error)
- func (s *Store) DelegationGrantsByUserID(ctx context.Context, userID theauth.ULID) ([]theauth.DelegationGrant, error)
- func (s *Store) DeleteBackchannelRequest(ctx context.Context, authReqID string) error
- func (s *Store) DeleteExpiredDeviceAuthorizations(ctx context.Context, before time.Time) (int64, error)
- func (s *Store) DeleteExpiredDeviceCodes(ctx context.Context, before time.Time) (int, error)
- func (s *Store) DeleteGroup(ctx context.Context, id theauth.ULID) error
- func (s *Store) DeleteOAuthAccountByProvider(ctx context.Context, userID theauth.ULID, provider string) error
- func (s *Store) DeleteOAuthClient(ctx context.Context, clientID string) error
- func (s *Store) DeleteOrganization(ctx context.Context, id theauth.ULID) error
- func (s *Store) DeleteOrganizationMember(ctx context.Context, orgID, userID theauth.ULID) error
- func (s *Store) DeleteRole(ctx context.Context, id theauth.ULID) error
- func (s *Store) DeleteSAMLConnection(ctx context.Context, id theauth.ULID) error
- func (s *Store) DeleteTOTPSecret(ctx context.Context, userID theauth.ULID) error
- func (s *Store) DeleteUserCascade(ctx context.Context, userID theauth.ULID) error
- func (s *Store) DeleteWebAuthnCredential(ctx context.Context, id theauth.ULID, userID theauth.ULID) error
- func (s *Store) DenyAccessToken(ctx context.Context, jti string, expiresAt time.Time) error
- func (s *Store) DeviceAuthorizationByDeviceCodeHash(ctx context.Context, hash []byte) (*theauth.DeviceAuthorization, error)
- func (s *Store) DeviceAuthorizationByUserCodeHash(ctx context.Context, hash []byte) (*theauth.DeviceAuthorization, error)
- func (s *Store) DeviceByID(ctx context.Context, id theauth.ULID) (*theauth.Device, error)
- func (s *Store) DeviceCodeByHash(ctx context.Context, hash []byte) (*theauth.DeviceCode, error)
- func (s *Store) DeviceCodeByUserCode(ctx context.Context, userCode string) (*theauth.DeviceCode, error)
- func (s *Store) DeviceJoinTokenByHash(ctx context.Context, hash []byte) (*theauth.DeviceJoinToken, error)
- func (s *Store) DeviceJoinTokenByID(ctx context.Context, id theauth.ULID) (*theauth.DeviceJoinToken, error)
- func (s *Store) ExpireBackchannelRequests(ctx context.Context, now time.Time) (int64, error)
- func (s *Store) GrantUserRole(ctx context.Context, ur theauth.UserRole) error
- func (s *Store) GroupByExternalIDInOrg(ctx context.Context, orgID theauth.ULID, externalID string) (*theauth.Group, error)
- func (s *Store) GroupByID(ctx context.Context, id theauth.ULID) (*theauth.Group, error)
- func (s *Store) GroupMembers(ctx context.Context, groupID theauth.ULID) ([]theauth.ULID, error)
- func (s *Store) InsertAPIToken(ctx context.Context, t theauth.APIToken) (theauth.APIToken, error)
- func (s *Store) InsertAgent(ctx context.Context, a theauth.Agent) (theauth.Agent, error)
- func (s *Store) InsertAgentCredential(ctx context.Context, c theauth.AgentCredential) error
- func (s *Store) InsertAuditEvents(ctx context.Context, events []theauth.AuditEvent) error
- func (s *Store) InsertAuthorizationCode(ctx context.Context, c theauth.AuthorizationCode) error
- func (s *Store) InsertBackchannelRequest(ctx context.Context, req theauth.BackchannelRequest) error
- func (s *Store) InsertDelegationGrant(ctx context.Context, g theauth.DelegationGrant) (theauth.DelegationGrant, error)
- func (s *Store) InsertDevice(ctx context.Context, d theauth.Device) error
- func (s *Store) InsertDeviceAuthorization(ctx context.Context, d theauth.DeviceAuthorization) error
- func (s *Store) InsertDeviceCode(ctx context.Context, d theauth.DeviceCode) error
- func (s *Store) InsertDeviceJoinToken(ctx context.Context, t theauth.DeviceJoinToken) error
- func (s *Store) InsertGroup(ctx context.Context, g theauth.Group) (theauth.Group, error)
- func (s *Store) InsertJTI(ctx context.Context, jti string, expiresAt time.Time) error
- func (s *Store) InsertJWKSKey(ctx context.Context, k theauth.JWKSKey) error
- func (s *Store) InsertOAuthClient(ctx context.Context, c theauth.OAuthClient) (theauth.OAuthClient, error)
- func (s *Store) InsertOpaqueAccessToken(ctx context.Context, t theauth.OpaqueAccessToken) error
- func (s *Store) InsertOrganization(ctx context.Context, o theauth.Organization) (theauth.Organization, error)
- func (s *Store) InsertPermission(ctx context.Context, p theauth.Permission) (theauth.Permission, error)
- func (s *Store) InsertPushedRequest(ctx context.Context, requestURI string, payload []byte, expiresAt time.Time) error
- func (s *Store) InsertRecoveryCodes(ctx context.Context, codes []theauth.RecoveryCode) error
- func (s *Store) InsertRefreshToken(ctx context.Context, t theauth.RefreshToken) error
- func (s *Store) InsertRegistrationToken(ctx context.Context, t theauth.RegistrationToken) error
- func (s *Store) InsertRole(ctx context.Context, r theauth.Role) (theauth.Role, error)
- func (s *Store) InsertSAMLConnection(ctx context.Context, c theauth.SAMLConnection) (theauth.SAMLConnection, error)
- func (s *Store) InsertSCIMToken(ctx context.Context, t theauth.SCIMToken) (theauth.SCIMToken, error)
- func (s *Store) InsertTrustedDevice(ctx context.Context, d theauth.TrustedDevice) error
- func (s *Store) InsertWebAuthnCredential(ctx context.Context, c theauth.WebAuthnCredential) (theauth.WebAuthnCredential, error)
- func (s *Store) IsAccessTokenDenied(ctx context.Context, jti string) (bool, error)
- func (s *Store) JWKSKeyByKID(ctx context.Context, kid string) (*theauth.JWKSKey, error)
- func (s *Store) JWKSKeysAll(ctx context.Context) ([]theauth.JWKSKey, error)
- func (s *Store) ListAPITokens(ctx context.Context) ([]theauth.APIToken, error)
- func (s *Store) ListDevices(ctx context.Context, orgID *theauth.ULID) ([]theauth.Device, error)
- func (s *Store) ListGroupsByOrganization(ctx context.Context, orgID theauth.ULID, offset, limit int, ...) ([]theauth.Group, int, error)
- func (s *Store) ListPendingDeviceCodes(ctx context.Context, f theauth.DevicePendingFilter) ([]theauth.DeviceCode, error)
- func (s *Store) ListPermissions(ctx context.Context) ([]theauth.Permission, error)
- func (s *Store) ListRegistrationTokens(ctx context.Context, orgID *theauth.ULID) ([]theauth.RegistrationToken, error)
- func (s *Store) ListTrustedDevices(ctx context.Context, userID theauth.ULID) ([]theauth.TrustedDevice, error)
- func (s *Store) ListUserSessions(ctx context.Context, userID theauth.ULID) ([]theauth.Session, error)
- func (s *Store) ListUsersByOrganization(ctx context.Context, orgID theauth.ULID, offset, limit int, ...) ([]theauth.User, int, error)
- func (s *Store) MarkEmailVerified(ctx context.Context, userID theauth.ULID) error
- func (s *Store) MoveOAuthAccount(ctx context.Context, provider, providerUserID string, newUserID theauth.ULID) error
- func (s *Store) MovePasswordHash(ctx context.Context, primaryID, secondaryID theauth.ULID) error
- func (s *Store) MoveTOTPSecret(ctx context.Context, primaryID, secondaryID theauth.ULID) error
- func (s *Store) MoveWebAuthnCredentials(ctx context.Context, primaryID, secondaryID theauth.ULID) error
- func (s *Store) OAuthAccountByProviderUserID(ctx context.Context, provider, providerUserID string) (*theauth.OAuthAccount, error)
- func (s *Store) OAuthAccountsByUserID(ctx context.Context, userID theauth.ULID) ([]theauth.OAuthAccount, error)
- func (s *Store) OAuthClientByClientID(ctx context.Context, clientID string) (*theauth.OAuthClient, error)
- func (s *Store) OpaqueAccessTokenByHash(ctx context.Context, hash []byte) (*theauth.OpaqueAccessToken, error)
- func (s *Store) OpenToolApproval(ctx context.Context, a theauth.ToolApproval) error
- func (s *Store) OrganizationByID(ctx context.Context, id theauth.ULID) (*theauth.Organization, error)
- func (s *Store) OrganizationBySlug(ctx context.Context, slug string) (*theauth.Organization, error)
- func (s *Store) OrganizationMemberRole(ctx context.Context, orgID, userID theauth.ULID) (string, error)
- func (s *Store) OrganizationMembersByOrg(ctx context.Context, orgID theauth.ULID) ([]theauth.OrganizationMember, error)
- func (s *Store) OrganizationsByUser(ctx context.Context, userID theauth.ULID) ([]theauth.Organization, error)
- func (s *Store) PermissionByName(ctx context.Context, name string) (*theauth.Permission, error)
- func (s *Store) PermissionsByRole(ctx context.Context, roleID theauth.ULID) ([]string, error)
- func (s *Store) PermissionsForUser(ctx context.Context, userID theauth.ULID, orgID *theauth.ULID) ([]string, error)
- func (s *Store) QueryAuditEvents(ctx context.Context, q theauth.AuditQuery) ([]theauth.AuditEvent, string, error)
- func (s *Store) RecordDeviceAuthorizationPoll(ctx context.Context, id theauth.ULID, polledAt time.Time, intervalSeconds int) error
- func (s *Store) RecordDevicePoll(ctx context.Context, hash []byte, at time.Time, intervalSeconds int) error
- func (s *Store) RedeemBackchannelRequest(ctx context.Context, authReqID string, now time.Time) (theauth.BackchannelRequest, bool, error)
- func (s *Store) RedeemDeviceJoinToken(ctx context.Context, id, deviceID theauth.ULID, now time.Time) (bool, error)
- func (s *Store) RedeemRegistrationToken(ctx context.Context, id theauth.ULID, now time.Time) (bool, error)
- func (s *Store) RefreshTokenByHash(ctx context.Context, hash []byte) (*theauth.RefreshToken, error)
- func (s *Store) RefundDeviceJoinToken(ctx context.Context, id theauth.ULID) error
- func (s *Store) RefundRegistrationToken(ctx context.Context, id theauth.ULID) error
- func (s *Store) RegistrationTokenByHash(ctx context.Context, hash []byte) (*theauth.RegistrationToken, error)
- func (s *Store) RegistrationTokenByID(ctx context.Context, id theauth.ULID) (*theauth.RegistrationToken, error)
- func (s *Store) RemoveGroupMembers(ctx context.Context, groupID theauth.ULID, userIDs []theauth.ULID) error
- func (s *Store) RenameWebAuthnCredential(ctx context.Context, id, userID theauth.ULID, name string) error
- func (s *Store) ReplaceRecoveryCodes(ctx context.Context, userID theauth.ULID, codes []theauth.RecoveryCode) error
- func (s *Store) RevokeAPIToken(ctx context.Context, id theauth.ULID, at time.Time) error
- func (s *Store) RevokeAPITokensByOwner(ctx context.Context, ownerID theauth.ULID, at time.Time) (int, error)
- func (s *Store) RevokeAgentCredential(ctx context.Context, id theauth.ULID, at time.Time) error
- func (s *Store) RevokeDelegationGrant(ctx context.Context, id theauth.ULID, at time.Time, reason string) error
- func (s *Store) RevokeDevice(ctx context.Context, id theauth.ULID, at time.Time) (bool, error)
- func (s *Store) RevokeDeviceJoinToken(ctx context.Context, id theauth.ULID, at time.Time) (bool, error)
- func (s *Store) RevokeOpaqueAccessToken(ctx context.Context, hash []byte) error
- func (s *Store) RevokeOtherUserSessions(ctx context.Context, userID, keep theauth.ULID) (int, error)
- func (s *Store) RevokeRefreshToken(ctx context.Context, hash []byte, reason string) error
- func (s *Store) RevokeRefreshTokenFamily(ctx context.Context, familyID theauth.ULID, reason string) error
- func (s *Store) RevokeRefreshTokensByAuthCode(ctx context.Context, codeHash, reason string) ([]string, error)
- func (s *Store) RevokeRegistrationToken(ctx context.Context, id theauth.ULID, at time.Time) (bool, error)
- func (s *Store) RevokeSCIMTokenByID(ctx context.Context, id theauth.ULID, at time.Time) error
- func (s *Store) RevokeSession(ctx context.Context, id theauth.ULID) error
- func (s *Store) RevokeSessionsByCredential(ctx context.Context, credentialID string) (int, error)
- func (s *Store) RevokeTrustedDevice(ctx context.Context, userID, id theauth.ULID) error
- func (s *Store) RevokeUserRole(ctx context.Context, userID, roleID theauth.ULID) error
- func (s *Store) RevokeUserSessions(ctx context.Context, userID theauth.ULID) error
- func (s *Store) RevokeUserTrustedDevices(ctx context.Context, userID theauth.ULID) (int, error)
- func (s *Store) RoleByID(ctx context.Context, id theauth.ULID) (*theauth.Role, error)
- func (s *Store) RoleByOrgAndName(ctx context.Context, orgID *theauth.ULID, name string) (*theauth.Role, error)
- func (s *Store) RolesByOrganization(ctx context.Context, orgID *theauth.ULID) ([]theauth.Role, error)
- func (s *Store) RolesForUser(ctx context.Context, userID theauth.ULID, orgID *theauth.ULID) ([]theauth.Role, error)
- func (s *Store) SAMLConnectionByID(ctx context.Context, id theauth.ULID) (*theauth.SAMLConnection, error)
- func (s *Store) SAMLConnectionsByOrg(ctx context.Context, orgID theauth.ULID) ([]theauth.SAMLConnection, error)
- func (s *Store) SAMLIdentityByConnectionAndNameID(ctx context.Context, connectionID theauth.ULID, nameID string) (*theauth.SAMLIdentity, error)
- func (s *Store) SCIMTokenByHash(ctx context.Context, hash []byte) (*theauth.SCIMToken, error)
- func (s *Store) SCIMTokensByOrg(ctx context.Context, orgID theauth.ULID) ([]theauth.SCIMToken, error)
- func (s *Store) SessionByID(ctx context.Context, id theauth.ULID) (*theauth.Session, error)
- func (s *Store) SessionByTokenHash(ctx context.Context, hash []byte) (*theauth.Session, error)
- func (s *Store) SetGroupMembers(ctx context.Context, groupID theauth.ULID, userIDs []theauth.ULID) error
- func (s *Store) SetMustChangePassword(ctx context.Context, userID theauth.ULID, required bool) error
- func (s *Store) SetRolePermissions(ctx context.Context, roleID theauth.ULID, permissionIDs []theauth.ULID) error
- func (s *Store) SetSessionActiveOrganization(ctx context.Context, sessionID theauth.ULID, orgID *theauth.ULID) error
- func (s *Store) SetSessionElevatedUntil(ctx context.Context, id theauth.ULID, until *time.Time) error
- func (s *Store) SetUserDisabledAt(ctx context.Context, userID theauth.ULID, at *time.Time) error
- func (s *Store) SetUserPassword(ctx context.Context, userID theauth.ULID, passwordHash string) error
- func (s *Store) SignalsStore() signals.Store
- func (s *Store) SweepExpired(ctx context.Context, now time.Time) (SweepResult, error)
- func (s *Store) SweepExpiredJTIs(ctx context.Context, before time.Time) error
- func (s *Store) TOTPSecretByUserID(ctx context.Context, userID theauth.ULID) (*theauth.TOTPSecret, error)
- func (s *Store) ThrottleStore() *ThrottleStore
- func (s *Store) TouchAPITokenLastUsed(ctx context.Context, id theauth.ULID, at time.Time) error
- func (s *Store) TouchBackchannelPoll(ctx context.Context, authReqID string, now time.Time, newInterval int) (theauth.BackchannelRequest, error)
- func (s *Store) TouchDevice(ctx context.Context, id theauth.ULID, at time.Time) error
- func (s *Store) TouchSAMLIdentityLastLogin(ctx context.Context, id theauth.ULID, at time.Time) error
- func (s *Store) TouchSCIMTokenLastUsed(ctx context.Context, id theauth.ULID, at time.Time) error
- func (s *Store) TouchSession(ctx context.Context, id theauth.ULID, at time.Time) error
- func (s *Store) TouchTrustedDevice(ctx context.Context, id theauth.ULID, at time.Time) error
- func (s *Store) TrustedDeviceByTokenHash(ctx context.Context, userID theauth.ULID, hash []byte) (*theauth.TrustedDevice, error)
- func (s *Store) UpdateAgentCredentialLastUsed(ctx context.Context, id theauth.ULID, at time.Time) error
- func (s *Store) UpdateAgentLastActive(ctx context.Context, id theauth.ULID, at time.Time) error
- func (s *Store) UpdateAgentStatus(ctx context.Context, id theauth.ULID, status string, _ time.Time) error
- func (s *Store) UpdateBackchannelRequest(ctx context.Context, req theauth.BackchannelRequest) error
- func (s *Store) UpdateGroup(ctx context.Context, g theauth.Group) error
- func (s *Store) UpdateJWKSKeyState(ctx context.Context, kid, state string, at time.Time) error
- func (s *Store) UpdateOAuthClient(ctx context.Context, c theauth.OAuthClient) (theauth.OAuthClient, error)
- func (s *Store) UpdateOrganization(ctx context.Context, o theauth.Organization) error
- func (s *Store) UpdateRoleRow(ctx context.Context, r theauth.Role) (theauth.Role, error)
- func (s *Store) UpdateSAMLConnectionRow(ctx context.Context, c theauth.SAMLConnection) error
- func (s *Store) UpdateSessionAuthLevel(ctx context.Context, id theauth.ULID, level string) error
- func (s *Store) UpdateUserSCIM(ctx context.Context, u theauth.User) error
- func (s *Store) UpdateWebAuthnBackupFlags(ctx context.Context, credentialID []byte, backupEligible, backupState bool) error
- func (s *Store) UpdateWebAuthnSignCount(ctx context.Context, credentialID []byte, newCount uint32, usedAt time.Time) error
- func (s *Store) UpsertOAuthAccount(ctx context.Context, a theauth.OAuthAccount) (theauth.OAuthAccount, error)
- func (s *Store) UpsertOrganizationMember(ctx context.Context, m theauth.OrganizationMember) error
- func (s *Store) UpsertPendingTOTPSecret(ctx context.Context, sec theauth.TOTPSecret) error
- func (s *Store) UpsertSAMLIdentity(ctx context.Context, i theauth.SAMLIdentity) (theauth.SAMLIdentity, error)
- func (s *Store) UserByEmail(ctx context.Context, email string) (*theauth.User, error)
- func (s *Store) UserByEmailWithPassword(ctx context.Context, email string) (*theauth.User, string, error)
- func (s *Store) UserByExternalIDInOrg(ctx context.Context, orgID theauth.ULID, externalID string) (*theauth.User, error)
- func (s *Store) UserByID(ctx context.Context, id theauth.ULID) (*theauth.User, error)
- func (s *Store) UserPasswordHashByID(ctx context.Context, userID theauth.ULID) (string, error)
- func (s *Store) VerifyAuditChain(ctx context.Context) (AuditChainResult, error)
- func (s *Store) WebAuthnCredentialByCredentialID(ctx context.Context, credentialID []byte) (*theauth.WebAuthnCredential, error)
- func (s *Store) WebAuthnCredentialsByUserID(ctx context.Context, userID theauth.ULID) ([]theauth.WebAuthnCredential, error)
- type SweepResult
- type ThrottleStore
- func (t *ThrottleStore) CompareAndSwap(ctx context.Context, key string, prev theauth.LoginThrottleEntry, ...) (bool, error)
- func (t *ThrottleStore) Delete(ctx context.Context, key string) error
- func (t *ThrottleStore) DeleteLoginEntries(ctx context.Context, ident string) error
- func (t *ThrottleStore) Get(ctx context.Context, key string) (theauth.LoginThrottleEntry, bool, error)
- func (t *ThrottleStore) Set(ctx context.Context, key string, e theauth.LoginThrottleEntry) error
- func (t *ThrottleStore) SweepExpired(ctx context.Context, now time.Time) (int, error)
Constants ¶
const ( // BackchannelStatusConsumed marks an approved request whose tokens were // redeemed through RedeemBackchannelRequest. BackchannelStatusConsumed = "consumed" // BackchannelStatusExpired marks a pending request swept by // ExpireBackchannelRequests. BackchannelStatusExpired = "expired" )
Extra CIBA lifecycle states persisted by this store beyond the three the service layer writes (pending, approved, denied).
const DefaultTablePrefix = "theauth_"
DefaultTablePrefix is the table name prefix used when WithTablePrefix is not set.
Variables ¶
var ErrBackchannelStateConflict = errors.New("theauth sqlite: backchannel request is not pending")
ErrBackchannelStateConflict is returned by UpdateBackchannelRequest when the stored request is no longer pending, so a second approve or deny loses.
Functions ¶
func Migrate ¶
Migrate applies pending migrations tracked in <prefix>schema_migrations. Each step runs under BEGIN IMMEDIATE so concurrent processes serialize, and is recorded in the same transaction as its DDL.
func Migrations ¶
Migrations returns the numbered forward-only .sql files, in the root of the FS, using the default table prefix.
Types ¶
type AuditChainBreak ¶ added in v0.3.0
type AuditChainBreak = theauth.AuditChainBreak
AuditChainBreak, AuditChainResult: see theauth.AuditChainResult.
type AuditChainResult ¶ added in v0.3.0
type AuditChainResult = theauth.AuditChainResult
AuditChainBreak, AuditChainResult: see theauth.AuditChainResult.
type DBTX ¶
type DBTX interface {
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
}
DBTX is the subset of *sql.DB and *sql.Tx the Store runs its statements on.
type Migration ¶
type Migration struct {
// Version is the file name without the .sql suffix, for example 0001_core.
Version string
SQL string
}
Migration is one forward-only schema step.
func RenderMigrations ¶
RenderMigrations returns the migrations in version order with the table prefix applied.
type Option ¶
type Option func(*config) error
Option configures New and Migrate.
func AllowForeignKeysOff ¶
func AllowForeignKeysOff() Option
AllowForeignKeysOff lets New succeed when PRAGMA foreign_keys is off, which disables ON DELETE CASCADE.
func WithTablePrefix ¶
WithTablePrefix sets the table name prefix, which must match between Migrate and New.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the SQLite-backed storage adapter.
func New ¶
New wraps db, which the caller keeps ownership of, and verifies foreign keys are enforced.
func NewTx ¶
NewTx binds a Store to the caller's open transaction. The Store never commits or rolls back; multi-statement methods use SAVEPOINTs inside tx. Run Migrate on the *sql.DB beforehand, as it cannot run inside a Tx.
func (*Store) APITokenByHash ¶
APITokenByHash returns the token with the given secret hash, else ErrStorageNotFound.
func (*Store) APITokenByID ¶
APITokenByID returns the token with the given ID, else ErrStorageNotFound.
func (*Store) APITokensByAgentID ¶ added in v0.3.0
func (s *Store) APITokensByAgentID(ctx context.Context, agentID theauth.ULID) ([]theauth.APIToken, error)
APITokensByAgentID returns every token minted for the agent, newest first.
func (*Store) APITokensByOwner ¶
func (s *Store) APITokensByOwner(ctx context.Context, ownerID theauth.ULID) ([]theauth.APIToken, error)
APITokensByOwner returns every token of the owner, newest first.
func (*Store) AccountStateByUserID ¶ added in v0.2.0
func (s *Store) AccountStateByUserID(ctx context.Context, userID theauth.ULID) (theauth.AccountState, error)
AccountStateByUserID returns the user's lifecycle flags; a user without a row yields the zero state.
func (*Store) AddGroupMembers ¶ added in v0.2.0
func (s *Store) AddGroupMembers(ctx context.Context, groupID theauth.ULID, userIDs []theauth.ULID) error
AddGroupMembers adds members, ignoring those already present.
func (*Store) AdvanceTOTPStep ¶
AdvanceTOTPStep records step as the user's last used TOTP step, returning false when it is not strictly newer.
func (*Store) AgentByClientID ¶ added in v0.3.0
AgentByClientID looks an agent up by its OAuth client id.
func (*Store) AgentByID ¶ added in v0.3.0
AgentByID implements the agent lookup; a missing row is ErrStorageNotFound.
func (*Store) AgentCredentialsByAgentID ¶ added in v0.3.0
func (s *Store) AgentCredentialsByAgentID(ctx context.Context, agentID theauth.ULID) ([]theauth.AgentCredential, error)
AgentCredentialsByAgentID returns every credential of the agent, oldest first, including revoked rows.
func (*Store) AgentsByOwner ¶ added in v0.3.0
func (s *Store) AgentsByOwner(ctx context.Context, owner theauth.AgentOwner) ([]theauth.Agent, error)
AgentsByOwner lists the agents of a user or organization, oldest first. The owner must set UserID or OrganizationID (UserID wins when both are set).
func (*Store) AppendSessionAuthMethods ¶ added in v0.3.0
func (s *Store) AppendSessionAuthMethods(ctx context.Context, id theauth.ULID, methods []string, at time.Time) ([]string, time.Time, error)
AppendSessionAuthMethods adds methods to the session's auth_methods and advances auth_time. The first statement of the transaction is a write, so SQLite holds the write lock for the whole read-merge-write and concurrent appends serialize without losing methods.
func (*Store) ApproveToolApproval ¶ added in v0.3.0
func (*Store) AtomicRotateJWKS ¶ added in v0.3.0
func (s *Store) AtomicRotateJWKS(ctx context.Context, retireKIDs []string, demoteKID, promoteKID string, freshKey theauth.JWKSKey, now time.Time) error
AtomicRotateJWKS implements as.JWKSAtomicRotator in one write-first transaction, so concurrent rotations serialize. Order matters for the one-current-per-algorithm index: retire, demote, promote, then insert. Unknown kids roll back.
func (*Store) BackchannelRequestByID ¶ added in v0.3.0
func (*Store) ChainSupported ¶ added in v0.3.0
ChainSupported reports that this backend keeps the tamper-evident audit hash chain (memory returns false). It hashes like postgres and mysql; the golden vector test pins them.
func (*Store) ClaimDeviceCode ¶
func (s *Store) ClaimDeviceCode(ctx context.Context, hash []byte, now time.Time) (*theauth.DeviceCode, error)
ClaimDeviceCode atomically moves an approved, unexpired request to redeemed; one concurrent caller wins.
func (*Store) ConfirmTOTPSecret ¶
ConfirmTOTPSecret confirms the user's pending secret, else ErrStorageNotFound.
func (*Store) ConsumeAuthorizationCode ¶ added in v0.3.0
func (s *Store) ConsumeAuthorizationCode(ctx context.Context, code string) (*theauth.AuthorizationCode, error)
ConsumeAuthorizationCode implements theauth.OAuthServerStorage. A single DELETE ... RETURNING is the winner check: SQLite serializes writers, so exactly one of N concurrent callers receives the row. Expiry is left to the caller, as in the other backends.
func (*Store) ConsumeDeviceAuthorization ¶ added in v0.3.0
func (s *Store) ConsumeDeviceAuthorization(ctx context.Context, id theauth.ULID, now time.Time) (bool, error)
ConsumeDeviceAuthorization implements theauth.DeviceAuthorizationStorage: approved to consumed, with exactly one winner under concurrency.
func (*Store) ConsumeMagicLink ¶
ConsumeMagicLink atomically marks an unused, unexpired link used and returns it.
func (*Store) ConsumePasswordResetToken ¶
func (s *Store) ConsumePasswordResetToken(ctx context.Context, tokenHash []byte) (*theauth.PasswordResetToken, error)
ConsumePasswordResetToken atomically marks an unused, unexpired token used and returns it.
func (*Store) ConsumePushedRequest ¶ added in v0.3.0
ConsumePushedRequest atomically marks the row consumed and returns its payload. It returns ErrStorageNotFound when the request_uri is unknown, already consumed, or expired. The conditional UPDATE is the single winner.
func (*Store) ConsumeRecoveryCode ¶
func (s *Store) ConsumeRecoveryCode(ctx context.Context, userID theauth.ULID, code string, at time.Time) error
ConsumeRecoveryCode marks the matching unused code used, else ErrStorageNotFound.
func (*Store) ConsumeSessionLink ¶
func (s *Store) ConsumeSessionLink(ctx context.Context, tokenHash []byte, now time.Time) (*theauth.SessionLink, error)
ConsumeSessionLink atomically marks an unused, unexpired link used and returns it, else ErrStorageNotFound.
func (*Store) ConsumeToolApproval ¶ added in v0.3.0
func (s *Store) ConsumeToolApproval(ctx context.Context, id, agentID, action, resource string, now time.Time) (bool, error)
ConsumeToolApproval implements theauth.ToolApprovalStorage. The conditional UPDATE is the single winner check: only one caller sees one affected row.
func (*Store) CountUnusedRecoveryCodes ¶
CountUnusedRecoveryCodes returns how many unused recovery codes userID holds.
func (*Store) CountUsers ¶
CountUsers returns the number of user rows.
func (*Store) CountUsersWithPermissionInOrg ¶ added in v0.2.0
func (s *Store) CountUsersWithPermissionInOrg(ctx context.Context, orgID theauth.ULID, perm string) (int, error)
CountUsersWithPermissionInOrg counts distinct users holding perm through an organization role.
func (*Store) CreateMagicLink ¶
CreateMagicLink stores a single-use magic link.
func (*Store) CreatePasswordResetToken ¶
CreatePasswordResetToken stores a single-use reset token.
func (*Store) CreateSession ¶
CreateSession inserts a session, defaulting AuthLevel to full.
func (*Store) CreateSessionLink ¶
CreateSessionLink stores a single-use session link.
func (*Store) CreateSessionWithAuthLevel ¶
func (s *Store) CreateSessionWithAuthLevel(ctx context.Context, sess theauth.Session) (theauth.Session, error)
CreateSessionWithAuthLevel is CreateSession; the level is read from sess.AuthLevel.
func (*Store) CreateUser ¶
CreateUser inserts u and returns the stored row. Email uniqueness is case-insensitive.
func (*Store) DecideDeviceAuthorization ¶ added in v0.3.0
func (s *Store) DecideDeviceAuthorization(ctx context.Context, id theauth.ULID, status string, userID theauth.ULID, now time.Time) (bool, error)
DecideDeviceAuthorization implements theauth.DeviceAuthorizationStorage as a compare and set from pending to the given status.
func (*Store) DecideDeviceCode ¶
func (s *Store) DecideDeviceCode(ctx context.Context, userCode string, d theauth.DeviceDecision, now time.Time) error
DecideDeviceCode moves a pending, unexpired request to approved or denied in one statement.
func (*Store) DelegationGrantByID ¶ added in v0.3.0
func (s *Store) DelegationGrantByID(ctx context.Context, id theauth.ULID) (*theauth.DelegationGrant, error)
DelegationGrantByID returns the grant or ErrStorageNotFound.
func (*Store) DelegationGrantByUserAgentResource ¶ added in v0.3.0
func (s *Store) DelegationGrantByUserAgentResource(ctx context.Context, userID, agentID theauth.ULID, resource string) (*theauth.DelegationGrant, error)
DelegationGrantByUserAgentResource returns the live grant for the tuple, or the most recent revoked one when no live grant exists.
func (*Store) DelegationGrantsByAgentID ¶ added in v0.3.0
func (s *Store) DelegationGrantsByAgentID(ctx context.Context, agentID theauth.ULID) ([]theauth.DelegationGrant, error)
DelegationGrantsByAgentID lists every grant held by the agent, oldest first.
func (*Store) DelegationGrantsByUserID ¶ added in v0.3.0
func (s *Store) DelegationGrantsByUserID(ctx context.Context, userID theauth.ULID) ([]theauth.DelegationGrant, error)
DelegationGrantsByUserID lists every grant of the user, oldest first.
func (*Store) DeleteBackchannelRequest ¶ added in v0.3.0
func (*Store) DeleteExpiredDeviceAuthorizations ¶ added in v0.3.0
func (*Store) DeleteExpiredDeviceCodes ¶
DeleteExpiredDeviceCodes removes requests that expired before the cutoff.
func (*Store) DeleteGroup ¶ added in v0.2.0
DeleteGroup removes a group and, by cascade, its memberships.
func (*Store) DeleteOAuthAccountByProvider ¶
func (s *Store) DeleteOAuthAccountByProvider(ctx context.Context, userID theauth.ULID, provider string) error
DeleteOAuthAccountByProvider unlinks a user's account for one provider.
func (*Store) DeleteOAuthClient ¶ added in v0.3.0
DeleteOAuthClient implements theauth.OAuthServerStorage. The 0029 trigger removes the client's codes and tokens in the same statement.
func (*Store) DeleteOrganization ¶ added in v0.2.0
DeleteOrganization removes the organization and, by cascade, its members, connections, tokens, groups and roles.
func (*Store) DeleteOrganizationMember ¶ added in v0.2.0
DeleteOrganizationMember removes one membership.
func (*Store) DeleteRole ¶ added in v0.2.0
DeleteRole removes a role and, by cascade, its grants and permission links.
func (*Store) DeleteSAMLConnection ¶ added in v0.2.0
DeleteSAMLConnection removes a connection and, by cascade, its identities.
func (*Store) DeleteTOTPSecret ¶
DeleteTOTPSecret removes the user's secret and recovery codes.
func (*Store) DeleteUserCascade ¶ added in v0.2.0
DeleteUserCascade removes the user and every row that belongs to it in one transaction.
func (*Store) DeleteWebAuthnCredential ¶
func (s *Store) DeleteWebAuthnCredential(ctx context.Context, id theauth.ULID, userID theauth.ULID) error
DeleteWebAuthnCredential removes a credential owned by userID.
func (*Store) DenyAccessToken ¶ added in v0.3.0
DenyAccessToken records jti as revoked until expiresAt (opt-in access token revocation) and opportunistically purges entries that have lapsed.
func (*Store) DeviceAuthorizationByDeviceCodeHash ¶ added in v0.3.0
func (*Store) DeviceAuthorizationByUserCodeHash ¶ added in v0.3.0
func (*Store) DeviceByID ¶ added in v0.2.0
DeviceByID returns the device, else ErrStorageNotFound.
func (*Store) DeviceCodeByHash ¶
DeviceCodeByHash returns the request with the given device code hash, else ErrStorageNotFound.
func (*Store) DeviceCodeByUserCode ¶
func (s *Store) DeviceCodeByUserCode(ctx context.Context, userCode string) (*theauth.DeviceCode, error)
DeviceCodeByUserCode returns the request with the given user code, else ErrStorageNotFound.
func (*Store) DeviceJoinTokenByHash ¶ added in v0.2.0
func (s *Store) DeviceJoinTokenByHash(ctx context.Context, hash []byte) (*theauth.DeviceJoinToken, error)
DeviceJoinTokenByHash returns the token with the given digest, else ErrStorageNotFound.
func (*Store) DeviceJoinTokenByID ¶ added in v0.2.0
func (s *Store) DeviceJoinTokenByID(ctx context.Context, id theauth.ULID) (*theauth.DeviceJoinToken, error)
DeviceJoinTokenByID returns the token, else ErrStorageNotFound.
func (*Store) ExpireBackchannelRequests ¶ added in v0.3.0
ExpireBackchannelRequests marks every pending request whose deadline has passed as expired and returns how many rows changed.
func (*Store) GrantUserRole ¶ added in v0.2.0
GrantUserRole binds a role to a user and keeps the first grant on repeat calls.
func (*Store) GroupByExternalIDInOrg ¶ added in v0.2.0
func (s *Store) GroupByExternalIDInOrg(ctx context.Context, orgID theauth.ULID, externalID string) (*theauth.Group, error)
GroupByExternalIDInOrg returns the group carrying the external ID in one organization.
func (*Store) GroupMembers ¶ added in v0.2.0
GroupMembers lists a group's member user IDs.
func (*Store) InsertAPIToken ¶
InsertAPIToken stores a token and returns the stored row.
func (*Store) InsertAgent ¶ added in v0.3.0
InsertAgent stores a. A duplicate id or client_id returns theauth.ErrStorageNotFound. An empty Status defaults to active and a zero CreatedAt to now.
func (*Store) InsertAgentCredential ¶ added in v0.3.0
InsertAgentCredential stores a credential row. A duplicate id returns ErrStorageNotFound.
func (*Store) InsertAuditEvents ¶
InsertAuditEvents appends a batch in one transaction. Rows are linked into a per-organization hash chain (see VerifyAuditChain). If the database has not run migration 0017 the rows are written without chain or accountability columns, so hosts upgrading in two steps keep working.
func (*Store) InsertAuthorizationCode ¶ added in v0.3.0
func (*Store) InsertBackchannelRequest ¶ added in v0.3.0
InsertBackchannelRequest fails on a duplicate auth_req_id (primary key).
func (*Store) InsertDelegationGrant ¶ added in v0.3.0
func (s *Store) InsertDelegationGrant(ctx context.Context, g theauth.DelegationGrant) (theauth.DelegationGrant, error)
InsertDelegationGrant allows at most one live grant per (user, agent, resource). A second live insert or a duplicate id returns ErrStorageNotFound; a revoked grant frees the tuple.
func (*Store) InsertDevice ¶ added in v0.2.0
InsertDevice stores a device, returning ErrDeviceConflict when its SPIFFE ID is taken.
func (*Store) InsertDeviceAuthorization ¶ added in v0.3.0
InsertDeviceAuthorization implements theauth.DeviceAuthorizationStorage. An expired holder of the same user code is deleted first; a live one yields ErrDeviceAuthUserCodeTaken.
func (*Store) InsertDeviceCode ¶
InsertDeviceCode stores a request, returning ErrDeviceUserCodeTaken on a user code collision.
func (*Store) InsertDeviceJoinToken ¶ added in v0.2.0
InsertDeviceJoinToken stores a join token.
func (*Store) InsertGroup ¶ added in v0.2.0
InsertGroup stores a group; (organization, display name) and (organization, external ID) are unique.
func (*Store) InsertJTI ¶ added in v0.3.0
InsertJTI records a jti for RFC 7523 replay protection. It returns ErrStorageNotFound when the jti is already recorded and unexpired (the JWTBearerStorage duplicate signal). One upsert statement decides the winner: an expired row is overwritten, a live row blocks the insert, so concurrent presentations of the same jti produce exactly one success.
func (*Store) InsertJWKSKey ¶ added in v0.3.0
InsertJWKSKey implements theauth.OAuthServerStorage. A duplicate kid, or a second current key for the same algorithm, is rejected by the schema.
func (*Store) InsertOAuthClient ¶ added in v0.3.0
func (s *Store) InsertOAuthClient(ctx context.Context, c theauth.OAuthClient) (theauth.OAuthClient, error)
func (*Store) InsertOpaqueAccessToken ¶ added in v0.3.0
func (*Store) InsertOrganization ¶ added in v0.2.0
func (s *Store) InsertOrganization(ctx context.Context, o theauth.Organization) (theauth.Organization, error)
InsertOrganization stores o with a lowercased slug and returns ErrSlugTaken on a duplicate.
func (*Store) InsertPermission ¶ added in v0.2.0
func (s *Store) InsertPermission(ctx context.Context, p theauth.Permission) (theauth.Permission, error)
InsertPermission is idempotent on the name: a duplicate returns the existing row.
func (*Store) InsertPushedRequest ¶ added in v0.3.0
func (s *Store) InsertPushedRequest(ctx context.Context, requestURI string, payload []byte, expiresAt time.Time) error
InsertPushedRequest stores a pushed authorization request. requestURI is the full urn: string, payload the JSON encoded AuthorizeRequest.
func (*Store) InsertRecoveryCodes ¶
InsertRecoveryCodes stores a batch of recovery codes atomically.
func (*Store) InsertRefreshToken ¶ added in v0.3.0
func (*Store) InsertRegistrationToken ¶ added in v0.3.0
func (*Store) InsertRole ¶ added in v0.2.0
InsertRole stores a role; names are unique within an organization and among system roles.
func (*Store) InsertSAMLConnection ¶ added in v0.2.0
func (s *Store) InsertSAMLConnection(ctx context.Context, c theauth.SAMLConnection) (theauth.SAMLConnection, error)
InsertSAMLConnection stores a connection bound to an existing organization.
func (*Store) InsertSCIMToken ¶ added in v0.2.0
func (s *Store) InsertSCIMToken(ctx context.Context, t theauth.SCIMToken) (theauth.SCIMToken, error)
InsertSCIMToken stores a token hash bound to an existing organization.
func (*Store) InsertTrustedDevice ¶ added in v0.2.0
InsertTrustedDevice stores a remember-this-device record.
func (*Store) InsertWebAuthnCredential ¶
func (s *Store) InsertWebAuthnCredential(ctx context.Context, c theauth.WebAuthnCredential) (theauth.WebAuthnCredential, error)
InsertWebAuthnCredential stores a credential and returns the stored row.
func (*Store) IsAccessTokenDenied ¶ added in v0.3.0
IsAccessTokenDenied reports whether jti is on the unexpired denylist.
func (*Store) JWKSKeyByKID ¶ added in v0.3.0
func (*Store) JWKSKeysAll ¶ added in v0.3.0
JWKSKeysAll implements theauth.OAuthServerStorage, oldest key first.
func (*Store) ListAPITokens ¶
ListAPITokens returns every token, newest first.
func (*Store) ListDevices ¶ added in v0.2.0
ListDevices returns devices newest first. A nil orgID lists every device.
func (*Store) ListGroupsByOrganization ¶ added in v0.2.0
func (s *Store) ListGroupsByOrganization(ctx context.Context, orgID theauth.ULID, offset, limit int, filter theauth.SCIMGroupFilter) ([]theauth.Group, int, error)
ListGroupsByOrganization pages through an organization's groups matching the equality filter.
func (*Store) ListPendingDeviceCodes ¶
func (s *Store) ListPendingDeviceCodes(ctx context.Context, f theauth.DevicePendingFilter) ([]theauth.DeviceCode, error)
ListPendingDeviceCodes returns pending, unexpired requests newest first without device code hashes.
func (*Store) ListPermissions ¶ added in v0.2.0
ListPermissions returns the catalog ordered by name.
func (*Store) ListRegistrationTokens ¶ added in v0.3.0
func (s *Store) ListRegistrationTokens(ctx context.Context, orgID *theauth.ULID) ([]theauth.RegistrationToken, error)
ListRegistrationTokens implements theauth.RegistrationTokenStorage, newest first.
func (*Store) ListTrustedDevices ¶ added in v0.2.0
func (s *Store) ListTrustedDevices(ctx context.Context, userID theauth.ULID) ([]theauth.TrustedDevice, error)
ListTrustedDevices returns the user's unrevoked, unexpired devices, newest first.
func (*Store) ListUserSessions ¶
func (s *Store) ListUserSessions(ctx context.Context, userID theauth.ULID) ([]theauth.Session, error)
ListUserSessions returns the user's live sessions, newest first.
func (*Store) ListUsersByOrganization ¶ added in v0.2.0
func (s *Store) ListUsersByOrganization(ctx context.Context, orgID theauth.ULID, offset, limit int, filter theauth.SCIMUserFilter) ([]theauth.User, int, error)
ListUsersByOrganization pages through an organization's members matching the equality filter.
func (*Store) MarkEmailVerified ¶
MarkEmailVerified sets the verification time once and keeps the first value on repeat calls.
func (*Store) MoveOAuthAccount ¶
func (s *Store) MoveOAuthAccount(ctx context.Context, provider, providerUserID string, newUserID theauth.ULID) error
MoveOAuthAccount reassigns a linked account to newUserID.
func (*Store) MovePasswordHash ¶
MovePasswordHash moves the hash from secondaryID to primaryID, overwriting any existing one.
func (*Store) MoveTOTPSecret ¶
MoveTOTPSecret moves secondaryID's secret to primaryID, or drops it when primaryID already has one.
func (*Store) MoveWebAuthnCredentials ¶
func (s *Store) MoveWebAuthnCredentials(ctx context.Context, primaryID, secondaryID theauth.ULID) error
MoveWebAuthnCredentials reassigns every credential of secondaryID to primaryID.
func (*Store) OAuthAccountByProviderUserID ¶
func (s *Store) OAuthAccountByProviderUserID(ctx context.Context, provider, providerUserID string) (*theauth.OAuthAccount, error)
OAuthAccountByProviderUserID looks up a linked account by its provider identity.
func (*Store) OAuthAccountsByUserID ¶
func (s *Store) OAuthAccountsByUserID(ctx context.Context, userID theauth.ULID) ([]theauth.OAuthAccount, error)
OAuthAccountsByUserID lists a user's linked accounts, empty when there are none.
func (*Store) OAuthClientByClientID ¶ added in v0.3.0
func (*Store) OpaqueAccessTokenByHash ¶ added in v0.3.0
func (*Store) OpenToolApproval ¶ added in v0.3.0
func (*Store) OrganizationByID ¶ added in v0.2.0
func (s *Store) OrganizationByID(ctx context.Context, id theauth.ULID) (*theauth.Organization, error)
OrganizationByID returns the organization with the given ID.
func (*Store) OrganizationBySlug ¶ added in v0.2.0
OrganizationBySlug returns the organization with the given slug, compared case-insensitively.
func (*Store) OrganizationMemberRole ¶ added in v0.2.0
func (s *Store) OrganizationMemberRole(ctx context.Context, orgID, userID theauth.ULID) (string, error)
OrganizationMemberRole returns the member's role, or ErrStorageNotFound when the user is not a member.
func (*Store) OrganizationMembersByOrg ¶ added in v0.2.0
func (s *Store) OrganizationMembersByOrg(ctx context.Context, orgID theauth.ULID) ([]theauth.OrganizationMember, error)
OrganizationMembersByOrg lists an organization's members, oldest first.
func (*Store) OrganizationsByUser ¶ added in v0.2.0
func (s *Store) OrganizationsByUser(ctx context.Context, userID theauth.ULID) ([]theauth.Organization, error)
OrganizationsByUser lists the organizations a user belongs to, oldest first.
func (*Store) PermissionByName ¶ added in v0.2.0
PermissionByName returns the permission with the given name.
func (*Store) PermissionsByRole ¶ added in v0.2.0
PermissionsByRole returns a role's permission names in order.
func (*Store) PermissionsForUser ¶ added in v0.2.0
func (s *Store) PermissionsForUser(ctx context.Context, userID theauth.ULID, orgID *theauth.ULID) ([]string, error)
PermissionsForUser returns the distinct permission names a user holds in one organization scope.
func (*Store) QueryAuditEvents ¶
func (s *Store) QueryAuditEvents(ctx context.Context, q theauth.AuditQuery) ([]theauth.AuditEvent, string, error)
QueryAuditEvents returns events newest first with keyset pagination over (created_at, id).
func (*Store) RecordDeviceAuthorizationPoll ¶ added in v0.3.0
func (*Store) RecordDevicePoll ¶
func (s *Store) RecordDevicePoll(ctx context.Context, hash []byte, at time.Time, intervalSeconds int) error
RecordDevicePoll stores the last poll time and the current polling interval.
func (*Store) RedeemBackchannelRequest ¶ added in v0.3.0
func (s *Store) RedeemBackchannelRequest(ctx context.Context, authReqID string, now time.Time) (theauth.BackchannelRequest, bool, error)
RedeemBackchannelRequest moves an approved, unexpired request to consumed in one statement, so exactly one concurrent caller wins. It extends theauth.CIBAStorage for one-time token delivery.
func (*Store) RedeemDeviceJoinToken ¶ added in v0.2.0
func (s *Store) RedeemDeviceJoinToken(ctx context.Context, id, deviceID theauth.ULID, now time.Time) (bool, error)
RedeemDeviceJoinToken marks an unredeemed, unrevoked, unexpired token redeemed and reports whether this call did it, so a join token is single use.
func (*Store) RedeemRegistrationToken ¶ added in v0.3.0
func (s *Store) RedeemRegistrationToken(ctx context.Context, id theauth.ULID, now time.Time) (bool, error)
RedeemRegistrationToken implements theauth.RegistrationTokenStorage. The uses < max_uses guard keeps a one-time token to one winner.
func (*Store) RefreshTokenByHash ¶ added in v0.3.0
func (*Store) RefundDeviceJoinToken ¶ added in v0.2.0
RefundDeviceJoinToken undoes a redemption when enrollment failed after it.
func (*Store) RefundRegistrationToken ¶ added in v0.3.0
func (*Store) RegistrationTokenByHash ¶ added in v0.3.0
func (*Store) RegistrationTokenByID ¶ added in v0.3.0
func (*Store) RemoveGroupMembers ¶ added in v0.2.0
func (s *Store) RemoveGroupMembers(ctx context.Context, groupID theauth.ULID, userIDs []theauth.ULID) error
RemoveGroupMembers removes members; absent users are ignored.
func (*Store) RenameWebAuthnCredential ¶
func (s *Store) RenameWebAuthnCredential(ctx context.Context, id, userID theauth.ULID, name string) error
RenameWebAuthnCredential sets a passkey's display name when it belongs to userID.
func (*Store) ReplaceRecoveryCodes ¶
func (s *Store) ReplaceRecoveryCodes(ctx context.Context, userID theauth.ULID, codes []theauth.RecoveryCode) error
ReplaceRecoveryCodes atomically swaps every recovery code of userID for codes.
func (*Store) RevokeAPIToken ¶
RevokeAPIToken revokes a token, keeping the first revocation time on repeat calls.
func (*Store) RevokeAPITokensByOwner ¶
func (s *Store) RevokeAPITokensByOwner(ctx context.Context, ownerID theauth.ULID, at time.Time) (int, error)
RevokeAPITokensByOwner revokes the owner's live tokens and returns how many it changed.
func (*Store) RevokeAgentCredential ¶ added in v0.3.0
RevokeAgentCredential sets revoked_at once. A repeat revoke returns ErrStorageNotFound, as the other adapters do.
func (*Store) RevokeDelegationGrant ¶ added in v0.3.0
func (s *Store) RevokeDelegationGrant(ctx context.Context, id theauth.ULID, at time.Time, reason string) error
RevokeDelegationGrant is conditional on revoked_at IS NULL, so exactly one concurrent caller wins and keeps its reason and time. Later calls return ErrStorageNotFound; internal/delegation relies on that to emit one audit event.
func (*Store) RevokeDevice ¶ added in v0.2.0
RevokeDevice marks an active device revoked and reports whether it changed anything.
func (*Store) RevokeDeviceJoinToken ¶ added in v0.2.0
func (s *Store) RevokeDeviceJoinToken(ctx context.Context, id theauth.ULID, at time.Time) (bool, error)
RevokeDeviceJoinToken revokes a token that is not yet revoked.
func (*Store) RevokeOpaqueAccessToken ¶ added in v0.3.0
RevokeOpaqueAccessToken implements theauth.OpaqueTokenStorage. Revoking an unknown or already revoked token is not an error, and the first revocation time is kept.
func (*Store) RevokeOtherUserSessions ¶
func (s *Store) RevokeOtherUserSessions(ctx context.Context, userID, keep theauth.ULID) (int, error)
RevokeOtherUserSessions revokes the user's live sessions except keep and returns the count.
func (*Store) RevokeRefreshToken ¶ added in v0.3.0
RevokeRefreshToken implements theauth.OAuthServerStorage. It is the rotation gate: exactly one caller wins per token; a replay or concurrent refresh gets ErrStorageNotFound.
func (*Store) RevokeRefreshTokenFamily ¶ added in v0.3.0
func (s *Store) RevokeRefreshTokenFamily(ctx context.Context, familyID theauth.ULID, reason string) error
RevokeRefreshTokenFamily implements theauth.OAuthServerStorage. Revoking a family with no live tokens is not an error.
func (*Store) RevokeRefreshTokensByAuthCode ¶ added in v0.3.0
func (s *Store) RevokeRefreshTokensByAuthCode(ctx context.Context, codeHash, reason string) ([]string, error)
RevokeRefreshTokensByAuthCode revokes every live token issued from the code stored under codeHash (RFC 6749 4.1.2 code replay) and returns their access token jtis, in one statement.
func (*Store) RevokeRegistrationToken ¶ added in v0.3.0
func (*Store) RevokeSCIMTokenByID ¶ added in v0.2.0
RevokeSCIMTokenByID marks a token revoked.
func (*Store) RevokeSession ¶
RevokeSession marks a session revoked and keeps the first revocation time on repeat calls.
func (*Store) RevokeSessionsByCredential ¶
RevokeSessionsByCredential revokes every live session bound to credentialID and returns the count.
func (*Store) RevokeTrustedDevice ¶ added in v0.2.0
RevokeTrustedDevice revokes one live device owned by userID.
func (*Store) RevokeUserRole ¶ added in v0.2.0
RevokeUserRole removes a grant, returning ErrStorageNotFound when none existed.
func (*Store) RevokeUserSessions ¶
RevokeUserSessions revokes every active session of a user.
func (*Store) RevokeUserTrustedDevices ¶ added in v0.2.0
RevokeUserTrustedDevices revokes every live device of userID and returns how many it revoked.
func (*Store) RoleByOrgAndName ¶ added in v0.2.0
func (s *Store) RoleByOrgAndName(ctx context.Context, orgID *theauth.ULID, name string) (*theauth.Role, error)
RoleByOrgAndName returns a role by name within an organization, or among system roles when orgID is nil.
func (*Store) RolesByOrganization ¶ added in v0.2.0
func (s *Store) RolesByOrganization(ctx context.Context, orgID *theauth.ULID) ([]theauth.Role, error)
RolesByOrganization lists roles of one organization, or the system roles when orgID is nil.
func (*Store) RolesForUser ¶ added in v0.2.0
func (s *Store) RolesForUser(ctx context.Context, userID theauth.ULID, orgID *theauth.ULID) ([]theauth.Role, error)
RolesForUser lists the user's roles in one organization, or the system roles when orgID is nil.
func (*Store) SAMLConnectionByID ¶ added in v0.2.0
func (s *Store) SAMLConnectionByID(ctx context.Context, id theauth.ULID) (*theauth.SAMLConnection, error)
SAMLConnectionByID returns the connection with the given ID.
func (*Store) SAMLConnectionsByOrg ¶ added in v0.2.0
func (s *Store) SAMLConnectionsByOrg(ctx context.Context, orgID theauth.ULID) ([]theauth.SAMLConnection, error)
SAMLConnectionsByOrg lists an organization's connections, oldest first.
func (*Store) SAMLIdentityByConnectionAndNameID ¶ added in v0.2.0
func (s *Store) SAMLIdentityByConnectionAndNameID(ctx context.Context, connectionID theauth.ULID, nameID string) (*theauth.SAMLIdentity, error)
SAMLIdentityByConnectionAndNameID returns the identity for a NameID on a connection.
func (*Store) SCIMTokenByHash ¶ added in v0.2.0
SCIMTokenByHash returns the token row for a hash, including revoked ones.
func (*Store) SCIMTokensByOrg ¶ added in v0.2.0
func (s *Store) SCIMTokensByOrg(ctx context.Context, orgID theauth.ULID) ([]theauth.SCIMToken, error)
SCIMTokensByOrg lists an organization's tokens, oldest first.
func (*Store) SessionByID ¶
SessionByID returns the session with the given ID.
func (*Store) SessionByTokenHash ¶
SessionByTokenHash returns the session for a token hash, including revoked and expired ones.
func (*Store) SetGroupMembers ¶ added in v0.2.0
func (s *Store) SetGroupMembers(ctx context.Context, groupID theauth.ULID, userIDs []theauth.ULID) error
SetGroupMembers replaces the member set atomically.
func (*Store) SetMustChangePassword ¶ added in v0.2.0
func (s *Store) SetMustChangePassword(ctx context.Context, userID theauth.ULID, required bool) error
SetMustChangePassword sets or clears the forced password change flag.
func (*Store) SetRolePermissions ¶ added in v0.2.0
func (s *Store) SetRolePermissions(ctx context.Context, roleID theauth.ULID, permissionIDs []theauth.ULID) error
SetRolePermissions replaces a role's permission set atomically.
func (*Store) SetSessionActiveOrganization ¶ added in v0.2.0
func (s *Store) SetSessionActiveOrganization(ctx context.Context, sessionID theauth.ULID, orgID *theauth.ULID) error
SetSessionActiveOrganization points a session at an organization, or clears it when orgID is nil.
func (*Store) SetSessionElevatedUntil ¶
func (s *Store) SetSessionElevatedUntil(ctx context.Context, id theauth.ULID, until *time.Time) error
SetSessionElevatedUntil sets or clears the step-up window of one session.
func (*Store) SetUserDisabledAt ¶ added in v0.2.0
SetUserDisabledAt disables the user at the given time, or re-enables it when at is nil.
func (*Store) SetUserPassword ¶
func (s *Store) SetUserPassword(ctx context.Context, userID theauth.ULID, passwordHash string) error
SetUserPassword upserts the user's PHC hash and returns ErrStorageNotFound for an unknown user.
func (*Store) SignalsStore ¶ added in v0.2.0
SignalsStore returns a signals.Store backed by this database. Pass it as SharedSignalsConfig.Store.
func (*Store) SweepExpired ¶
SweepExpired deletes expired rows (sessions, magic links, reset tokens, trusted devices, session links, device codes, join tokens). Consumed tokens go only once expired, so replay detection is not weakened early. Tables from migrations the host has not applied are skipped.
func (*Store) SweepExpiredJTIs ¶ added in v0.3.0
SweepExpiredJTIs removes every jti that expired before the given time.
func (*Store) TOTPSecretByUserID ¶
func (s *Store) TOTPSecretByUserID(ctx context.Context, userID theauth.ULID) (*theauth.TOTPSecret, error)
TOTPSecretByUserID returns the user's secret row.
func (*Store) ThrottleStore ¶
func (s *Store) ThrottleStore() *ThrottleStore
ThrottleStore returns a login throttle store backed by the same database and table prefix.
func (*Store) TouchAPITokenLastUsed ¶
TouchAPITokenLastUsed records the last use time of a token.
func (*Store) TouchBackchannelPoll ¶ added in v0.3.0
func (s *Store) TouchBackchannelPoll(ctx context.Context, authReqID string, now time.Time, newInterval int) (theauth.BackchannelRequest, error)
TouchBackchannelPoll implements theauth.CIBAStorage in one UPDATE ... RETURNING.
func (*Store) TouchDevice ¶ added in v0.2.0
TouchDevice stamps last_seen_at.
func (*Store) TouchSAMLIdentityLastLogin ¶ added in v0.2.0
func (s *Store) TouchSAMLIdentityLastLogin(ctx context.Context, id theauth.ULID, at time.Time) error
TouchSAMLIdentityLastLogin records a login time on an identity.
func (*Store) TouchSCIMTokenLastUsed ¶ added in v0.2.0
TouchSCIMTokenLastUsed records the last successful use of a token.
func (*Store) TouchSession ¶
TouchSession advances last-seen time and never moves it backwards.
func (*Store) TouchTrustedDevice ¶ added in v0.2.0
TouchTrustedDevice sets LastUsedAt.
func (*Store) TrustedDeviceByTokenHash ¶ added in v0.2.0
func (s *Store) TrustedDeviceByTokenHash(ctx context.Context, userID theauth.ULID, hash []byte) (*theauth.TrustedDevice, error)
TrustedDeviceByTokenHash returns the record for userID and hash, revoked or expired rows included.
func (*Store) UpdateAgentCredentialLastUsed ¶ added in v0.3.0
func (s *Store) UpdateAgentCredentialLastUsed(ctx context.Context, id theauth.ULID, at time.Time) error
UpdateAgentCredentialLastUsed records credential use. Like Postgres it does not fail on a missing row.
func (*Store) UpdateAgentLastActive ¶ added in v0.3.0
UpdateAgentLastActive records the last activity time.
func (*Store) UpdateAgentStatus ¶ added in v0.3.0
func (s *Store) UpdateAgentStatus(ctx context.Context, id theauth.ULID, status string, _ time.Time) error
UpdateAgentStatus sets the lifecycle status. The service layer owns the state machine; a single UPDATE serializes concurrent changes.
func (*Store) UpdateBackchannelRequest ¶ added in v0.3.0
UpdateBackchannelRequest implements theauth.CIBAStorage. Mutable fields are written only while the row is still pending, in one conditional UPDATE, so approval or denial happens exactly once under concurrency.
func (*Store) UpdateGroup ¶ added in v0.2.0
UpdateGroup rewrites a group's display name and external ID.
func (*Store) UpdateJWKSKeyState ¶ added in v0.3.0
UpdateJWKSKeyState implements theauth.OAuthServerStorage, stamping promoted_at or retired_at on transition. An unknown kid is ErrStorageNotFound.
func (*Store) UpdateOAuthClient ¶ added in v0.3.0
func (s *Store) UpdateOAuthClient(ctx context.Context, c theauth.OAuthClient) (theauth.OAuthClient, error)
UpdateOAuthClient implements theauth.OAuthServerStorage. Owner, secret hash and creation time are immutable here, matching the other backends.
func (*Store) UpdateOrganization ¶ added in v0.2.0
UpdateOrganization rewrites the name and slug and returns ErrSlugTaken on a duplicate slug.
func (*Store) UpdateRoleRow ¶ added in v0.2.0
UpdateRoleRow rewrites a role's name and description.
func (*Store) UpdateSAMLConnectionRow ¶ added in v0.2.0
UpdateSAMLConnectionRow rewrites the IdP and SP settings of a connection.
func (*Store) UpdateSessionAuthLevel ¶
UpdateSessionAuthLevel rewrites one session's auth level.
func (*Store) UpdateUserSCIM ¶ added in v0.2.0
UpdateUserSCIM rewrites the SCIM-managed profile fields of a user.
func (*Store) UpdateWebAuthnBackupFlags ¶
func (s *Store) UpdateWebAuthnBackupFlags(ctx context.Context, credentialID []byte, backupEligible, backupState bool) error
UpdateWebAuthnBackupFlags records BE and BS flags, and is a no-op for a missing credential.
func (*Store) UpdateWebAuthnSignCount ¶
func (s *Store) UpdateWebAuthnSignCount(ctx context.Context, credentialID []byte, newCount uint32, usedAt time.Time) error
UpdateWebAuthnSignCount writes a strictly greater count, else ErrReplayDetected or ErrStorageNotFound.
func (*Store) UpsertOAuthAccount ¶
func (s *Store) UpsertOAuthAccount(ctx context.Context, a theauth.OAuthAccount) (theauth.OAuthAccount, error)
UpsertOAuthAccount inserts or refreshes the tokens of a (provider, provider user) pair.
func (*Store) UpsertOrganizationMember ¶ added in v0.2.0
UpsertOrganizationMember adds a member or updates the role of an existing one.
func (*Store) UpsertPendingTOTPSecret ¶
UpsertPendingTOTPSecret writes an unconfirmed secret and leaves a confirmed one untouched.
func (*Store) UpsertSAMLIdentity ¶ added in v0.2.0
func (s *Store) UpsertSAMLIdentity(ctx context.Context, i theauth.SAMLIdentity) (theauth.SAMLIdentity, error)
UpsertSAMLIdentity inserts the (connection, NameID) identity or rebinds an existing one.
func (*Store) UserByEmail ¶
UserByEmail returns the user with the given email, compared case-insensitively.
func (*Store) UserByEmailWithPassword ¶
func (s *Store) UserByEmailWithPassword(ctx context.Context, email string) (*theauth.User, string, error)
UserByEmailWithPassword returns the user and their hash, empty when no password is set.
func (*Store) UserByExternalIDInOrg ¶ added in v0.2.0
func (s *Store) UserByExternalIDInOrg(ctx context.Context, orgID theauth.ULID, externalID string) (*theauth.User, error)
UserByExternalIDInOrg returns the organization member carrying the SCIM external ID.
func (*Store) UserPasswordHashByID ¶
UserPasswordHashByID returns the stored hash, or "" when the user has none.
func (*Store) VerifyAuditChain ¶ added in v0.3.0
func (s *Store) VerifyAuditChain(ctx context.Context) (AuditChainResult, error)
VerifyAuditChain walks every chain in seq order and reports the first mismatched row. Pre-0017 rows count as Unchained; erased rows verify via their pseudonyms and count as Erased.
func (*Store) WebAuthnCredentialByCredentialID ¶
func (s *Store) WebAuthnCredentialByCredentialID(ctx context.Context, credentialID []byte) (*theauth.WebAuthnCredential, error)
WebAuthnCredentialByCredentialID looks up a credential by its authenticator ID.
func (*Store) WebAuthnCredentialsByUserID ¶
func (s *Store) WebAuthnCredentialsByUserID(ctx context.Context, userID theauth.ULID) ([]theauth.WebAuthnCredential, error)
WebAuthnCredentialsByUserID lists a user's credentials oldest first.
type SweepResult ¶
type SweepResult struct {
Sessions int64
MagicLinks int64
PasswordResetTokens int64
TrustedDevices int64
SessionLinks int64
DeviceCodes int64
DeviceJoinTokens int64
}
SweepResult counts rows removed by SweepExpired.
type ThrottleStore ¶
type ThrottleStore struct {
// contains filtered or unexported fields
}
ThrottleStore is a SQLite-backed theauth.LoginThrottleStore shared by every process using the database.
func (*ThrottleStore) CompareAndSwap ¶
func (t *ThrottleStore) CompareAndSwap(ctx context.Context, key string, prev theauth.LoginThrottleEntry, prevExists bool, next theauth.LoginThrottleEntry) (bool, error)
CompareAndSwap writes next only when the stored entry still equals prev, or is absent when prevExists is false.
func (*ThrottleStore) Delete ¶
func (t *ThrottleStore) Delete(ctx context.Context, key string) error
Delete removes key.
func (*ThrottleStore) DeleteLoginEntries ¶ added in v0.2.0
func (t *ThrottleStore) DeleteLoginEntries(ctx context.Context, ident string) error
DeleteLoginEntries removes every login backoff entry for ident across all client IPs.
func (*ThrottleStore) Get ¶
func (t *ThrottleStore) Get(ctx context.Context, key string) (theauth.LoginThrottleEntry, bool, error)
Get returns the entry for key.
func (*ThrottleStore) Set ¶
func (t *ThrottleStore) Set(ctx context.Context, key string, e theauth.LoginThrottleEntry) error
Set stores e under key unconditionally.
func (*ThrottleStore) SweepExpired ¶
SweepExpired deletes entries whose ExpiresAt is at or before now and returns how many it removed.
Source Files
¶
- agents.go
- apitoken_caps.go
- as_assert.go
- as_clients.go
- as_codes.go
- as_common.go
- as_device.go
- as_jwks.go
- as_opaque.go
- as_par.go
- as_refresh.go
- audit.go
- audit_chain.go
- ciba.go
- delegations.go
- device_identity_caps.go
- doc.go
- jwtbearer.go
- lifecycle.go
- migrate.go
- oauth.go
- oauth_server_assert.go
- org_caps.go
- passwords.go
- rbac_caps.go
- saml_caps.go
- scim_caps.go
- sessions.go
- sessions_auth.go
- signals.go
- sqlite.go
- storage_hardening.go
- storage_mfa_caps.go
- storage_sessions.go
- sweep.go
- throttle.go
- tool_approvals.go
- totp.go
- users.go
- webauthn.go