postgres

package
v2.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 23 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 https://docs.theauth.dev/go/reference/stability 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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(ctx context.Context, pool *pgxpool.Pool) error

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 New

func New(pool *pgxpool.Pool) *Store

New constructs a Store using the given pgxpool.Pool.

func (*Store) APITokenByHash

func (s *Store) APITokenByHash(ctx context.Context, hash []byte) (*theauth.APIToken, error)

APITokenByHash returns the token with the given secret hash, else ErrNotFound.

func (*Store) APITokenByID

func (s *Store) APITokenByID(ctx context.Context, id theauth.ULID) (*theauth.APIToken, error)

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 (s *Store) AddGroupMembers(ctx context.Context, groupID theauth.ULID, userIDs []theauth.ULID) error

func (*Store) AdvanceTOTPStep

func (s *Store) AdvanceTOTPStep(ctx context.Context, userID theauth.ULID, step int64) (bool, error)

AdvanceTOTPStep records step as the user's last used TOTP step, returning false when it is not strictly newer.

func (*Store) AgentByClientID

func (s *Store) AgentByClientID(ctx context.Context, clientID string) (*theauth.Agent, error)

func (*Store) AgentByID

func (s *Store) AgentByID(ctx context.Context, id theauth.ULID) (*theauth.Agent, error)

func (*Store) AgentCredentialsByAgentID

func (s *Store) AgentCredentialsByAgentID(ctx context.Context, agentID theauth.ULID) ([]theauth.AgentCredential, error)

func (*Store) AgentsByOwner

func (s *Store) AgentsByOwner(ctx context.Context, owner theauth.AgentOwner) ([]theauth.Agent, error)

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 (s *Store) ConfirmTOTPSecret(ctx context.Context, userID theauth.ULID, at time.Time) error

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) ConsumeDeviceAuthorization added in v2.8.0

func (s *Store) ConsumeDeviceAuthorization(ctx context.Context, id theauth.ULID, now time.Time) (bool, error)

ConsumeDeviceAuthorization satisfies DeviceAuthorizationStorage.

func (s *Store) ConsumeMagicLink(ctx context.Context, tokenHash []byte) (*theauth.MagicLink, error)

func (*Store) ConsumePasswordResetToken

func (s *Store) ConsumePasswordResetToken(ctx context.Context, tokenHash []byte) (*theauth.PasswordResetToken, error)

func (*Store) ConsumePushedRequest

func (s *Store) ConsumePushedRequest(ctx context.Context, requestURI string) ([]byte, error)

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 (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)

ConsumeSessionLink atomically marks an unused, unexpired link used and returns it, else ErrNotFound.

func (*Store) CountUnusedRecoveryCodes

func (s *Store) CountUnusedRecoveryCodes(ctx context.Context, userID theauth.ULID) (int, error)

CountUnusedRecoveryCodes implements theauth.RecoveryCodeStorage.

func (*Store) CountUsers

func (s *Store) CountUsers(ctx context.Context) (int, error)

CountUsers returns the number of user rows.

func (*Store) CountUsersWithPermissionInOrg

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 (*Store) CreatePasswordResetToken

func (s *Store) CreatePasswordResetToken(ctx context.Context, t theauth.PasswordResetToken) error

func (*Store) CreateSession

func (s *Store) CreateSession(ctx context.Context, sess theauth.Session) (theauth.Session, error)

CreateSession inserts a session with the default full auth level.

func (s *Store) CreateSessionLink(ctx context.Context, l theauth.SessionLink) error

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 (s *Store) CreateUser(ctx context.Context, u theauth.User) (theauth.User, error)

func (*Store) DecideDeviceAuthorization added in v2.8.0

func (s *Store) DecideDeviceAuthorization(ctx context.Context, id theauth.ULID, status string, userID theauth.ULID, now time.Time) (bool, error)

