Documentation
¶
Overview ¶
Package pgstore implements auth's store ports on Postgres through sqlc: the user plane (users, sessions, reset and verification tokens, TOTP, lockout, linked accounts, passkeys and email login), the team plane (teams, members and invitations), personal access tokens, RFC 8628 device authorizations and the operator plane.
Its tables live in the auth schema and migrate with their own goose version table, so an app runs Migrate beside its own migrations and neither sees the other's history.
Index ¶
- Constants
- func Migrate(ctx context.Context, pool *pgxpool.Pool) error
- type Store
- func (s *Store) ClearFailedLoginAttempts(ctx context.Context, email string) error
- func (s *Store) ConsumeRefreshToken(ctx context.Context, id string) (bool, error)
- func (s *Store) ConsumeSuperuserRefreshToken(ctx context.Context, id string) (bool, error)
- func (s *Store) ConsumeWebAuthnChallenge(ctx context.Context, tokenHash string) (*store.WebAuthnChallenge, error)
- func (s *Store) CountRecentFailedLoginAttempts(ctx context.Context, email string, since time.Time) (int, error)
- func (s *Store) CountSuperusers(ctx context.Context) (int, error)
- func (s *Store) CreateAccount(ctx context.Context, a *store.Account) error
- func (s *Store) CreateBoundDevice(ctx context.Context, d *store.BoundDevice) error
- func (s *Store) CreateDeviceAuthorization(ctx context.Context, d *store.DeviceAuthorization) error
- func (s *Store) CreateEmailLoginToken(ctx context.Context, t *store.EmailLoginToken) error
- func (s *Store) CreateEmailVerificationToken(ctx context.Context, t *store.EmailVerificationToken) error
- func (s *Store) CreateInvitation(ctx context.Context, i *store.Invitation) error
- func (s *Store) CreateMember(ctx context.Context, m *store.Member) error
- func (s *Store) CreatePasswordResetToken(ctx context.Context, t *store.PasswordResetToken) error
- func (s *Store) CreatePendingTwoFactorSession(ctx context.Context, p *store.PendingTwoFactorSession) error
- func (s *Store) CreatePersonalAccessToken(ctx context.Context, t *store.PersonalAccessToken) error
- func (s *Store) CreateRefreshToken(ctx context.Context, t *store.RefreshToken) error
- func (s *Store) CreateSuperuser(ctx context.Context, su *store.Superuser) error
- func (s *Store) CreateSuperuserPendingTwoFactorSession(ctx context.Context, p *store.PendingTwoFactorSession) error
- func (s *Store) CreateSuperuserRefreshToken(ctx context.Context, t *store.SuperuserRefreshToken) error
- func (s *Store) CreateSuperuserTOTPSettings(ctx context.Context, t *store.TOTPSettings) error
- func (s *Store) CreateTOTPSettings(ctx context.Context, t *store.TOTPSettings) error
- func (s *Store) CreateTeam(ctx context.Context, t *store.Team) error
- func (s *Store) CreateUser(ctx context.Context, u *store.User) error
- func (s *Store) CreateWebAuthnChallenge(ctx context.Context, c *store.WebAuthnChallenge) error
- func (s *Store) CreateWebAuthnCredential(ctx context.Context, c *store.WebAuthnCredential) error
- func (s *Store) DeleteAccount(ctx context.Context, id string) error
- func (s *Store) DeleteDeviceAuthorization(ctx context.Context, id string) error
- func (s *Store) DeleteEmailLoginTokens(ctx context.Context, email string, kind store.EmailLoginKind) error
- func (s *Store) DeleteMember(ctx context.Context, id string) error
- func (s *Store) DeletePINCredential(ctx context.Context, userID string) error
- func (s *Store) DeletePendingTwoFactorSession(ctx context.Context, id string) error
- func (s *Store) DeleteSuperuserPendingTwoFactorSession(ctx context.Context, id string) error
- func (s *Store) DeleteSuperuserTOTPSettings(ctx context.Context, superuserID string) error
- func (s *Store) DeleteTOTPSettings(ctx context.Context, userID string) error
- func (s *Store) DeleteTeam(ctx context.Context, id string) error
- func (s *Store) DeleteUserEmailVerificationTokens(ctx context.Context, userID string) error
- func (s *Store) DeleteUserPasswordResetTokens(ctx context.Context, userID string) error
- func (s *Store) DeleteWebAuthnCredential(ctx context.Context, id string) error
- func (s *Store) GetAccount(ctx context.Context, id string) (*store.Account, error)
- func (s *Store) GetAccountByProvider(ctx context.Context, provider, providerAccountID string) (*store.Account, error)
- func (s *Store) GetBoundDevice(ctx context.Context, id string) (*store.BoundDevice, error)
- func (s *Store) GetBoundDeviceByTokenHash(ctx context.Context, hash string) (*store.BoundDevice, error)
- func (s *Store) GetDeviceAuthorizationByDeviceCodeHash(ctx context.Context, hash string) (*store.DeviceAuthorization, error)
- func (s *Store) GetDeviceAuthorizationByUserCode(ctx context.Context, userCode string) (*store.DeviceAuthorization, error)
- func (s *Store) GetEmailLoginTokenByEmail(ctx context.Context, email string, kind store.EmailLoginKind) (*store.EmailLoginToken, error)
- func (s *Store) GetEmailLoginTokenByHash(ctx context.Context, hash string) (*store.EmailLoginToken, error)
- func (s *Store) GetEmailVerificationTokenByHash(ctx context.Context, hash string) (*store.EmailVerificationToken, error)
- func (s *Store) GetInvitation(ctx context.Context, id string) (*store.Invitation, error)
- func (s *Store) GetInvitationByTokenHash(ctx context.Context, hash string) (*store.Invitation, error)
- func (s *Store) GetMember(ctx context.Context, id string) (*store.Member, error)
- func (s *Store) GetMemberByUserAndTeam(ctx context.Context, userID, teamID string) (*store.Member, error)
- func (s *Store) GetPINCredential(ctx context.Context, userID string) (*store.PINCredential, error)
- func (s *Store) GetPasswordResetTokenByHash(ctx context.Context, hash string) (*store.PasswordResetToken, error)
- func (s *Store) GetPendingTwoFactorSessionByHash(ctx context.Context, hash string) (*store.PendingTwoFactorSession, error)
- func (s *Store) GetPersonalAccessToken(ctx context.Context, id string) (*store.PersonalAccessToken, error)
- func (s *Store) GetPersonalAccessTokenByHash(ctx context.Context, hash string) (*store.PersonalAccessToken, error)
- func (s *Store) GetRefreshTokenByHash(ctx context.Context, hash string) (*store.RefreshToken, error)
- func (s *Store) GetSuperuserByEmail(ctx context.Context, email string) (*store.Superuser, error)
- func (s *Store) GetSuperuserByID(ctx context.Context, id string) (*store.Superuser, error)
- func (s *Store) GetSuperuserPendingTwoFactorSessionByHash(ctx context.Context, hash string) (*store.PendingTwoFactorSession, error)
- func (s *Store) GetSuperuserRefreshTokenByHash(ctx context.Context, hash string) (*store.SuperuserRefreshToken, error)
- func (s *Store) GetSuperuserTOTPSettings(ctx context.Context, superuserID string) (*store.TOTPSettings, error)
- func (s *Store) GetTOTPSettingsByUserID(ctx context.Context, userID string) (*store.TOTPSettings, error)
- func (s *Store) GetTeam(ctx context.Context, id string) (*store.Team, error)
- func (s *Store) GetTeamBySlug(ctx context.Context, slug string) (*store.Team, error)
- func (s *Store) GetUserByEmail(ctx context.Context, email string) (*store.User, error)
- func (s *Store) GetUserByID(ctx context.Context, id string) (*store.User, error)
- func (s *Store) GetWebAuthnCredential(ctx context.Context, id string) (*store.WebAuthnCredential, error)
- func (s *Store) GetWebAuthnCredentialByCredentialID(ctx context.Context, credentialID []byte) (*store.WebAuthnCredential, error)
- func (s *Store) IncrementEmailLoginTokenAttempts(ctx context.Context, id string) (int, error)
- func (s *Store) IsAccountLocked(ctx context.Context, userID string) (bool, error)
- func (s *Store) ListAccountsByUser(ctx context.Context, userID string) ([]*store.Account, error)
- func (s *Store) ListActiveRefreshTokens(ctx context.Context, userID string) ([]*store.RefreshToken, error)
- func (s *Store) ListActiveSuperuserRefreshTokens(ctx context.Context, superuserID string) ([]*store.SuperuserRefreshToken, error)
- func (s *Store) ListBoundDevicesByUser(ctx context.Context, userID string) ([]*store.BoundDevice, error)
- func (s *Store) ListInvitationsByTeam(ctx context.Context, teamID string) ([]*store.Invitation, error)
- func (s *Store) ListMembersByTeam(ctx context.Context, teamID string) ([]*store.Member, error)
- func (s *Store) ListMembershipsByUser(ctx context.Context, userID string) ([]*store.Member, error)
- func (s *Store) ListPersonalAccessTokensByUser(ctx context.Context, userID string) ([]*store.PersonalAccessToken, error)
- func (s *Store) ListSuperusers(ctx context.Context) ([]*store.Superuser, error)
- func (s *Store) ListWebAuthnCredentialsByUser(ctx context.Context, userID string) ([]*store.WebAuthnCredential, error)
- func (s *Store) LockAccount(ctx context.Context, userID string) error
- func (s *Store) MarkEmailLoginTokenUsed(ctx context.Context, id string, usedAt time.Time) error
- func (s *Store) MarkEmailVerificationTokenUsed(ctx context.Context, id string) error
- func (s *Store) MarkPasswordResetTokenUsed(ctx context.Context, id string) error
- func (s *Store) RecordFailedLoginAttempt(ctx context.Context, a *store.FailedLoginAttempt) error
- func (s *Store) RevokeAllBoundDevices(ctx context.Context, userID string, at time.Time) (int, error)
- func (s *Store) RevokeAllSuperuserRefreshTokens(ctx context.Context, superuserID string) error
- func (s *Store) RevokeAllUserRefreshTokens(ctx context.Context, userID string) error
- func (s *Store) RevokeBoundDevice(ctx context.Context, id string, at time.Time) error
- func (s *Store) RevokeRefreshToken(ctx context.Context, id string) error
- func (s *Store) RevokeSuperuserRefreshToken(ctx context.Context, id string) error
- func (s *Store) RunInTx(ctx context.Context, fn func(ctx context.Context) error) error
- func (s *Store) SetPINCredential(ctx context.Context, c *store.PINCredential) error
- func (s *Store) TouchBoundDevice(ctx context.Context, id string, at time.Time) error
- func (s *Store) TouchRefreshToken(ctx context.Context, id string, expiresAt time.Time) error
- func (s *Store) UnlockAccount(ctx context.Context, userID string) error
- func (s *Store) UpdateAccount(ctx context.Context, a *store.Account) error
- func (s *Store) UpdateDeviceAuthorization(ctx context.Context, d *store.DeviceAuthorization) error
- func (s *Store) UpdateInvitation(ctx context.Context, i *store.Invitation) error
- func (s *Store) UpdateMember(ctx context.Context, m *store.Member) error
- func (s *Store) UpdatePersonalAccessToken(ctx context.Context, t *store.PersonalAccessToken) error
- func (s *Store) UpdateSuperuser(ctx context.Context, su *store.Superuser) error
- func (s *Store) UpdateSuperuserTOTPSettings(ctx context.Context, t *store.TOTPSettings) error
- func (s *Store) UpdateTOTPSettings(ctx context.Context, t *store.TOTPSettings) error
- func (s *Store) UpdateTeam(ctx context.Context, t *store.Team) error
- func (s *Store) UpdateUser(ctx context.Context, u *store.User) error
- func (s *Store) UpdateWebAuthnCredential(ctx context.Context, c *store.WebAuthnCredential) error
Constants ¶
const VersionTable = "auth.goose_db_version"
VersionTable is goose's bookkeeping for the auth schema, kept apart from the app's own goose_db_version.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store implements every port above and store.TxRunner over one pool.
func (*Store) ClearFailedLoginAttempts ¶
func (*Store) ConsumeRefreshToken ¶ added in v0.6.0
func (*Store) ConsumeSuperuserRefreshToken ¶ added in v0.6.0
func (*Store) ConsumeWebAuthnChallenge ¶
func (*Store) CountRecentFailedLoginAttempts ¶
func (*Store) CreateAccount ¶
func (*Store) CreateBoundDevice ¶ added in v0.7.0
func (*Store) CreateDeviceAuthorization ¶ added in v0.7.0
func (*Store) CreateEmailLoginToken ¶
func (*Store) CreateEmailVerificationToken ¶
func (*Store) CreateInvitation ¶ added in v0.7.0
func (*Store) CreateMember ¶ added in v0.7.0
func (*Store) CreatePasswordResetToken ¶
func (*Store) CreatePendingTwoFactorSession ¶
func (*Store) CreatePersonalAccessToken ¶ added in v0.7.0
func (*Store) CreateRefreshToken ¶
func (*Store) CreateSuperuser ¶
func (*Store) CreateSuperuserPendingTwoFactorSession ¶
func (*Store) CreateSuperuserRefreshToken ¶
func (*Store) CreateSuperuserTOTPSettings ¶
func (*Store) CreateTOTPSettings ¶
func (*Store) CreateTeam ¶ added in v0.7.0
func (*Store) CreateWebAuthnChallenge ¶
func (*Store) CreateWebAuthnCredential ¶
func (*Store) DeleteDeviceAuthorization ¶ added in v0.7.0
DeleteDeviceAuthorization succeeds for a row that is already gone: the device package deletes a resolved authorization and ignores the result.
func (*Store) DeleteEmailLoginTokens ¶
func (*Store) DeleteMember ¶ added in v0.7.0
func (*Store) DeletePINCredential ¶ added in v0.7.0
func (*Store) DeletePendingTwoFactorSession ¶
func (*Store) DeleteSuperuserPendingTwoFactorSession ¶
func (*Store) DeleteSuperuserTOTPSettings ¶
func (*Store) DeleteTOTPSettings ¶
func (*Store) DeleteTeam ¶ added in v0.7.0
DeleteTeam takes the team's members and invitations with it.
func (*Store) DeleteUserEmailVerificationTokens ¶
func (*Store) DeleteUserPasswordResetTokens ¶
func (*Store) DeleteWebAuthnCredential ¶
func (*Store) GetAccount ¶
func (*Store) GetAccountByProvider ¶
func (*Store) GetBoundDevice ¶ added in v0.7.0
func (*Store) GetBoundDeviceByTokenHash ¶ added in v0.7.0
func (*Store) GetDeviceAuthorizationByDeviceCodeHash ¶ added in v0.7.0
func (*Store) GetDeviceAuthorizationByUserCode ¶ added in v0.7.0
func (*Store) GetEmailLoginTokenByEmail ¶
func (s *Store) GetEmailLoginTokenByEmail(ctx context.Context, email string, kind store.EmailLoginKind) (*store.EmailLoginToken, error)
func (*Store) GetEmailLoginTokenByHash ¶
func (*Store) GetEmailVerificationTokenByHash ¶
func (*Store) GetInvitation ¶ added in v0.7.0
func (*Store) GetInvitationByTokenHash ¶ added in v0.7.0
func (*Store) GetMemberByUserAndTeam ¶ added in v0.7.0
func (s *Store) GetMemberByUserAndTeam(ctx context.Context, userID, teamID string) (*store.Member, error)
GetMemberByUserAndTeam never matches a member without a user: the equality is false against NULL.
func (*Store) GetPINCredential ¶ added in v0.7.0
func (*Store) GetPasswordResetTokenByHash ¶
func (*Store) GetPendingTwoFactorSessionByHash ¶
func (*Store) GetPersonalAccessToken ¶ added in v0.7.0
func (*Store) GetPersonalAccessTokenByHash ¶ added in v0.7.0
func (*Store) GetRefreshTokenByHash ¶
func (*Store) GetSuperuserByEmail ¶
func (*Store) GetSuperuserByID ¶
func (*Store) GetSuperuserPendingTwoFactorSessionByHash ¶
func (*Store) GetSuperuserRefreshTokenByHash ¶
func (*Store) GetSuperuserTOTPSettings ¶
func (*Store) GetTOTPSettingsByUserID ¶
func (*Store) GetTeamBySlug ¶ added in v0.7.0
func (*Store) GetUserByEmail ¶
func (*Store) GetUserByID ¶
func (*Store) GetWebAuthnCredential ¶
func (*Store) GetWebAuthnCredentialByCredentialID ¶
func (*Store) IncrementEmailLoginTokenAttempts ¶
func (*Store) IsAccountLocked ¶
func (*Store) ListAccountsByUser ¶
func (*Store) ListActiveRefreshTokens ¶
func (*Store) ListActiveSuperuserRefreshTokens ¶
func (*Store) ListBoundDevicesByUser ¶ added in v0.7.0
func (*Store) ListInvitationsByTeam ¶ added in v0.7.0
func (*Store) ListMembersByTeam ¶ added in v0.7.0
ListMembersByTeam lists every member, active or not, since the last-owner check reads Role and IsActive itself. Inside a transaction it also locks the rows it returns, so that check and the write it guards cannot interleave with another transaction doing the same.
func (*Store) ListMembershipsByUser ¶ added in v0.7.0
func (*Store) ListPersonalAccessTokensByUser ¶ added in v0.7.0
func (*Store) ListSuperusers ¶
func (*Store) ListWebAuthnCredentialsByUser ¶
func (*Store) MarkEmailLoginTokenUsed ¶
func (*Store) MarkEmailVerificationTokenUsed ¶
func (*Store) MarkPasswordResetTokenUsed ¶
func (*Store) RecordFailedLoginAttempt ¶
func (*Store) RevokeAllBoundDevices ¶ added in v0.7.0
func (*Store) RevokeAllSuperuserRefreshTokens ¶
func (*Store) RevokeAllUserRefreshTokens ¶
func (*Store) RevokeBoundDevice ¶ added in v0.7.0
func (*Store) RevokeRefreshToken ¶
func (*Store) RevokeSuperuserRefreshToken ¶
func (*Store) RunInTx ¶
RunInTx runs fn in one transaction. store.TxRunner requires every store call made with fn's context to join it, so q reads the transaction back out of the context; a call inside an open transaction joins that one.