Documentation
¶
Overview ¶
Package postgres provides a production-grade implementation of theauth.Storage backed by PostgreSQL through pgx and sqlc-generated query bindings.
Migrations live under migrations/ and are append-only: a renamed column ships as a new migration. Use the in-package New constructor with a pgxpool.Pool. See docs/STABILITY.md for the rules that govern future schema and query changes.
Package postgres: migrate.go exposes a runtime applier for the embedded SQL migration files under storage/postgres/migrations. Consumers call Migrate once at boot before constructing the Store, so the schema is in place when theauth.New attaches.
Migrate is safe to call concurrently across replicas: it acquires a transaction-scoped Postgres advisory lock so only one replica drives a migration at a time. The applied versions are recorded in the theauth_schema_migrations table; reruns are no-ops.
Package postgres provides a Postgres-backed storage.Storage implementation built on top of sqlc-generated queries and pgx/v5.
Index ¶
- func Migrate(ctx context.Context, pool *pgxpool.Pool) error
- 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) APITokensByOwner(ctx context.Context, ownerID theauth.ULID) ([]theauth.APIToken, 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) 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) 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) 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) 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) 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) 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) DeleteWebAuthnCredential(ctx context.Context, id theauth.ULID, userID theauth.ULID) 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) 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) InsertDeviceCode(ctx context.Context, d theauth.DeviceCode) error
- func (s *Store) InsertGroup(ctx context.Context, g theauth.Group) (theauth.Group, 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) 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) 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) InsertWebAuthnCredential(ctx context.Context, c theauth.WebAuthnCredential) (theauth.WebAuthnCredential, 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) 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) 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) 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) RecordDevicePoll(ctx context.Context, hash []byte, at time.Time, intervalSeconds int) error
- func (s *Store) RefreshTokenByHash(ctx context.Context, hash []byte) (*theauth.RefreshToken, 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) 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) 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) RevokeUserRole(ctx context.Context, userID, roleID theauth.ULID) error
- func (s *Store) RevokeUserSessions(ctx context.Context, userID theauth.ULID) 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) 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) SetUserPassword(ctx context.Context, userID theauth.ULID, passwordHash string) 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) 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) 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) WebAuthnCredentialByCredentialID(ctx context.Context, credentialID []byte) (*theauth.WebAuthnCredential, error)
- func (s *Store) WebAuthnCredentialsByUserID(ctx context.Context, userID theauth.ULID) ([]theauth.WebAuthnCredential, error)
- 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 ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Migrate ¶
Migrate applies every embedded up migration that has not already been recorded in theauth_schema_migrations, in version order, under a Postgres transaction-scoped advisory lock. Returns nil when the schema is at the latest version. Callers should invoke Migrate before constructing theauth.New(...) so the storage adapter sees a fully-migrated schema.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the Postgres-backed storage adapter.
func (*Store) APITokenByHash ¶
APITokenByHash returns the token with the given secret hash, else ErrNotFound.
func (*Store) APITokenByID ¶
APITokenByID returns the token with the given ID, else ErrNotFound.
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) AddGroupMembers ¶
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 ¶
func (*Store) AgentCredentialsByAgentID ¶
func (*Store) AgentsByOwner ¶
func (*Store) AtomicRotateJWKS ¶
func (s *Store) AtomicRotateJWKS(ctx context.Context, retireKIDs []string, demoteKID, promoteKID string, freshKey theauth.JWKSKey, now time.Time) error
AtomicRotateJWKS implements as.JWKSAtomicRotator. It wraps the entire JWKS rotation state transition in a single serializable transaction so that concurrent callers cannot produce two rows with state = current.
The theauth_jwks_one_current partial unique index (migration 0015) enforces this invariant at the database level as a belt-and-suspenders guard.
func (*Store) BackchannelRequestByID ¶
func (s *Store) BackchannelRequestByID(ctx context.Context, authReqID string) (theauth.BackchannelRequest, error)
BackchannelRequestByID satisfies CIBAStorage.
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 ¶
func (*Store) ConsumeAuthorizationCode ¶
func (s *Store) ConsumeAuthorizationCode(ctx context.Context, code string) (*theauth.AuthorizationCode, error)
ConsumeAuthorizationCode uses DELETE ... RETURNING for atomicity: exactly one of N concurrent callers wins per code.
func (*Store) ConsumeMagicLink ¶
func (*Store) ConsumePasswordResetToken ¶
func (*Store) ConsumePushedRequest ¶
ConsumePushedRequest atomically marks the row as consumed and returns the payload. Returns ErrNotFound when:
- the request_uri does not exist
- the row has already been consumed (consumed_at IS NOT NULL)
- the row is expired (expires_at <= now)
func (*Store) ConsumeRecoveryCode ¶
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 ErrNotFound.
func (*Store) CountUnusedRecoveryCodes ¶
CountUnusedRecoveryCodes implements theauth.RecoveryCodeStorage.
func (*Store) CountUsers ¶
CountUsers returns the number of user rows.
func (*Store) CountUsersWithPermissionInOrg ¶
func (*Store) CreateMagicLink ¶
func (*Store) CreatePasswordResetToken ¶
func (*Store) CreateSession ¶
CreateSession inserts a session with the default full auth level.
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 inserts a session with its own auth level.
func (*Store) CreateUser ¶
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 ¶
func (*Store) DelegationGrantByUserAgentResource ¶
func (*Store) DelegationGrantsByAgentID ¶
func (*Store) DelegationGrantsByUserID ¶
func (*Store) DeleteBackchannelRequest ¶
DeleteBackchannelRequest satisfies CIBAStorage.
func (*Store) DeleteExpiredDeviceCodes ¶
DeleteExpiredDeviceCodes removes requests that expired before the cutoff.
func (*Store) DeleteOAuthAccountByProvider ¶
func (s *Store) DeleteOAuthAccountByProvider(ctx context.Context, userID theauth.ULID, provider string) error
DeleteOAuthAccountByProvider removes the row for (userID, provider).
func (*Store) DeleteOAuthClient ¶
func (*Store) DeleteOrganization ¶
func (*Store) DeleteOrganizationMember ¶
func (*Store) DeleteSAMLConnection ¶
func (*Store) DeleteTOTPSecret ¶
func (*Store) DeleteWebAuthnCredential ¶
func (*Store) DeviceCodeByHash ¶
DeviceCodeByHash returns the request with the given device code hash, else ErrNotFound.
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 ErrNotFound.
func (*Store) GrantUserRole ¶
func (*Store) GroupByExternalIDInOrg ¶
func (*Store) GroupMembers ¶
func (*Store) InsertAPIToken ¶
InsertAPIToken stores a token and returns the stored row.
func (*Store) InsertAgent ¶
func (*Store) InsertAgentCredential ¶
func (*Store) InsertAuditEvents ¶
func (*Store) InsertAuthorizationCode ¶
func (*Store) InsertBackchannelRequest ¶
InsertBackchannelRequest satisfies CIBAStorage.
func (*Store) InsertDelegationGrant ¶
func (s *Store) InsertDelegationGrant(ctx context.Context, g theauth.DelegationGrant) (theauth.DelegationGrant, error)
func (*Store) InsertDeviceCode ¶
InsertDeviceCode stores a request, returning ErrDeviceUserCodeTaken on a user code collision.
func (*Store) InsertGroup ¶
func (*Store) InsertJWKSKey ¶
func (*Store) InsertOAuthClient ¶
func (s *Store) InsertOAuthClient(ctx context.Context, c theauth.OAuthClient) (theauth.OAuthClient, error)
func (*Store) InsertOrganization ¶
func (s *Store) InsertOrganization(ctx context.Context, o theauth.Organization) (theauth.Organization, error)
func (*Store) InsertPermission ¶
func (s *Store) InsertPermission(ctx context.Context, p theauth.Permission) (theauth.Permission, error)
func (*Store) InsertPushedRequest ¶
func (s *Store) InsertPushedRequest(ctx context.Context, requestURI string, payload []byte, expiresAt time.Time) error
InsertPushedRequest stores a pushed authorization request. The requestURI is the full urn: string; payload is the JSON-encoded AuthorizeRequest; expiresAt is the absolute expiry timestamp.
func (*Store) InsertRecoveryCodes ¶
func (*Store) InsertRefreshToken ¶
func (*Store) InsertRole ¶
func (*Store) InsertSAMLConnection ¶
func (s *Store) InsertSAMLConnection(ctx context.Context, c theauth.SAMLConnection) (theauth.SAMLConnection, error)
func (*Store) InsertSCIMToken ¶
func (*Store) InsertWebAuthnCredential ¶
func (s *Store) InsertWebAuthnCredential(ctx context.Context, c theauth.WebAuthnCredential) (theauth.WebAuthnCredential, error)
func (*Store) JWKSKeyByKID ¶
func (*Store) JWKSKeysAll ¶
func (*Store) ListAPITokens ¶
ListAPITokens returns every token, newest first.
func (*Store) ListGroupsByOrganization ¶
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 ¶
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 ¶
func (*Store) MarkEmailVerified ¶
func (*Store) MoveOAuthAccount ¶
func (s *Store) MoveOAuthAccount(ctx context.Context, provider, providerUserID string, newUserID theauth.ULID) error
MoveOAuthAccount reassigns the row keyed by (provider, providerUserID) to newUserID.
func (*Store) MovePasswordHash ¶
MovePasswordHash copies the Argon2id hash from secondaryID to primaryID, overwriting any existing hash for primaryID, then clears secondaryID's row. A no-op when secondaryID has no password row.
func (*Store) MoveTOTPSecret ¶
MoveTOTPSecret reassigns the TOTP secret from secondaryID to primaryID. If primaryID already has a confirmed TOTP secret the secondary row is deleted without overwriting the active primary factor.
func (*Store) MoveWebAuthnCredentials ¶
func (s *Store) MoveWebAuthnCredentials(ctx context.Context, primaryID, secondaryID theauth.ULID) error
MoveWebAuthnCredentials reassigns every WebAuthn credential row from secondaryID to primaryID.
func (*Store) OAuthAccountByProviderUserID ¶
func (*Store) OAuthAccountsByUserID ¶
func (s *Store) OAuthAccountsByUserID(ctx context.Context, userID theauth.ULID) ([]theauth.OAuthAccount, error)
OAuthAccountsByUserID returns every oauth_accounts row linked to userID.
func (*Store) OAuthClientByClientID ¶
func (*Store) OrganizationByID ¶
func (*Store) OrganizationBySlug ¶
func (*Store) OrganizationMemberRole ¶
func (*Store) OrganizationMembersByOrg ¶
func (*Store) OrganizationsByUser ¶
func (*Store) PermissionByName ¶
func (*Store) PermissionsByRole ¶
func (*Store) PermissionsForUser ¶
func (*Store) QueryAuditEvents ¶
func (s *Store) QueryAuditEvents(ctx context.Context, q theauth.AuditQuery) ([]theauth.AuditEvent, string, error)
QueryAuditEvents is hand-built because the filter combinations vary too much for a fixed sqlc query. The query is keyset-paginated on (created_at DESC, id DESC) so it stays efficient as audit_events grows.
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) RefreshTokenByHash ¶
func (*Store) RemoveGroupMembers ¶
func (*Store) RenameWebAuthnCredential ¶
func (s *Store) RenameWebAuthnCredential(ctx context.Context, id, userID theauth.ULID, name string) error
RenameWebAuthnCredential implements theauth.WebAuthnRenameStorage.
func (*Store) ReplaceRecoveryCodes ¶
func (s *Store) ReplaceRecoveryCodes(ctx context.Context, userID theauth.ULID, codes []theauth.RecoveryCode) error
ReplaceRecoveryCodes implements theauth.RecoveryCodeStorage.
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 ¶
func (*Store) RevokeDelegationGrant ¶
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 ¶
func (*Store) RevokeRefreshTokenFamily ¶
func (*Store) RevokeSCIMTokenByID ¶
func (*Store) RevokeSession ¶
func (*Store) RevokeSessionsByCredential ¶
RevokeSessionsByCredential revokes every live session bound to credentialID and returns the count.
func (*Store) RevokeUserRole ¶
func (*Store) RevokeUserSessions ¶
func (*Store) RoleByOrgAndName ¶
func (*Store) RolesByOrganization ¶
func (*Store) RolesForUser ¶
func (*Store) SAMLConnectionByID ¶
func (*Store) SAMLConnectionsByOrg ¶
func (*Store) SAMLIdentityByConnectionAndNameID ¶
func (*Store) SCIMTokenByHash ¶
func (*Store) SCIMTokensByOrg ¶
func (*Store) SessionByID ¶
SessionByID returns the session with the given ID.
func (*Store) SessionByTokenHash ¶
SessionByTokenHash returns the session with the given token hash.
func (*Store) SetGroupMembers ¶
func (*Store) SetRolePermissions ¶
func (*Store) SetSessionActiveOrganization ¶
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) SetUserPassword ¶
func (*Store) TOTPSecretByUserID ¶
func (*Store) ThrottleStore ¶
func (s *Store) ThrottleStore() *ThrottleStore
ThrottleStore returns a login throttle store backed by the same database.
func (*Store) TouchAPITokenLastUsed ¶
TouchAPITokenLastUsed records the last use time of a token.
func (*Store) TouchBackchannelPoll ¶
func (s *Store) TouchBackchannelPoll(ctx context.Context, authReqID string, now time.Time, newInterval int) (theauth.BackchannelRequest, error)
TouchBackchannelPoll satisfies CIBAStorage. Updates last_poll_at and poll_interval atomically and returns the updated row.
func (*Store) TouchSAMLIdentityLastLogin ¶
func (*Store) TouchSCIMTokenLastUsed ¶
func (*Store) TouchSession ¶
TouchSession advances last-seen time and never moves it backwards.
func (*Store) UpdateAgentCredentialLastUsed ¶
func (*Store) UpdateAgentLastActive ¶
func (*Store) UpdateAgentStatus ¶
func (*Store) UpdateBackchannelRequest ¶
UpdateBackchannelRequest satisfies CIBAStorage. Writes all mutable fields.
func (*Store) UpdateJWKSKeyState ¶
func (*Store) UpdateOAuthClient ¶
func (s *Store) UpdateOAuthClient(ctx context.Context, c theauth.OAuthClient) (theauth.OAuthClient, error)
func (*Store) UpdateOrganization ¶
func (*Store) UpdateRoleRow ¶
func (*Store) UpdateSAMLConnectionRow ¶
func (*Store) UpdateSessionAuthLevel ¶
func (*Store) UpdateUserSCIM ¶
func (*Store) UpdateWebAuthnBackupFlags ¶
func (s *Store) UpdateWebAuthnBackupFlags(ctx context.Context, credentialID []byte, backupEligible, backupState bool) error
UpdateWebAuthnBackupFlags records the BE / BS flags for a credential that had none stored (trust-on-first-use reconciliation for legacy synced passkeys). A missing credential returns nil (not an error): the caller treats reconciliation as best-effort and must not fail a verified login.
func (*Store) UpdateWebAuthnSignCount ¶
func (s *Store) UpdateWebAuthnSignCount(ctx context.Context, credentialID []byte, newCount uint32, usedAt time.Time) error
UpdateWebAuthnSignCount executes the strictly-greater UPDATE; zero rows affected with the credential present means the supplied count was not strictly greater than the stored one, which is the WebAuthn replay signal. We disambiguate "no such credential" from "replay" via a follow up SELECT only when the UPDATE is a miss, to keep the happy path single round-trip.
func (*Store) UpsertOAuthAccount ¶
func (s *Store) UpsertOAuthAccount(ctx context.Context, a theauth.OAuthAccount) (theauth.OAuthAccount, error)
func (*Store) UpsertOrganizationMember ¶
func (*Store) UpsertPendingTOTPSecret ¶
func (*Store) UpsertSAMLIdentity ¶
func (s *Store) UpsertSAMLIdentity(ctx context.Context, i theauth.SAMLIdentity) (theauth.SAMLIdentity, error)
func (*Store) UserByEmail ¶
func (*Store) UserByEmailWithPassword ¶
func (*Store) UserByExternalIDInOrg ¶
func (*Store) UserPasswordHashByID ¶
UserPasswordHashByID returns the stored Argon2id PHC string for the user, or "" when no password row exists.
func (*Store) WebAuthnCredentialByCredentialID ¶
func (*Store) WebAuthnCredentialsByUserID ¶
type ThrottleStore ¶
type ThrottleStore struct {
// contains filtered or unexported fields
}
ThrottleStore is a Postgres-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 v2.7.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.