DecideDeviceAuthorization satisfies DeviceAuthorizationStorage.

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 (s *Store) DelegationGrantByID(ctx context.Context, id theauth.ULID) (*theauth.DelegationGrant, error)

func (*Store) DelegationGrantByUserAgentResource

func (s *Store) DelegationGrantByUserAgentResource(ctx context.Context, userID, agentID theauth.ULID, resource string) (*theauth.DelegationGrant, error)

func (*Store) DelegationGrantsByAgentID

func (s *Store) DelegationGrantsByAgentID(ctx context.Context, agentID theauth.ULID) ([]theauth.DelegationGrant, error)

func (*Store) DelegationGrantsByUserID

func (s *Store) DelegationGrantsByUserID(ctx context.Context, userID theauth.ULID) ([]theauth.DelegationGrant, error)

func (*Store) DeleteBackchannelRequest

func (s *Store) DeleteBackchannelRequest(ctx context.Context, authReqID string) error

DeleteBackchannelRequest satisfies CIBAStorage.

func (*Store) DeleteExpiredDeviceAuthorizations added in v2.8.0

func (s *Store) DeleteExpiredDeviceAuthorizations(ctx context.Context, before time.Time) (int64, error)

DeleteExpiredDeviceAuthorizations satisfies DeviceAuthorizationStorage.

func (*Store) DeleteExpiredDeviceCodes

func (s *Store) DeleteExpiredDeviceCodes(ctx context.Context, before time.Time) (int, error)

DeleteExpiredDeviceCodes removes requests that expired before the cutoff.

func (*Store) DeleteGroup

func (s *Store) DeleteGroup(ctx context.Context, id theauth.ULID) error

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 (s *Store) DeleteOAuthClient(ctx context.Context, clientID string) error

func (*Store) DeleteOrganization

func (s *Store) DeleteOrganization(ctx context.Context, id theauth.ULID) error

func (*Store) DeleteOrganizationMember

func (s *Store) DeleteOrganizationMember(ctx context.Context, orgID, userID theauth.ULID) error

func (*Store) DeleteRole

func (s *Store) DeleteRole(ctx context.Context, id theauth.ULID) error

func (*Store) DeleteSAMLConnection

func (s *Store) DeleteSAMLConnection(ctx context.Context, id theauth.ULID) error

func (*Store) DeleteTOTPSecret

func (s *Store) DeleteTOTPSecret(ctx context.Context, userID theauth.ULID) error

func (*Store) DeleteWebAuthnCredential

func (s *Store) DeleteWebAuthnCredential(ctx context.Context, id theauth.ULID, userID theauth.ULID) error

func (*Store) DenyAccessToken added in v2.8.0

func (s *Store) DenyAccessToken(ctx context.Context, jti string, expiresAt time.Time) error

DenyAccessToken records jti as revoked until expiresAt (opt-in access token revocation).

func (*Store) DeviceAuthorizationByDeviceCodeHash added in v2.8.0

func (s *Store) DeviceAuthorizationByDeviceCodeHash(ctx context.Context, hash []byte) (*theauth.DeviceAuthorization, error)

DeviceAuthorizationByDeviceCodeHash satisfies DeviceAuthorizationStorage.

func (*Store) DeviceAuthorizationByUserCodeHash added in v2.8.0

func (s *Store) DeviceAuthorizationByUserCodeHash(ctx context.Context, hash []byte) (*theauth.DeviceAuthorization, error)

DeviceAuthorizationByUserCodeHash satisfies DeviceAuthorizationStorage.

func (*Store) DeviceCodeByHash

func (s *Store) DeviceCodeByHash(ctx context.Context, hash []byte) (*theauth.DeviceCode, error)

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 (s *Store) GrantUserRole(ctx context.Context, ur theauth.UserRole) error

func (*Store) GroupByExternalIDInOrg

func (s *Store) GroupByExternalIDInOrg(ctx context.Context, orgID theauth.ULID, externalID string) (*theauth.Group, error)

