Documentation
¶
Index ¶
- Constants
- Variables
- func CanonicalMCPOAuthScope(raw string) (string, bool)
- func DetachedWriteContext(ctx context.Context) (context.Context, context.CancelFunc)
- func GenerateCode() (string, error)
- func GenerateLoginLinkToken() (string, error)
- func HashCode(code, secret string) string
- func IsPermanentMailError(err error) bool
- func MailFailureDetail(err error) string
- func NormalizeEmail(raw string) (string, error)
- func NormalizeRecipients(raw []string) ([]string, error)
- func ResolveMCPRefreshScope(granted, requested string) (string, bool)
- func SendAlert(ctx context.Context, cfg SMTPConfig, alert AlertMail) error
- func SendCode(cfg SMTPConfig, to, code string) error
- func SendInvite(cfg SMTPConfig, to string) error
- func SessionMetadataMiddleware(next http.Handler) http.Handler
- func ValidRole(role string) bool
- func ValidUserStatus(status string) bool
- func VerifyHash(code, hash, secret string) bool
- type AlertMail
- type AuditEvent
- type AuditEventType
- type AuditOutcome
- type AuditStore
- type AuditTargetType
- type BrowserSessions
- func (s *BrowserSessions) AuthVersion(ctx context.Context) int64
- func (s *BrowserSessions) BeginOIDCSession(ctx context.Context, flowTTL, maximum time.Duration, ...) error
- func (s *BrowserSessions) CleanupExpired(ctx context.Context, now time.Time) (int64, error)
- func (s *BrowserSessions) ClearOIDCFlow(ctx context.Context)
- func (s *BrowserSessions) CountStatus(ctx context.Context, now time.Time) (active, expired int64, err error)
- func (s *BrowserSessions) Deadline(ctx context.Context) time.Time
- func (s *BrowserSessions) Destroy(ctx context.Context) error
- func (s *BrowserSessions) EnforceActivity(ctx context.Context, now time.Time) error
- func (s *BrowserSessions) EstablishAuthenticatedSession(ctx context.Context, user User) error
- func (s *BrowserSessions) Middleware(next http.Handler) http.Handler
- func (s *BrowserSessions) OIDCFlow(ctx context.Context) (state, nonce, verifier, returnTo string)
- func (s *BrowserSessions) UserID(ctx context.Context) string
- type CodeStore
- func (s *CodeStore) Cleanup() error
- func (s *CodeStore) Create(email string) (string, error)
- func (s *CodeStore) CreateBreakGlassLoginLink(email string) (string, error)
- func (s *CodeStore) CreateLoginLink(email string) (string, error)
- func (s *CodeStore) RecentCount(email string, since time.Time) (int, error)
- func (s *CodeStore) Verify(email, code string) (bool, error)
- func (s *CodeStore) VerifyBreakGlassLoginLink(token string) (string, bool, error)
- func (s *CodeStore) VerifyLoginLink(token string) (string, bool, error)
- type IdentityStore
- func (s *IdentityStore) CountForUser(ctx context.Context, userID string) (int64, error)
- func (s *IdentityStore) Find(ctx context.Context, issuer, subject string) (UserIdentity, error)
- func (s *IdentityStore) FindForUser(ctx context.Context, userID string) (UserIdentity, error)
- func (s *IdentityStore) LinkWithAudit(ctx context.Context, userID, issuer, subject, email string, audit *AuditStore, ...) (UserIdentity, error)
- func (s *IdentityStore) TouchLogin(ctx context.Context, id string) error
- type KeyedLimiter
- type OAuthAuthorizationCode
- type OAuthClient
- type OAuthConnection
- type OAuthStore
- func (s *OAuthStore) CleanupExpired(ctx context.Context, now time.Time) (int64, error)
- func (s *OAuthStore) ConsumeAuthorizationCode(ctx context.Context, raw string) (OAuthAuthorizationCode, error)
- func (s *OAuthStore) CreateAuthorizationCode(ctx context.Context, code OAuthAuthorizationCode) (string, error)
- func (s *OAuthStore) GetClient(ctx context.Context, clientID string) (OAuthClient, error)
- func (s *OAuthStore) IssueTokenPair(ctx context.Context, clientID, userID, scope, resource string) (OAuthTokenPair, error)
- func (s *OAuthStore) ListConnections(ctx context.Context, userID string) ([]OAuthConnection, error)
- func (s *OAuthStore) RegisterClient(ctx context.Context, name, clientURI string, redirectURIs []string) (OAuthClient, error)
- func (s *OAuthStore) RevokeConnection(ctx context.Context, userID, clientID string, event AuditEvent) error
- func (s *OAuthStore) RotateRefreshToken(ctx context.Context, clientID, raw, resource, requestedScope string) (OAuthTokenPair, error)
- func (s *OAuthStore) VerifyAccessToken(ctx context.Context, raw, resource string) (OAuthTokenRecord, error)
- type OAuthTokenPair
- type OAuthTokenRecord
- type ProvisionRequest
- type Role
- type SMTPConfig
- type SQLiteSessionStore
- func (s *SQLiteSessionStore) CleanupExpired(ctx context.Context, idleTTL time.Duration, now time.Time) (int64, error)
- func (s *SQLiteSessionStore) Commit(token string, data []byte, expiry time.Time) error
- func (s *SQLiteSessionStore) CommitCtx(ctx context.Context, token string, data []byte, expiry time.Time) error
- func (s *SQLiteSessionStore) CountStatus(ctx context.Context, idleTTL time.Duration, now time.Time) (active, expired int64, err error)
- func (s *SQLiteSessionStore) Delete(token string) error
- func (s *SQLiteSessionStore) DeleteCtx(ctx context.Context, token string) error
- func (s *SQLiteSessionStore) DeleteUserSessions(ctx context.Context, userID string) error
- func (s *SQLiteSessionStore) Find(token string) ([]byte, bool, error)
- func (s *SQLiteSessionStore) FindCtx(ctx context.Context, token string) ([]byte, bool, error)
- func (s *SQLiteSessionStore) Touch(ctx context.Context, rawToken SessionToken, before, now time.Time) (bool, error)
- type SessionMetadata
- type SessionToken
- type SessionTokenDigest
- type Setup
- type SetupStatus
- type TokenKind
- type User
- type UserChange
- type UserIdentity
- type UserStatus
- type UserStore
- func (s *UserStore) CountActiveAdmins() (int64, error)
- func (s *UserStore) CountUsers() (int64, error)
- func (s *UserStore) CreateFirstAdminWithAudit(email, displayName string, event AuditEvent) (User, error)
- func (s *UserStore) CreateWithAudit(email, displayName string, role Role, event AuditEvent) (User, error)
- func (s *UserStore) DeleteWithAudit(id string, event AuditEvent) error
- func (s *UserStore) GetByEmail(email string) (User, error)
- func (s *UserStore) GetByEmailContext(ctx context.Context, email string) (User, error)
- func (s *UserStore) GetByID(id string) (User, error)
- func (s *UserStore) GetByIDContext(ctx context.Context, id string) (User, error)
- func (s *UserStore) List() ([]User, error)
- func (s *UserStore) ProvisionFederated(ctx context.Context, req ProvisionRequest, source AuditEvent) (User, UserIdentity, bool, error)
- func (s *UserStore) RevokeAllSessionsWithAudit(id string, event AuditEvent) error
- func (s *UserStore) TouchLogin(id string) error
- func (s *UserStore) TouchLoginAt(id string, at time.Time) error
- func (s *UserStore) UpdateProvisioned(id string, change UserChange, source AuditEvent) (User, bool, error)
- func (s *UserStore) UpdateWithAudit(id string, email, displayName *string, role *Role, status *UserStatus, ...) (User, error)
Constants ¶
const ( // MCPScopeTelemetryRead grants read access to Pitot observability data. MCPScopeTelemetryRead = "telemetry:read" // MCPScopeDashboardManage grants access to manage the authenticated user's dashboards. MCPScopeDashboardManage = "dashboard:manage" )
const ( // Access tokens are checked against the database on every request, so // revocation is immediate whatever their lifetime. A long lifetime keeps // agent clients from refreshing, and racing each other, more than monthly. OAuthAccessTTL = 30 * 24 * time.Hour OAuthRefreshTTL = 90 * 24 * time.Hour OAuthCodeTTL = 5 * time.Minute // OAuthRefreshReuseGrace admits a refresh token its own client rotated // within one access-token lifetime. Agent processes sharing one stored // credential refresh from stale copies minutes or hours apart, and the // holder of that credential already holds an access token that lives as // long; later reuse still revokes the family. OAuthRefreshReuseGrace = OAuthAccessTTL )
const MaxAlertEmailRecipients = 10
MaxAlertEmailRecipients caps the addresses on one alert rule and on the default destination.
const SetupTTL = time.Hour
Variables ¶
var ( ErrOAuthClientNotFound = errors.New("oauth client not found") ErrOAuthConnectionNotFound = errors.New("oauth connection not found") ErrInvalidOAuthGrant = errors.New("invalid oauth grant") ErrInvalidOAuthScope = errors.New("invalid oauth scope") ErrOAuthRefreshReuse = errors.New("oauth refresh token reuse detected") ErrInvalidOAuthToken = errors.New("invalid oauth token") )
var ErrCodeSecretRequired = errors.New("auth: PITOT_AUTH_CODE_SECRET is required for sign-in credentials")
ErrCodeSecretRequired reports a sign-in credential operation attempted without PITOT_AUTH_CODE_SECRET. An empty HMAC key would make stored hashes computable from the credential alone.
var ErrFirstUserMustBeAdmin = errors.New("the first account must be an active administrator")
ErrFirstUserMustBeAdmin refuses an account on an empty database that would leave the installation without an active administrator.
var ErrIdentityConflict = errors.New("identity is already linked")
var ErrInvalidMailAddress = errors.New("invalid mail address")
ErrInvalidMailAddress marks a sender or recipient that does not parse.
var ErrLastActiveAdmin = errors.New("cannot remove the last active admin")
ErrLastActiveAdmin is returned when an operation would remove the final active admin.
var ErrSessionExpired = errors.New("session expired")
var ErrSetupComplete = errors.New("setup already complete")
ErrSetupComplete is returned when setup is attempted but users already exist.
var ErrUserConflict = errors.New("user already exists")
ErrUserConflict is returned when an email is already assigned to a user.
var ErrUserNotFound = errors.New("user not found")
ErrUserNotFound is returned when a requested user does not exist.
Functions ¶
func CanonicalMCPOAuthScope ¶
CanonicalMCPOAuthScope validates an MCP OAuth scope string and returns its deduplicated canonical representation. Retired scope names are rejected.
func DetachedWriteContext ¶
DetachedWriteContext preserves request values but prevents a disconnected client from cancelling a security-critical revocation, session, or audit write. The deadline remains bounded beyond SQLite's busy window.
func GenerateLoginLinkToken ¶
GenerateLoginLinkToken returns a credential with 256 bits of entropy.
func IsPermanentMailError ¶
IsPermanentMailError reports whether retrying err cannot succeed: an address that does not parse, or a 5xx SMTP reply. Everything else is transient, including a connection lost mid-session, which go-mail reports as a SendError with no server code and does not count as temporary.
func MailFailureDetail ¶
MailFailureDetail describes a send failure by its class and SMTP code, for logs and status shown to users. It never includes err's text, which can carry server responses and recipient addresses.
func NormalizeEmail ¶
NormalizeEmail trims, lowercases, and validates an email address.
func NormalizeRecipients ¶
NormalizeRecipients validates a list of bare email addresses, returning them normalized and deduplicated. It rejects display-name forms, control characters and lists over MaxAlertEmailRecipients.
func ResolveMCPRefreshScope ¶
ResolveMCPRefreshScope applies the optional scope from a refresh request. Refreshes may retain or reduce the original grant, but never expand it.
func SendAlert ¶
func SendAlert(ctx context.Context, cfg SMTPConfig, alert AlertMail) error
SendAlert renders and sends one alert notification.
func SendCode ¶
func SendCode(cfg SMTPConfig, to, code string) error
SendCode sends a verification code email via SMTP.
func SendInvite ¶
func SendInvite(cfg SMTPConfig, to string) error
SendInvite sends an invitation email to a new user.
func SessionMetadataMiddleware ¶
SessionMetadataMiddleware must wrap SCS LoadAndSave.
func ValidUserStatus ¶
func VerifyHash ¶
VerifyHash checks a code against a hash using constant-time comparison.
Types ¶
type AlertMail ¶
type AlertMail struct {
// ID identifies the delivery. It becomes the Message-ID, so a resend after
// an interrupted attempt carries the same one.
ID string
To string
Rule string
Description string
Service string
Event string
Value float64
Time time.Time
// LimitNotice, when set, warns that later notifications will be suppressed.
LimitNotice string
}
AlertMail is one alert notification for one recipient. Every text field may hold telemetry-derived or operator-written values; SendAlert neutralizes them.
type AuditEvent ¶
type AuditEvent struct {
ActorUserID string
EventType AuditEventType
Outcome AuditOutcome
TargetType AuditTargetType
TargetID string
RemoteIP string
UserAgent string
Metadata map[string]any
}
type AuditEventType ¶
type AuditEventType string
type AuditOutcome ¶
type AuditOutcome string
type AuditStore ¶
type AuditStore struct {
// contains filtered or unexported fields
}
func NewAuditStore ¶
func NewAuditStore(db *sql.DB) *AuditStore
func (*AuditStore) Record ¶
func (s *AuditStore) Record(ctx context.Context, event AuditEvent) error
func (*AuditStore) RecordTx ¶
func (s *AuditStore) RecordTx(ctx context.Context, tx *sql.Tx, event AuditEvent) error
type AuditTargetType ¶
type AuditTargetType string
type BrowserSessions ¶
type BrowserSessions struct {
IdleTTL time.Duration
AbsoluteTTL time.Duration
ActivityCheckpoint time.Duration
// contains filtered or unexported fields
}
BrowserSessions owns every permitted SCS deadline and renewal operation.
func NewBrowserSessions ¶
func (*BrowserSessions) AuthVersion ¶
func (s *BrowserSessions) AuthVersion(ctx context.Context) int64
func (*BrowserSessions) BeginOIDCSession ¶
func (s *BrowserSessions) BeginOIDCSession(ctx context.Context, flowTTL, maximum time.Duration, state, nonce, verifier, returnTo string) error
BeginOIDCSession creates a short-lived pre-authentication session and stores the single-use values needed to validate the callback.
func (*BrowserSessions) CleanupExpired ¶
func (*BrowserSessions) ClearOIDCFlow ¶
func (s *BrowserSessions) ClearOIDCFlow(ctx context.Context)
func (*BrowserSessions) CountStatus ¶
func (*BrowserSessions) Deadline ¶
func (s *BrowserSessions) Deadline(ctx context.Context) time.Time
func (*BrowserSessions) EnforceActivity ¶
func (*BrowserSessions) EstablishAuthenticatedSession ¶
func (s *BrowserSessions) EstablishAuthenticatedSession(ctx context.Context, user User) error
func (*BrowserSessions) Middleware ¶
func (s *BrowserSessions) Middleware(next http.Handler) http.Handler
type CodeStore ¶
type CodeStore struct {
// contains filtered or unexported fields
}
CodeStore manages verification codes in SQLite.
func NewCodeStore ¶
NewCodeStore creates a CodeStore with the given HMAC secret.
func (*CodeStore) Create ¶
Create stores a verification code for the given email. Returns the plaintext code.
func (*CodeStore) CreateBreakGlassLoginLink ¶
CreateBreakGlassLoginLink stores a short-lived, single-use credential that only the OIDC-mode link route redeems.
func (*CodeStore) CreateLoginLink ¶
CreateLoginLink stores a short-lived, single-use login link credential.
func (*CodeStore) RecentCount ¶
func (*CodeStore) VerifyBreakGlassLoginLink ¶
VerifyBreakGlassLoginLink atomically consumes a valid break-glass link and returns the email it was issued for. Ordinary login links never match.
type IdentityStore ¶
type IdentityStore struct {
// contains filtered or unexported fields
}
func NewIdentityStore ¶
func NewIdentityStore(db *sql.DB) *IdentityStore
func (*IdentityStore) CountForUser ¶
func (*IdentityStore) Find ¶
func (s *IdentityStore) Find(ctx context.Context, issuer, subject string) (UserIdentity, error)
func (*IdentityStore) FindForUser ¶
func (s *IdentityStore) FindForUser(ctx context.Context, userID string) (UserIdentity, error)
FindForUser returns the identity linked to a user, or ErrUserNotFound when the user has none.
func (*IdentityStore) LinkWithAudit ¶
func (s *IdentityStore) LinkWithAudit(ctx context.Context, userID, issuer, subject, email string, audit *AuditStore, event AuditEvent) (UserIdentity, error)
func (*IdentityStore) TouchLogin ¶
func (s *IdentityStore) TouchLogin(ctx context.Context, id string) error
type KeyedLimiter ¶
type KeyedLimiter struct {
// contains filtered or unexported fields
}
KeyedLimiter is a bounded-lifetime in-memory limiter for source-derived bucket keys. Account/email cooldowns remain durable in SQLite.
func NewKeyedLimiter ¶
func NewKeyedLimiter(count int, window time.Duration) *KeyedLimiter
func (*KeyedLimiter) Allow ¶
func (l *KeyedLimiter) Allow(key string) bool
type OAuthAuthorizationCode ¶
type OAuthClient ¶
type OAuthClient struct {
ClientID string `json:"client_id"`
ClientName string `json:"client_name"`
ClientURI string `json:"client_uri,omitempty"`
RedirectURIs []string `json:"redirect_uris"`
GrantTypes []string `json:"grant_types"`
ResponseTypes []string `json:"response_types"`
TokenEndpointAuthMethod string `json:"token_endpoint_auth_method"`
CreatedAt int64 `json:"client_id_issued_at"`
}
type OAuthConnection ¶
type OAuthStore ¶
type OAuthStore struct {
// contains filtered or unexported fields
}
func NewOAuthStore ¶
func NewOAuthStore(db *sql.DB) *OAuthStore
func (*OAuthStore) CleanupExpired ¶
CleanupExpired garbage-collects OAuth state that can no longer affect any flow, returning the total number of rows deleted. It removes:
- authorization codes past their expiry,
- token rows that are individually dead (expired or revoked) AND whose refresh family has no live refresh token left — revoked rows in a still-live family are kept because they are exactly what refresh-reuse detection matches against,
- dynamically-registered clients older than oauthClientGCAge with no remaining codes or tokens.
func (*OAuthStore) ConsumeAuthorizationCode ¶
func (s *OAuthStore) ConsumeAuthorizationCode(ctx context.Context, raw string) (OAuthAuthorizationCode, error)
func (*OAuthStore) CreateAuthorizationCode ¶
func (s *OAuthStore) CreateAuthorizationCode(ctx context.Context, code OAuthAuthorizationCode) (string, error)
func (*OAuthStore) GetClient ¶
func (s *OAuthStore) GetClient(ctx context.Context, clientID string) (OAuthClient, error)
func (*OAuthStore) IssueTokenPair ¶
func (s *OAuthStore) IssueTokenPair(ctx context.Context, clientID, userID, scope, resource string) (OAuthTokenPair, error)
func (*OAuthStore) ListConnections ¶
func (s *OAuthStore) ListConnections(ctx context.Context, userID string) ([]OAuthConnection, error)
func (*OAuthStore) RegisterClient ¶
func (s *OAuthStore) RegisterClient(ctx context.Context, name, clientURI string, redirectURIs []string) (OAuthClient, error)
func (*OAuthStore) RevokeConnection ¶
func (s *OAuthStore) RevokeConnection(ctx context.Context, userID, clientID string, event AuditEvent) error
func (*OAuthStore) RotateRefreshToken ¶
func (s *OAuthStore) RotateRefreshToken(ctx context.Context, clientID, raw, resource, requestedScope string) (OAuthTokenPair, error)
func (*OAuthStore) VerifyAccessToken ¶
func (s *OAuthStore) VerifyAccessToken(ctx context.Context, raw, resource string) (OAuthTokenRecord, error)
VerifyAccessToken returns ErrInvalidOAuthToken only for tokens that are definitively invalid (unknown, expired, revoked, or wrong audience). A database failure is returned as a wrapped infrastructure error so callers can fail closed without treating an outage as a bad credential.
type OAuthTokenPair ¶
func (OAuthTokenPair) String ¶
func (p OAuthTokenPair) String() string
String implements fmt.Stringer with the token material redacted so that a stray %v/%s log of a pair can never leak raw credentials.
type OAuthTokenRecord ¶
type ProvisionRequest ¶
type ProvisionRequest struct {
Issuer string
Subject string
Email string
DisplayName string
Role Role
Status UserStatus
}
ProvisionRequest describes an account an identity provider wants to exist.
type SMTPConfig ¶
SMTPConfig holds SMTP connection settings.
type SQLiteSessionStore ¶
type SQLiteSessionStore struct {
// contains filtered or unexported fields
}
SQLiteSessionStore implements both scs.Store and scs.CtxStore. Reads inherit request cancellation. Security writes deliberately shed request cancellation but remain bounded beyond SQLite's busy timeout.
func NewSQLiteSessionStore ¶
func NewSQLiteSessionStore(db *sql.DB) *SQLiteSessionStore
func (*SQLiteSessionStore) CleanupExpired ¶
func (*SQLiteSessionStore) CountStatus ¶
func (*SQLiteSessionStore) Delete ¶
func (s *SQLiteSessionStore) Delete(token string) error
func (*SQLiteSessionStore) DeleteCtx ¶
func (s *SQLiteSessionStore) DeleteCtx(ctx context.Context, token string) error
func (*SQLiteSessionStore) DeleteUserSessions ¶
func (s *SQLiteSessionStore) DeleteUserSessions(ctx context.Context, userID string) error
func (*SQLiteSessionStore) Find ¶
func (s *SQLiteSessionStore) Find(token string) ([]byte, bool, error)
func (*SQLiteSessionStore) Touch ¶
func (s *SQLiteSessionStore) Touch(ctx context.Context, rawToken SessionToken, before, now time.Time) (bool, error)
type SessionMetadata ¶
type SessionMetadata struct {
UserID string
CreatedAt time.Time
LastActivityAt time.Time
AbsoluteExpiresAt time.Time
}
SessionMetadata is queryable metadata stored alongside SCS's opaque blob. A pointer is placed in the request context before SCS runs so FindCtx and CommitCtx share it without replacing the context SCS retains for commit.
type SessionToken ¶
type SessionToken string
type SessionTokenDigest ¶
type SessionTokenDigest string
func SessionTokenHash ¶
func SessionTokenHash(token SessionToken) SessionTokenDigest
SessionTokenHash matches SCS v2.9 HashTokenInStore. Its compatibility is covered by an integration test so an upstream format change cannot silently orphan activity updates or revocation.
type Setup ¶
type Setup struct {
// contains filtered or unexported fields
}
Setup holds the in-memory first-boot admin token.
func (*Setup) Verify ¶
func (s *Setup) Verify(token string) SetupStatus
Verify returns why a setup token is or isn't acceptable. Comparison is constant-time.
type SetupStatus ¶
type SetupStatus int
SetupStatus is the result of verifying a presented setup token.
const ( SetupStatusOK SetupStatus = iota SetupStatusUnset SetupStatusExpired SetupStatusWrong )
func (SetupStatus) String ¶
func (s SetupStatus) String() string
type User ¶
type User struct {
ID string `json:"id"`
Email string `json:"email"`
DisplayName string `json:"display_name"`
Role Role `json:"role"`
Status UserStatus `json:"status"`
AuthVersion int64 `json:"-"`
LoggedInAt string `json:"logged_in_at,omitempty"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
User represents an authenticated user.
type UserChange ¶
type UserChange struct {
Email *string
DisplayName *string
Role *Role
Status *UserStatus
}
UserChange lists the fields a directory update may set; nil leaves one alone.
type UserIdentity ¶
type UserStatus ¶
type UserStatus string
const ( UserStatusActive UserStatus = "active" UserStatusSuspended UserStatus = "suspended" )
type UserStore ¶
type UserStore struct {
// contains filtered or unexported fields
}
UserStore provides CRUD operations for users.
func NewUserStore ¶
NewUserStore creates a UserStore backed by the given database connection.
func (*UserStore) CountActiveAdmins ¶
CountActiveAdmins returns the number of active admin users.
func (*UserStore) CountUsers ¶
CountUsers returns the number of users in the database.
func (*UserStore) CreateFirstAdminWithAudit ¶
func (s *UserStore) CreateFirstAdminWithAudit(email, displayName string, event AuditEvent) (User, error)
CreateFirstAdminWithAudit atomically creates the first admin user. Returns ErrSetupComplete if users already exist (race-safe).
func (*UserStore) CreateWithAudit ¶
func (s *UserStore) CreateWithAudit(email, displayName string, role Role, event AuditEvent) (User, error)
CreateWithAudit adds a new user.
func (*UserStore) DeleteWithAudit ¶
func (s *UserStore) DeleteWithAudit(id string, event AuditEvent) error
DeleteWithAudit removes a user and all of its browser sessions by ID.
func (*UserStore) GetByEmail ¶
GetByEmail returns a user by email address.
func (*UserStore) GetByEmailContext ¶
func (*UserStore) GetByIDContext ¶
func (*UserStore) ProvisionFederated ¶
func (s *UserStore) ProvisionFederated(ctx context.Context, req ProvisionRequest, source AuditEvent) (User, UserIdentity, bool, error)
ProvisionFederated creates an account and its identity link in one transaction, so a crash cannot leave an unlinked account for a later login to claim by email.
A request whose identity already exists changes nothing and returns the current account with created false. A delayed retry therefore cannot undo a later role change or suspension; the provisioner applies changes with an update.
source supplies attribution for the audit events; its type and target are set here.
func (*UserStore) RevokeAllSessionsWithAudit ¶
func (s *UserStore) RevokeAllSessionsWithAudit(id string, event AuditEvent) error
RevokeAllSessionsWithAudit invalidates and removes every browser session for a user.
func (*UserStore) TouchLogin ¶
TouchLogin updates the logged_in_at timestamp.
func (*UserStore) UpdateProvisioned ¶
func (s *UserStore) UpdateProvisioned(id string, change UserChange, source AuditEvent) (User, bool, error)
UpdateProvisioned applies a directory update in one write transaction, including the last-active-administrator check. A change to the current state is reported with changed false and writes nothing, so it is safe to repeat. The exception is repeating a suspension while a session or OAuth credential is still live: those are removed and audited. The identity link is never touched.
func (*UserStore) UpdateWithAudit ¶
func (s *UserStore) UpdateWithAudit(id string, email, displayName *string, role *Role, status *UserStatus, event AuditEvent) (User, error)
UpdateWithAudit modifies a user's fields. Email, role, or status changes revoke every browser session.