Documentation
¶
Index ¶
- func MigrateDown(databaseURL string) error
- func MigrateUp(databaseURL string) error
- func MigrateVersion(databaseURL string) (uint, bool, error)
- type DB
- func (d *DB) Close()
- func (d *DB) Health(ctx context.Context) error
- func (d *DB) Pool() *pgxpool.Pool
- func (d *DB) Queries() *sqlc.Queries
- func (d *DB) WithTenantContext(ctx context.Context, fn func(*sqlc.Queries) error) error
- func (d *DB) WithTransaction(ctx context.Context, fn func(*sqlc.Queries) error) error
- type LoginAttemptsDB
- func (r *LoginAttemptsDB) DeleteOldLoginAttempts(ctx context.Context, olderThan time.Time) error
- func (r *LoginAttemptsDB) GetMostRecentLockout(ctx context.Context, email string) (*time.Time, error)
- func (r *LoginAttemptsDB) GetRecentFailedAttempts(ctx context.Context, email string, since time.Time) (int64, error)
- func (r *LoginAttemptsDB) RecordAttempt(ctx context.Context, email string, userID *uuid.UUID, ipAddress *string, ...) error
- type OIDCLinksDB
- func (o *OIDCLinksDB) CreateOIDCLink(ctx context.Context, link *auth.OIDCLink) (*auth.OIDCLink, error)
- func (o *OIDCLinksDB) DeleteOIDCLink(ctx context.Context, userID uuid.UUID, providerID uuid.UUID) error
- func (o *OIDCLinksDB) GetOIDCLinkByProvider(ctx context.Context, providerID uuid.UUID, providerUserID string) (*auth.OIDCLink, error)
- func (o *OIDCLinksDB) GetOIDCLinkByUser(ctx context.Context, userID uuid.UUID, providerID uuid.UUID) (*auth.OIDCLink, error)
- func (o *OIDCLinksDB) ListOIDCLinksByUser(ctx context.Context, userID uuid.UUID) ([]*auth.OIDCLink, error)
- func (o *OIDCLinksDB) UpdateOIDCLinkLastUsed(ctx context.Context, id uuid.UUID) error
- type OIDCProvidersDB
- func (o *OIDCProvidersDB) CreateOIDCProvider(ctx context.Context, provider *auth.OIDCProviderConfig) (*auth.OIDCProviderConfig, error)
- func (o *OIDCProvidersDB) DeleteOIDCProviderByID(ctx context.Context, id uuid.UUID) error
- func (o *OIDCProvidersDB) GetOIDCProviderByID(ctx context.Context, id uuid.UUID) (*auth.OIDCProviderConfig, error)
- func (o *OIDCProvidersDB) GetOIDCProvidersByDomain(ctx context.Context, domain string) ([]*auth.OIDCProviderConfig, error)
- func (o *OIDCProvidersDB) ListOIDCProviders(ctx context.Context) ([]*auth.OIDCProviderConfig, error)
- func (o *OIDCProvidersDB) UpdateOIDCProvider(ctx context.Context, params *auth.UpdateOIDCProviderParams) (*auth.OIDCProviderConfig, error)
- type OIDCSessionsDB
- func (o *OIDCSessionsDB) CreateOIDCSession(ctx context.Context, session *auth.OIDCSession) (*auth.OIDCSession, error)
- func (o *OIDCSessionsDB) DeleteExpiredOIDCSessions(ctx context.Context) error
- func (o *OIDCSessionsDB) DeleteOIDCSession(ctx context.Context, id uuid.UUID) error
- func (o *OIDCSessionsDB) GetOIDCSessionByState(ctx context.Context, state string) (*auth.OIDCSession, error)
- type PasswordResetTokensDB
- func (r *PasswordResetTokensDB) CreateToken(ctx context.Context, userID uuid.UUID, token string, expiresAt time.Time) (*auth.Token, error)
- func (r *PasswordResetTokensDB) DeleteExpiredTokens(ctx context.Context) error
- func (r *PasswordResetTokensDB) DeleteToken(ctx context.Context, userID uuid.UUID) error
- func (r *PasswordResetTokensDB) GetToken(ctx context.Context, token string) (*auth.Token, error)
- type UsersDB
- func (u *UsersDB) CreateUser(ctx context.Context, user *auth.User) (*auth.User, error)
- func (u *UsersDB) DeleteOldUnverifiedUsers(ctx context.Context, days int32) error
- func (u *UsersDB) DeleteUser(ctx context.Context, id uuid.UUID) error
- func (u *UsersDB) GetUser(ctx context.Context, id uuid.UUID) (*auth.User, error)
- func (u *UsersDB) GetUserByEmail(ctx context.Context, email string) (*auth.User, error)
- func (u *UsersDB) UpdateLastLogin(ctx context.Context, id uuid.UUID) error
- func (u *UsersDB) UpdatePassword(ctx context.Context, id uuid.UUID, passwordHash string) error
- func (u *UsersDB) UpdateUser(ctx context.Context, id uuid.UUID, email string, status auth.UserStatus) (*auth.User, error)
- func (u *UsersDB) UpdateUserPassword(ctx context.Context, id uuid.UUID, passwordHash string) error
- func (u *UsersDB) UpdateUserStatus(ctx context.Context, id uuid.UUID, status auth.UserStatus) (*auth.User, error)
- type VerificationTokensDB
- func (r *VerificationTokensDB) CreateToken(ctx context.Context, userID uuid.UUID, token string, expiresAt time.Time) (*auth.Token, error)
- func (r *VerificationTokensDB) DeleteExpiredTokens(ctx context.Context) error
- func (r *VerificationTokensDB) DeleteToken(ctx context.Context, userID uuid.UUID) error
- func (r *VerificationTokensDB) GetToken(ctx context.Context, token string) (*auth.Token, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MigrateDown ¶
MigrateDown rolls back the most recent migration (use with caution)
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB wraps the pgx connection pool
func (*DB) WithTenantContext ¶
WithTenantContext executes a function within a tenant-scoped transaction. Sets app.current_tenant_id for Row Level Security policies to enforce automatic tenant isolation
type LoginAttemptsDB ¶
type LoginAttemptsDB struct {
// contains filtered or unexported fields
}
LoginAttemptsDB tracks failed login attempts for progressive lockout and audit trail
func NewLoginAttemptsDB ¶
func NewLoginAttemptsDB(db *DB) *LoginAttemptsDB
func (*LoginAttemptsDB) DeleteOldLoginAttempts ¶
DeleteOldLoginAttempts cleans up old audit data (recommended: retain 30-90 days for compliance)
func (*LoginAttemptsDB) GetMostRecentLockout ¶
func (r *LoginAttemptsDB) GetMostRecentLockout(ctx context.Context, email string) (*time.Time, error)
GetMostRecentLockout returns latest lockout expiry time (nil if no active lockouts)
func (*LoginAttemptsDB) GetRecentFailedAttempts ¶
func (r *LoginAttemptsDB) GetRecentFailedAttempts(ctx context.Context, email string, since time.Time) (int64, error)
GetRecentFailedAttempts counts failed login attempts since specified time (for lockout calculation)
type OIDCLinksDB ¶
type OIDCLinksDB struct {
// contains filtered or unexported fields
}
OIDCLinksDB manages user-to-provider links for SSO (tracks by provider's sub claim)
func NewOIDCLinksDB ¶
func NewOIDCLinksDB(db *DB) *OIDCLinksDB
func (*OIDCLinksDB) CreateOIDCLink ¶
func (o *OIDCLinksDB) CreateOIDCLink(ctx context.Context, link *auth.OIDCLink) (*auth.OIDCLink, error)
CreateOIDCLink creates link between user and provider (tracks by immutable sub claim)
func (*OIDCLinksDB) DeleteOIDCLink ¶
func (o *OIDCLinksDB) DeleteOIDCLink(ctx context.Context, userID uuid.UUID, providerID uuid.UUID) error
DeleteOIDCLink deletes an OIDC link by user ID and provider ID
func (*OIDCLinksDB) GetOIDCLinkByProvider ¶
func (o *OIDCLinksDB) GetOIDCLinkByProvider(ctx context.Context, providerID uuid.UUID, providerUserID string) (*auth.OIDCLink, error)
GetOIDCLinkByProvider retrieves link by provider's sub claim (allows email reassignment)
func (*OIDCLinksDB) GetOIDCLinkByUser ¶
func (o *OIDCLinksDB) GetOIDCLinkByUser(ctx context.Context, userID uuid.UUID, providerID uuid.UUID) (*auth.OIDCLink, error)
GetOIDCLinkByUser retrieves an OIDC link by user ID and provider ID
func (*OIDCLinksDB) ListOIDCLinksByUser ¶
func (o *OIDCLinksDB) ListOIDCLinksByUser(ctx context.Context, userID uuid.UUID) ([]*auth.OIDCLink, error)
ListOIDCLinksByUser lists all OIDC links for a user
func (*OIDCLinksDB) UpdateOIDCLinkLastUsed ¶
UpdateOIDCLinkLastUsed updates the last_used_at timestamp
type OIDCProvidersDB ¶
type OIDCProvidersDB struct {
// contains filtered or unexported fields
}
OIDCProvidersDB manages tenant-specific OIDC provider configs with encrypted secrets
func NewOIDCProvidersDB ¶
func NewOIDCProvidersDB(db *DB, cipher *aes.Cipher) *OIDCProvidersDB
func (*OIDCProvidersDB) CreateOIDCProvider ¶
func (o *OIDCProvidersDB) CreateOIDCProvider(ctx context.Context, provider *auth.OIDCProviderConfig) (*auth.OIDCProviderConfig, error)
CreateOIDCProvider stores provider config with AES-256-GCM encrypted client secret
func (*OIDCProvidersDB) DeleteOIDCProviderByID ¶
DeleteOIDCProviderByID deletes an OAuth provider by ID
func (*OIDCProvidersDB) GetOIDCProviderByID ¶
func (o *OIDCProvidersDB) GetOIDCProviderByID(ctx context.Context, id uuid.UUID) (*auth.OIDCProviderConfig, error)
GetOIDCProviderByID retrieves provider by ID with tenant isolation
func (*OIDCProvidersDB) GetOIDCProvidersByDomain ¶
func (o *OIDCProvidersDB) GetOIDCProvidersByDomain(ctx context.Context, domain string) ([]*auth.OIDCProviderConfig, error)
GetOIDCProvidersByDomain retrieves all OAuth providers configured for an email domain This is used for SSO discovery during login (cross-tenant, pre-authentication)
func (*OIDCProvidersDB) ListOIDCProviders ¶
func (o *OIDCProvidersDB) ListOIDCProviders(ctx context.Context) ([]*auth.OIDCProviderConfig, error)
ListOIDCProviders lists all enabled OAuth providers for the tenant
func (*OIDCProvidersDB) UpdateOIDCProvider ¶
func (o *OIDCProvidersDB) UpdateOIDCProvider(ctx context.Context, params *auth.UpdateOIDCProviderParams) (*auth.OIDCProviderConfig, error)
UpdateOIDCProvider updates an OAuth provider Fields in params that are pointers (nil) or empty slices will not be updated (COALESCE in SQL)
type OIDCSessionsDB ¶
type OIDCSessionsDB struct {
// contains filtered or unexported fields
}
OIDCSessionsDB manages OAuth flow sessions (state, PKCE, provider tracking)
func NewOIDCSessionsDB ¶
func NewOIDCSessionsDB(db *DB) *OIDCSessionsDB
func (*OIDCSessionsDB) CreateOIDCSession ¶
func (o *OIDCSessionsDB) CreateOIDCSession(ctx context.Context, session *auth.OIDCSession) (*auth.OIDCSession, error)
CreateOIDCSession creates temporary session for OAuth flow (CSRF protection via state)
func (*OIDCSessionsDB) DeleteExpiredOIDCSessions ¶
func (o *OIDCSessionsDB) DeleteExpiredOIDCSessions(ctx context.Context) error
DeleteExpiredOIDCSessions deletes all expired OAuth sessions
func (*OIDCSessionsDB) DeleteOIDCSession ¶
DeleteOIDCSession deletes an OAuth session by ID
func (*OIDCSessionsDB) GetOIDCSessionByState ¶
func (o *OIDCSessionsDB) GetOIDCSessionByState(ctx context.Context, state string) (*auth.OIDCSession, error)
GetOIDCSessionByState retrieves session by state parameter (validates CSRF token)
type PasswordResetTokensDB ¶
type PasswordResetTokensDB struct {
// contains filtered or unexported fields
}
PasswordResetTokensDB manages password reset tokens (pre-authentication operation)
func NewPasswordResetTokensDB ¶
func NewPasswordResetTokensDB(db *DB) *PasswordResetTokensDB
func (*PasswordResetTokensDB) CreateToken ¶
func (r *PasswordResetTokensDB) CreateToken(ctx context.Context, userID uuid.UUID, token string, expiresAt time.Time) (*auth.Token, error)
CreateToken creates or replaces reset token (user_id is PK, enforces one token per user)
func (*PasswordResetTokensDB) DeleteExpiredTokens ¶
func (r *PasswordResetTokensDB) DeleteExpiredTokens(ctx context.Context) error
DeleteExpiredTokens cleans up expired tokens (should be called periodically via cleanup job)
func (*PasswordResetTokensDB) DeleteToken ¶
DeleteToken removes reset token after successful password change
type UsersDB ¶
type UsersDB struct {
// contains filtered or unexported fields
}
UsersDB handles user database operations with tenant isolation
func (*UsersDB) CreateUser ¶
CreateUser creates a new user Uses WithTransaction (not WithTenantContext) because registration happens pre-authentication
func (*UsersDB) DeleteOldUnverifiedUsers ¶
DeleteOldUnverifiedUsers deletes unverified users older than the specified number of days Cross-tenant cleanup operation runs via scheduled job, not user request
func (*UsersDB) DeleteUser ¶
DeleteUser deletes a user with tenant isolation
func (*UsersDB) GetUserByEmail ¶
GetUserByEmail retrieves a user by email without tenant isolation Pre-authentication operation: emails are globally unique for password users, but may duplicate for SSO users
func (*UsersDB) UpdateLastLogin ¶
UpdateLastLogin updates a user's last login timestamp with tenant isolation
func (*UsersDB) UpdatePassword ¶
UpdatePassword updates a user's password without tenant isolation Password reset tokens contain user ID, so tenant context is unnecessary
func (*UsersDB) UpdateUser ¶
func (u *UsersDB) UpdateUser(ctx context.Context, id uuid.UUID, email string, status auth.UserStatus) (*auth.User, error)
UpdateUser updates a user with tenant isolation
func (*UsersDB) UpdateUserPassword ¶
UpdateUserPassword updates a user's password with tenant isolation
func (*UsersDB) UpdateUserStatus ¶
func (u *UsersDB) UpdateUserStatus(ctx context.Context, id uuid.UUID, status auth.UserStatus) (*auth.User, error)
UpdateUserStatus updates a user's status without tenant isolation and returns the updated user Email verification tokens contain user ID, so tenant context is unnecessary for this operation
type VerificationTokensDB ¶
type VerificationTokensDB struct {
// contains filtered or unexported fields
}
VerificationTokensDB manages email verification tokens (pre-authentication operation)
func NewVerificationTokensDB ¶
func NewVerificationTokensDB(db *DB) *VerificationTokensDB
func (*VerificationTokensDB) CreateToken ¶
func (r *VerificationTokensDB) CreateToken(ctx context.Context, userID uuid.UUID, token string, expiresAt time.Time) (*auth.Token, error)
CreateToken creates or replaces verification token (user_id is PK, enforces one token per user)
func (*VerificationTokensDB) DeleteExpiredTokens ¶
func (r *VerificationTokensDB) DeleteExpiredTokens(ctx context.Context) error
DeleteExpiredTokens cleans up expired tokens (should be called periodically via cleanup job)
func (*VerificationTokensDB) DeleteToken ¶
DeleteToken removes verification token after successful email confirmation