func (*Store) GroupByID

func (s *Store) GroupByID(ctx context.Context, id theauth.ULID) (*theauth.Group, error)

func (*Store) GroupMembers

func (s *Store) GroupMembers(ctx context.Context, groupID theauth.ULID) ([]theauth.ULID, error)

func (*Store) InsertAPIToken

func (s *Store) InsertAPIToken(ctx context.Context, t theauth.APIToken) (theauth.APIToken, error)

InsertAPIToken stores a token and returns the stored row.

func (*Store) InsertAgent

func (s *Store) InsertAgent(ctx context.Context, a theauth.Agent) (theauth.Agent, error)

func (*Store) InsertAgentCredential

func (s *Store) InsertAgentCredential(ctx context.Context, c theauth.AgentCredential) error

func (*Store) InsertAuditEvents

func (s *Store) InsertAuditEvents(ctx context.Context, events []theauth.AuditEvent) error

func (*Store) InsertAuthorizationCode

func (s *Store) InsertAuthorizationCode(ctx context.Context, c theauth.AuthorizationCode) error

func (*Store) InsertBackchannelRequest

func (s *Store) InsertBackchannelRequest(ctx context.Context, req theauth.BackchannelRequest) error

InsertBackchannelRequest satisfies CIBAStorage.

func (*Store) InsertDelegationGrant

func (s *Store) InsertDelegationGrant(ctx context.Context, g theauth.DelegationGrant) (theauth.DelegationGrant, error)

func (*Store) InsertDeviceAuthorization added in v2.8.0

func (s *Store) InsertDeviceAuthorization(ctx context.Context, d theauth.DeviceAuthorization) error

InsertDeviceAuthorization satisfies DeviceAuthorizationStorage.

func (*Store) InsertDeviceCode

func (s *Store) InsertDeviceCode(ctx context.Context, d theauth.DeviceCode) error

InsertDeviceCode stores a request, returning ErrDeviceUserCodeTaken on a user code collision.

func (*Store) InsertGroup

func (s *Store) InsertGroup(ctx context.Context, g theauth.Group) (theauth.Group, error)

func (*Store) InsertJWKSKey

func (s *Store) InsertJWKSKey(ctx context.Context, k theauth.JWKSKey) error

func (*Store) InsertOAuthClient

func (s *Store) InsertOAuthClient(ctx context.Context, c theauth.OAuthClient) (theauth.OAuthClient, error)

func (*Store) InsertOpaqueAccessToken added in v2.8.0

func (s *Store) InsertOpaqueAccessToken(ctx context.Context, t theauth.OpaqueAccessToken) error

InsertOpaqueAccessToken satisfies OpaqueTokenStorage.

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 (s *Store) InsertRecoveryCodes(ctx context.Context, codes []theauth.RecoveryCode) error

func (*Store) InsertRefreshToken

func (s *Store) InsertRefreshToken(ctx context.Context, t theauth.RefreshToken) error

func (*Store) InsertRegistrationToken added in v2.8.0

func (s *Store) InsertRegistrationToken(ctx context.Context, t theauth.RegistrationToken) error

InsertRegistrationToken satisfies RegistrationTokenStorage.

func (*Store) InsertRole

func (s *Store) InsertRole(ctx context.Context, r theauth.Role) (theauth.Role, error)

func (*Store) InsertSAMLConnection

func (s *Store) InsertSAMLConnection(ctx context.Context, c theauth.SAMLConnection) (theauth.SAMLConnection, error)

func (*Store) InsertSCIMToken

func (s *Store) InsertSCIMToken(ctx context.Context, t theauth.SCIMToken) (theauth.SCIMToken, error)

func (*Store) InsertWebAuthnCredential

func (s *Store) InsertWebAuthnCredential(ctx context.Context, c theauth.WebAuthnCredential) (theauth.WebAuthnCredential, error)

func (*Store) IsAccessTokenDenied added in v2.8.0

func (s *Store) IsAccessTokenDenied(ctx context.Context, jti string) (bool, error)

IsAccessTokenDenied reports whether jti is on the unexpired denylist.

func (*Store) JWKSKeyByKID

func (s *Store) JWKSKeyByKID(ctx context.Context, kid string) (*theauth.JWKSKey, error)

func (*Store) JWKSKeysAll

func (s *Store) JWKSKeysAll(ctx context.Context) ([]theauth.JWKSKey, error)

func (*Store) ListAPITokens

func (s *Store) ListAPITokens(ctx context.Context) ([]theauth.APIToken, error)

ListAPITokens returns every token, newest first.

func (*Store) ListGroupsByOrganization

func (s *Store) ListGroupsByOrganization(ctx context.Context, orgID theauth.ULID, offset, limit int, filter theauth.SCIMGroupFilter) ([]theauth.Group, int, error)

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 (s *Store) ListPermissions(ctx context.Context) ([]theauth.Permission, error)

func (*Store) ListRegistrationTokens added in v2.8.0

func (s *Store) ListRegistrationTokens(ctx context.Context, orgID *theauth.ULID) ([]theauth.RegistrationToken, error)

ListRegistrationTokens satisfies RegistrationTokenStorage.

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 (s *Store) ListUsersByOrganization(ctx context.Context, orgID theauth.ULID, offset, limit int, filter theauth.SCIMUserFilter) ([]theauth.User, int, error)

func (*Store) MarkEmailVerified

func (s *Store) MarkEmailVerified(ctx context.Context, userID theauth.ULID) error

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

func (s *Store) MovePasswordHash(ctx context.Context, primaryID, secondaryID theauth.ULID) error

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

func (s *Store) MoveTOTPSecret(ctx context.Context, primaryID, secondaryID theauth.ULID) error

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 (s *Store) OAuthAccountByProviderUserID(ctx context.Context, provider, providerUserID string) (*theauth.OAuthAccount, error)

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 (s *Store) OAuthClientByClientID(ctx context.Context, clientID string) (*theauth.OAuthClient, error)

func (*Store) OpaqueAccessTokenByHash added in v2.8.0

func (s *Store) OpaqueAccessTokenByHash(ctx context.Context, hash []byte) (*theauth.OpaqueAccessToken, error)

OpaqueAccessTokenByHash satisfies OpaqueTokenStorage.

func (*Store) OrganizationByID

func (s *Store) OrganizationByID(ctx context.Context, id theauth.ULID) (*theauth.Organization, error)

func (*Store) OrganizationBySlug

func (s *Store) OrganizationBySlug(ctx context.Context, slug string) (*theauth.Organization, error)

func (*Store) OrganizationMemberRole

func (s *Store) OrganizationMemberRole(ctx context.Context, orgID, userID theauth.ULID) (string, error)

func (*Store) OrganizationMembersByOrg

func (s *Store) OrganizationMembersByOrg(ctx context.Context, orgID theauth.ULID) ([]theauth.OrganizationMember, error)

func (*Store) OrganizationsByUser

func (s *Store) OrganizationsByUser(ctx context.Context, userID theauth.ULID) ([]theauth.Organization, error)

func (*Store) PermissionByName

func (s *Store) PermissionByName(ctx context.Context, name string) (*theauth.Permission, error)

func (*Store) PermissionsByRole

func (s *Store) PermissionsByRole(ctx context.Context, roleID theauth.ULID) ([]string, error)

func (*Store) PermissionsForUser

func (s *Store) PermissionsForUser(ctx context.Context, userID theauth.ULID, orgID *theauth.ULID) ([]string, error)

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) RecordDeviceAuthorizationPoll added in v2.8.0

func (s *Store) RecordDeviceAuthorizationPoll(ctx context.Context, id theauth.ULID, polledAt time.Time, intervalSeconds int) error

RecordDeviceAuthorizationPoll satisfies DeviceAuthorizationStorage.

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) RedeemRegistrationToken added in v2.8.0

func (s *Store) RedeemRegistrationToken(ctx context.Context, id theauth.ULID, now time.Time) (bool, error)

RedeemRegistrationToken satisfies RegistrationTokenStorage.

func (*Store) RefreshTokenByHash

func (s *Store) RefreshTokenByHash(ctx context.Context, hash []byte) (*theauth.RefreshToken, error)

func (*Store) RefundRegistrationToken added in v2.8.0

func (s *Store) RefundRegistrationToken(ctx context.Context, id theauth.ULID) error

RefundRegistrationToken satisfies RegistrationTokenStorage.

func (*Store) RegistrationTokenByHash added in v2.8.0

func (s *Store) RegistrationTokenByHash(ctx context.Context, hash []byte) (*theauth.RegistrationToken, error)

RegistrationTokenByHash satisfies RegistrationTokenStorage.

func (*Store) RegistrationTokenByID added in v2.8.0

func (s *Store) RegistrationTokenByID(ctx context.Context, id theauth.ULID) (*theauth.RegistrationToken, error)

RegistrationTokenByID satisfies RegistrationTokenStorage.

func (*Store) RemoveGroupMembers

func (s *Store) RemoveGroupMembers(ctx context.Context, groupID theauth.ULID, userIDs []theauth.ULID) error

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

func (s *Store) RevokeAPIToken(ctx context.Context, id theauth.ULID, at time.Time) error

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 (s *Store) RevokeAgentCredential(ctx context.Context, id theauth.ULID, at time.Time) error

func (*Store) RevokeDelegationGrant

func (s *Store) RevokeDelegationGrant(ctx context.Context, id theauth.ULID, at time.Time, reason string) error

func (*Store) RevokeOpaqueAccessToken added in v2.8.0

func (s *Store) RevokeOpaqueAccessToken(ctx context.Context, hash []byte) error

RevokeOpaqueAccessToken satisfies OpaqueTokenStorage.

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 (s *Store) RevokeRefreshToken(ctx context.Context, hash []byte, reason string) error

func (*Store) RevokeRefreshTokenFamily

func (s *Store) RevokeRefreshTokenFamily(ctx context.Context, familyID theauth.ULID, reason string) error

func (*Store) RevokeRefreshTokensByAuthCode added in v2.8.0

func (s *Store) RevokeRefreshTokensByAuthCode(ctx context.Context, codeHash, reason string) ([]string, error)

RevokeRefreshTokensByAuthCode revokes every live token in the rotation families first issued from the code stored under codeHash and returns the access-token jtis of the tokens it revoked.

func (*Store) RevokeRegistrationToken added in v2.8.0

func (s *Store) RevokeRegistrationToken(ctx context.Context, id theauth.ULID, at time.Time) (bool, error)

RevokeRegistrationToken satisfies RegistrationTokenStorage.

func (*Store) RevokeSCIMTokenByID

func (s *Store) RevokeSCIMTokenByID(ctx context.Context, id theauth.ULID, at time.Time) error

func (*Store) RevokeSession

func (s *Store) RevokeSession(ctx context.Context, id theauth.ULID) error

func (*Store) RevokeSessionsByCredential

func (s *Store) RevokeSessionsByCredential(ctx context.Context, credentialID string) (int, error)

RevokeSessionsByCredential revokes every live session bound to credentialID and returns the count.

func (*Store) RevokeUserRole

func (s *Store) RevokeUserRole(ctx context.Context, userID, roleID theauth.ULID) error

func (*Store) RevokeUserSessions

func (s *Store) RevokeUserSessions(ctx context.Context, userID theauth.ULID) error

func (*Store) RoleByID

func (s *Store) RoleByID(ctx context.Context, id theauth.ULID) (*theauth.Role, error)

func (*Store) RoleByOrgAndName

func (s *Store) RoleByOrgAndName(ctx context.Context, orgID *theauth.ULID, name string) (*theauth.Role, error)

func (*Store) RolesByOrganization

func (s *Store) RolesByOrganization(ctx context.Context, orgID *theauth.ULID) ([]theauth.Role, error)

func (*Store) RolesForUser

func (s *Store) RolesForUser(ctx context.Context, userID theauth.ULID, orgID *theauth.ULID) ([]theauth.Role, error)

func (*Store) SAMLConnectionByID

func (s *Store) SAMLConnectionByID(ctx context.Context, id theauth.ULID) (*theauth.SAMLConnection, error)

func (*Store) SAMLConnectionsByOrg

func (s *Store) SAMLConnectionsByOrg(ctx context.Context, orgID theauth.ULID) ([]theauth.SAMLConnection, error)

func (*Store) SAMLIdentityByConnectionAndNameID

func (s *Store) SAMLIdentityByConnectionAndNameID(ctx context.Context, connectionID theauth.ULID, nameID string) (*theauth.SAMLIdentity, error)

func (*Store) SCIMTokenByHash

func (s *Store) SCIMTokenByHash(ctx context.Context, hash []byte) (*theauth.SCIMToken, error)

func (*Store) SCIMTokensByOrg

func (s *Store) SCIMTokensByOrg(ctx context.Context, orgID theauth.ULID) ([]theauth.SCIMToken, error)

func (*Store) SessionAndUserByTokenHash added in v2.8.0

func (s *Store) SessionAndUserByTokenHash(ctx context.Context, hash []byte) (*theauth.Session, *theauth.User, error)

SessionAndUserByTokenHash returns a session and its user in one round trip, instead of the two sequential queries SessionByTokenHash plus UserByID cost.

func (*Store) SessionByID

func (s *Store) SessionByID(ctx context.Context, id theauth.ULID) (*theauth.Session, error)

SessionByID returns the session with the given ID.

func (*Store) SessionByTokenHash

func (s *Store) SessionByTokenHash(ctx context.Context, hash []byte) (*theauth.Session, error)

SessionByTokenHash returns the session with the given token hash.

func (*Store) SetGroupMembers

func (s *Store) SetGroupMembers(ctx context.Context, groupID theauth.ULID, userIDs []theauth.ULID) error

func (*Store) SetRolePermissions

func (s *Store) SetRolePermissions(ctx context.Context, roleID theauth.ULID, permissionIDs []theauth.ULID) error

func (*Store) SetSessionActiveOrganization

func (s *Store) SetSessionActiveOrganization(ctx context.Context, sessionID theauth.ULID, orgID *theauth.ULID) error

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 (s *Store) SetUserPassword(ctx context.Context, userID theauth.ULID, passwordHash string) error

func (*Store) TOTPSecretByUserID

func (s *Store) TOTPSecretByUserID(ctx context.Context, userID theauth.ULID) (*theauth.TOTPSecret, error)

func (*Store) ThrottleStore

func (s *Store) ThrottleStore() *ThrottleStore

ThrottleStore returns a login throttle store backed by the same database.

func (*Store) TouchAPITokenLastUsed

func (s *Store) TouchAPITokenLastUsed(ctx context.Context, id theauth.ULID, at time.Time) error

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 (s *Store) TouchSAMLIdentityLastLogin(ctx context.Context, id theauth.ULID, at time.Time) error

func (*Store) TouchSCIMTokenLastUsed

func (s *Store) TouchSCIMTokenLastUsed(ctx context.Context, id theauth.ULID, at time.Time) error

func (*Store) TouchSession

func (s *Store) TouchSession(ctx context.Context, id theauth.ULID, at time.Time) error

TouchSession advances last-seen time and never moves it backwards.

func (*Store) UpdateAgentCredentialLastUsed

func (s *Store) UpdateAgentCredentialLastUsed(ctx context.Context, id theauth.ULID, at time.Time) error

func (*Store) UpdateAgentLastActive

func (s *Store) UpdateAgentLastActive(ctx context.Context, id theauth.ULID, at time.Time) error

func (*Store) UpdateAgentStatus

func (s *Store) UpdateAgentStatus(ctx context.Context, id theauth.ULID, status string, _ time.Time) error

func (*Store) UpdateBackchannelRequest

func (s *Store) UpdateBackchannelRequest(ctx context.Context, req theauth.BackchannelRequest) error

UpdateBackchannelRequest satisfies CIBAStorage. Writes all mutable fields.

func (*Store) UpdateGroup

func (s *Store) UpdateGroup(ctx context.Context, g theauth.Group) error

func (*Store) UpdateJWKSKeyState

func (s *Store) UpdateJWKSKeyState(ctx context.Context, kid, state string, at time.Time) error

func (*Store) UpdateOAuthClient

func (s *Store) UpdateOAuthClient(ctx context.Context, c theauth.OAuthClient) (theauth.OAuthClient, error)

func (*Store) UpdateOrganization

func (s *Store) UpdateOrganization(ctx context.Context, o theauth.Organization) error

func (*Store) UpdateRoleRow

func (s *Store) UpdateRoleRow(ctx context.Context, r theauth.Role) (theauth.Role, error)

func (*Store) UpdateSAMLConnectionRow

func (s *Store) UpdateSAMLConnectionRow(ctx context.Context, c theauth.SAMLConnection) error

func (*Store) UpdateSessionAuthLevel

func (s *Store) UpdateSessionAuthLevel(ctx context.Context, id theauth.ULID, level string) error

func (*Store) UpdateUserSCIM

func (s *Store) UpdateUserSCIM(ctx context.Context, u theauth.User) error

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 (s *Store) UpsertOrganizationMember(ctx context.Context, m theauth.OrganizationMember) error

func (*Store) UpsertPendingTOTPSecret

func (s *Store) UpsertPendingTOTPSecret(ctx context.Context, sec theauth.TOTPSecret) error

func (*Store) UpsertSAMLIdentity

func (s *Store) UpsertSAMLIdentity(ctx context.Context, i theauth.SAMLIdentity) (theauth.SAMLIdentity, error)

func (*Store) UserByEmail

func (s *Store) UserByEmail(ctx context.Context, email string) (*theauth.User, error)

func (*Store) UserByEmailWithPassword

func (s *Store) UserByEmailWithPassword(ctx context.Context, email string) (*theauth.User, string, error)

func (*Store) UserByExternalIDInOrg

func (s *Store) UserByExternalIDInOrg(ctx context.Context, orgID theauth.ULID, externalID string) (*theauth.User, error)

func (*Store) UserByID

func (s *Store) UserByID(ctx context.Context, id theauth.ULID) (*theauth.User, error)

func (*Store) UserPasswordHashByID

func (s *Store) UserPasswordHashByID(ctx context.Context, userID theauth.ULID) (string, error)

UserPasswordHashByID returns the stored Argon2id PHC string for the user, or "" when no password row exists.

func (*Store) WebAuthnCredentialByCredentialID

func (s *Store) WebAuthnCredentialByCredentialID(ctx context.Context, credentialID []byte) (*theauth.WebAuthnCredential, error)

func (*Store) WebAuthnCredentialsByUserID

func (s *Store) WebAuthnCredentialsByUserID(ctx context.Context, userID theauth.ULID) ([]theauth.WebAuthnCredential, error)

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

Get returns the entry for key.

func (*ThrottleStore) Set

Set stores e under key unconditionally.

func (*ThrottleStore) SweepExpired

func (t *ThrottleStore) SweepExpired(ctx context.Context, now time.Time) (int, error)

SweepExpired deletes entries whose ExpiresAt is at or before now and returns how many it removed.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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