Documentation
¶
Overview ¶
Package mongo implements the AuthSome store interface using MongoDB via Grove ORM.
Index ¶
- Variables
- type Store
- func (s *Store) AddUserEmail(ctx context.Context, e *user.UserEmail) error
- func (s *Store) BatchResolve(ctx context.Context, keys []string, opts settings.ResolveOpts) (map[string][]*settings.Setting, error)
- func (s *Store) Close() error
- func (s *Store) ConsumePasswordReset(ctx context.Context, token string) error
- func (s *Store) ConsumeVerification(ctx context.Context, token string) error
- func (s *Store) CreateAPIKey(ctx context.Context, k *apikey.APIKey) error
- func (s *Store) CreateApp(ctx context.Context, a *app.App) error
- func (s *Store) CreateDelegation(ctx context.Context, d *principal.Delegation) error
- func (s *Store) CreateDevice(ctx context.Context, d *device.Device) error
- func (s *Store) CreateEnvironment(ctx context.Context, e *environment.Environment) error
- func (s *Store) CreateFormConfig(ctx context.Context, fc *formconfig.FormConfig) error
- func (s *Store) CreateInvitation(ctx context.Context, inv *organization.Invitation) error
- func (s *Store) CreateMember(ctx context.Context, mem *organization.Member) error
- func (s *Store) CreateNotification(ctx context.Context, n *notification.Notification) error
- func (s *Store) CreateOrganization(ctx context.Context, o *organization.Organization) error
- func (s *Store) CreatePasswordReset(ctx context.Context, pr *account.PasswordReset) error
- func (s *Store) CreateServiceAccount(ctx context.Context, svc *serviceaccount.ServiceAccount) error
- func (s *Store) CreateSession(ctx context.Context, sess *session.Session) error
- func (s *Store) CreateTeam(ctx context.Context, t *organization.Team) error
- func (s *Store) CreateUser(ctx context.Context, u *user.User) error
- func (s *Store) CreateUserWithPrimaryEmail(ctx context.Context, u *user.User, primary *user.UserEmail) error
- func (s *Store) CreateVerification(ctx context.Context, v *account.Verification) error
- func (s *Store) CreateWebhook(ctx context.Context, w *webhook.Webhook) error
- func (s *Store) DB() *grove.DB
- func (s *Store) DeleteAPIKey(ctx context.Context, keyID id.APIKeyID) error
- func (s *Store) DeleteApp(ctx context.Context, appID id.AppID) error
- func (s *Store) DeleteAppClientConfig(ctx context.Context, appID id.AppID) error
- func (s *Store) DeleteAppSessionConfig(ctx context.Context, appID id.AppID) error
- func (s *Store) DeleteBranding(ctx context.Context, orgID id.OrgID) error
- func (s *Store) DeleteDevice(ctx context.Context, deviceID id.DeviceID) error
- func (s *Store) DeleteEnvironment(ctx context.Context, envID id.EnvironmentID) error
- func (s *Store) DeleteExpiredPasswordResets(ctx context.Context, before time.Time, batch int) (int64, error)
- func (s *Store) DeleteExpiredRevokedRefreshTokens(ctx context.Context, before time.Time, batch int) (int64, error)
- func (s *Store) DeleteExpiredSessions(ctx context.Context, before time.Time, batch int) (int64, error)
- func (s *Store) DeleteExpiredVerifications(ctx context.Context, before time.Time, batch int) (int64, error)
- func (s *Store) DeleteFormConfig(ctx context.Context, appID id.AppID, formType string) error
- func (s *Store) DeleteInvitation(ctx context.Context, invID id.InvitationID) error
- func (s *Store) DeleteMember(ctx context.Context, memberID id.MemberID) error
- func (s *Store) DeleteOrganization(ctx context.Context, orgID id.OrgID) error
- func (s *Store) DeleteOrganizationCascade(ctx context.Context, orgID id.OrgID) error
- func (s *Store) DeleteServiceAccount(ctx context.Context, svcID id.ServiceAccountID) error
- func (s *Store) DeleteSession(ctx context.Context, sessionID id.SessionID) error
- func (s *Store) DeleteSessionsByGrant(ctx context.Context, grantID id.AgentGrantID) error
- func (s *Store) DeleteSetting(ctx context.Context, key string, scope settings.Scope, scopeID string) error
- func (s *Store) DeleteSettingsByNamespace(ctx context.Context, namespace string) error
- func (s *Store) DeleteTeam(ctx context.Context, teamID id.TeamID) error
- func (s *Store) DeleteUser(ctx context.Context, userID id.UserID) error
- func (s *Store) DeleteUserEmail(ctx context.Context, userID id.UserID, email string) error
- func (s *Store) DeleteUserSessions(ctx context.Context, userID id.UserID) error
- func (s *Store) DeleteWebhook(ctx context.Context, webhookID id.WebhookID) error
- func (s *Store) EnsureTTLIndexes(ctx context.Context, ttl map[string]time.Duration) error
- func (s *Store) FindActiveDelegation(ctx context.Context, appID id.AppID, actor, subject principal.Ref, ...) (*principal.Delegation, error)
- func (s *Store) FindByPrefix(ctx context.Context, prefix string) (*apikey.APIKey, error)
- func (s *Store) GetAPIKey(ctx context.Context, keyID id.APIKeyID) (*apikey.APIKey, error)
- func (s *Store) GetAPIKeyByPrefix(ctx context.Context, appID id.AppID, prefix string) (*apikey.APIKey, error)
- func (s *Store) GetAPIKeyByPublicKey(ctx context.Context, appID id.AppID, publicKey string) (*apikey.APIKey, error)
- func (s *Store) GetActiveEmailVerification(ctx context.Context, userID id.UserID) (*account.Verification, error)
- func (s *Store) GetApp(ctx context.Context, appID id.AppID) (*app.App, error)
- func (s *Store) GetAppByPublishableKey(ctx context.Context, key string) (*app.App, error)
- func (s *Store) GetAppBySlug(ctx context.Context, slug string) (*app.App, error)
- func (s *Store) GetAppClientConfig(ctx context.Context, appID id.AppID) (*appclientconfig.Config, error)
- func (s *Store) GetAppSessionConfig(ctx context.Context, appID id.AppID) (*appsessionconfig.Config, error)
- func (s *Store) GetBranding(ctx context.Context, orgID id.OrgID) (*formconfig.BrandingConfig, error)
- func (s *Store) GetDefaultEnvironment(ctx context.Context, appID id.AppID) (*environment.Environment, error)
- func (s *Store) GetDelegation(ctx context.Context, delID id.DelegationID) (*principal.Delegation, error)
- func (s *Store) GetDevice(ctx context.Context, deviceID id.DeviceID) (*device.Device, error)
- func (s *Store) GetDeviceByFingerprint(ctx context.Context, userID id.UserID, fingerprint string) (*device.Device, error)
- func (s *Store) GetEnvironment(ctx context.Context, envID id.EnvironmentID) (*environment.Environment, error)
- func (s *Store) GetEnvironmentBySlug(ctx context.Context, appID id.AppID, slug string) (*environment.Environment, error)
- func (s *Store) GetFormConfig(ctx context.Context, appID id.AppID, formType string) (*formconfig.FormConfig, error)
- func (s *Store) GetInvitation(ctx context.Context, invID id.InvitationID) (*organization.Invitation, error)
- func (s *Store) GetInvitationByToken(ctx context.Context, token string) (*organization.Invitation, error)
- func (s *Store) GetMember(ctx context.Context, memberID id.MemberID) (*organization.Member, error)
- func (s *Store) GetMemberByUserAndOrg(ctx context.Context, userID id.UserID, orgID id.OrgID) (*organization.Member, error)
- func (s *Store) GetNotification(ctx context.Context, notifID id.NotificationID) (*notification.Notification, error)
- func (s *Store) GetOrganization(ctx context.Context, orgID id.OrgID) (*organization.Organization, error)
- func (s *Store) GetOrganizationBySlug(ctx context.Context, appID id.AppID, slug string) (*organization.Organization, error)
- func (s *Store) GetPasswordReset(ctx context.Context, token string) (*account.PasswordReset, error)
- func (s *Store) GetPlatformApp(ctx context.Context) (*app.App, error)
- func (s *Store) GetPrincipal(ctx context.Context, ref principal.Ref) (*principal.Principal, error)
- func (s *Store) GetRevokedRefreshTokenFamily(ctx context.Context, tokenHash string) (id.SessionFamilyID, error)
- func (s *Store) GetServiceAccount(ctx context.Context, svcID id.ServiceAccountID) (*serviceaccount.ServiceAccount, error)
- func (s *Store) GetSession(ctx context.Context, sessionID id.SessionID) (*session.Session, error)
- func (s *Store) GetSessionByRefreshToken(ctx context.Context, refreshToken string) (*session.Session, error)
- func (s *Store) GetSessionByToken(ctx context.Context, token string) (*session.Session, error)
- func (s *Store) GetSetting(ctx context.Context, key string, scope settings.Scope, scopeID string) (*settings.Setting, error)
- func (s *Store) GetTeam(ctx context.Context, teamID id.TeamID) (*organization.Team, error)
- func (s *Store) GetUser(ctx context.Context, userID id.UserID) (*user.User, error)
- func (s *Store) GetUserByAnyEmail(ctx context.Context, appID id.AppID, envID id.EnvironmentID, email string) (*user.User, error)
- func (s *Store) GetUserByEmail(ctx context.Context, appID id.AppID, envID id.EnvironmentID, email string) (*user.User, error)
- func (s *Store) GetUserByPhone(ctx context.Context, appID id.AppID, envID id.EnvironmentID, phone string) (*user.User, error)
- func (s *Store) GetUserByUsername(ctx context.Context, appID id.AppID, envID id.EnvironmentID, username string) (*user.User, error)
- func (s *Store) GetUserEmailRecord(ctx context.Context, appID id.AppID, envID id.EnvironmentID, email string) (*user.UserEmail, error)
- func (s *Store) GetUserEmails(ctx context.Context, userID id.UserID) ([]*user.UserEmail, error)
- func (s *Store) GetVerification(ctx context.Context, token string) (*account.Verification, error)
- func (s *Store) GetWebhook(ctx context.Context, webhookID id.WebhookID) (*webhook.Webhook, error)
- func (s *Store) HashLegacyTokens(ctx context.Context, batch int) (int64, error)
- func (s *Store) IsRefreshTokenRevoked(ctx context.Context, tokenHash string) (bool, error)
- func (s *Store) KVCounter(ctx context.Context, key string) (int64, error)
- func (s *Store) KVDelete(ctx context.Context, key string) error
- func (s *Store) KVDeleteExpired(ctx context.Context, now time.Time) (int64, error)
- func (s *Store) KVGet(ctx context.Context, key string) ([]byte, error)
- func (s *Store) KVIncrement(ctx context.Context, key string, ttl time.Duration) (int64, error)
- func (s *Store) KVSet(ctx context.Context, key string, value []byte, ttl time.Duration) error
- func (s *Store) KVSetNX(ctx context.Context, key string, value []byte, ttl time.Duration) (bool, error)
- func (s *Store) ListAPIKeysByApp(ctx context.Context, appID id.AppID) ([]*apikey.APIKey, error)
- func (s *Store) ListAPIKeysByUser(ctx context.Context, appID id.AppID, userID id.UserID) ([]*apikey.APIKey, error)
- func (s *Store) ListApps(ctx context.Context) ([]*app.App, error)
- func (s *Store) ListDelegations(ctx context.Context, q *principal.DelegationQuery) ([]*principal.Delegation, error)
- func (s *Store) ListDevices(ctx context.Context, limit int) ([]*device.Device, error)
- func (s *Store) ListEnvironments(ctx context.Context, appID id.AppID) ([]*environment.Environment, error)
- func (s *Store) ListFormConfigs(ctx context.Context, appID id.AppID) ([]*formconfig.FormConfig, error)
- func (s *Store) ListInvitations(ctx context.Context, orgID id.OrgID) ([]*organization.Invitation, error)
- func (s *Store) ListInvitationsPage(ctx context.Context, orgID id.OrgID, opts page.Opts) (page.Page[*organization.Invitation], error)
- func (s *Store) ListMembers(ctx context.Context, orgID id.OrgID) ([]*organization.Member, error)
- func (s *Store) ListMembersPage(ctx context.Context, orgID id.OrgID, opts page.Opts) (page.Page[*organization.Member], error)
- func (s *Store) ListOrganizations(ctx context.Context, appID id.AppID) ([]*organization.Organization, error)
- func (s *Store) ListOrganizationsPage(ctx context.Context, appID id.AppID, opts page.Opts) (page.Page[*organization.Organization], error)
- func (s *Store) ListPrincipals(ctx context.Context, q *principal.Query) ([]*principal.Principal, error)
- func (s *Store) ListServiceAccounts(ctx context.Context, q *serviceaccount.Query) (*serviceaccount.List, error)
- func (s *Store) ListSessions(ctx context.Context, limit int) ([]*session.Session, error)
- func (s *Store) ListSettings(ctx context.Context, opts settings.ListOpts) ([]*settings.Setting, error)
- func (s *Store) ListTeams(ctx context.Context, orgID id.OrgID) ([]*organization.Team, error)
- func (s *Store) ListTeamsPage(ctx context.Context, orgID id.OrgID, opts page.Opts) (page.Page[*organization.Team], error)
- func (s *Store) ListUserDevices(ctx context.Context, userID id.UserID) ([]*device.Device, error)
- func (s *Store) ListUserNotifications(ctx context.Context, userID id.UserID) ([]*notification.Notification, error)
- func (s *Store) ListUserOrganizations(ctx context.Context, userID id.UserID) ([]*organization.Organization, error)
- func (s *Store) ListUserOrganizationsPage(ctx context.Context, userID id.UserID, opts page.Opts) (page.Page[*organization.Organization], error)
- func (s *Store) ListUserSessions(ctx context.Context, userID id.UserID) ([]*session.Session, error)
- func (s *Store) ListUserSessionsPage(ctx context.Context, userID id.UserID, opts page.Opts) (page.Page[*session.Session], error)
- func (s *Store) ListUsers(ctx context.Context, q *user.Query) (*user.List, error)
- func (s *Store) ListWebhooks(ctx context.Context, appID id.AppID) ([]*webhook.Webhook, error)
- func (s *Store) MarkRefreshTokenReplayed(ctx context.Context, tokenHash string) (bool, error)
- func (s *Store) MarkRefreshTokenRevoked(ctx context.Context, tokenHash string, familyID id.SessionFamilyID, ...) error
- func (s *Store) MarkSent(ctx context.Context, notifID id.NotificationID) error
- func (s *Store) MarkUserEmailVerified(ctx context.Context, userID id.UserID, email string) error
- func (s *Store) Migrate(ctx context.Context, extraGroups ...*migrate.Group) error
- func (s *Store) Ping(ctx context.Context) error
- func (s *Store) ResolveSettings(ctx context.Context, key string, opts settings.ResolveOpts) ([]*settings.Setting, error)
- func (s *Store) RevokeDelegation(ctx context.Context, delID id.DelegationID, at time.Time) error
- func (s *Store) RevokeRefreshTokenFamily(ctx context.Context, familyID id.SessionFamilyID, reason string) error
- func (s *Store) RotateSession(ctx context.Context, sess *session.Session, expectedTokenHash string) (bool, error)
- func (s *Store) SaveBranding(ctx context.Context, b *formconfig.BrandingConfig) error
- func (s *Store) SeedLegacyInvitation(ctx context.Context, inv *organization.Invitation) error
- func (s *Store) SeedLegacyPasswordReset(ctx context.Context, pr *account.PasswordReset) error
- func (s *Store) SeedLegacySession(ctx context.Context, sess *session.Session) error
- func (s *Store) SeedLegacyVerification(ctx context.Context, v *account.Verification) error
- func (s *Store) SetAppClientConfig(ctx context.Context, cfg *appclientconfig.Config) error
- func (s *Store) SetAppSessionConfig(ctx context.Context, cfg *appsessionconfig.Config) error
- func (s *Store) SetDefaultEnvironment(ctx context.Context, appID id.AppID, envID id.EnvironmentID) error
- func (s *Store) SetPrimaryEmail(ctx context.Context, userID id.UserID, email string) error
- func (s *Store) SetSetting(ctx context.Context, st *settings.Setting) error
- func (s *Store) TouchAPIKey(ctx context.Context, keyID id.APIKeyID, at time.Time) error
- func (s *Store) TouchSession(ctx context.Context, sessionID id.SessionID, ...) error
- func (s *Store) UpdateAPIKey(ctx context.Context, k *apikey.APIKey) error
- func (s *Store) UpdateApp(ctx context.Context, a *app.App) error
- func (s *Store) UpdateDevice(ctx context.Context, d *device.Device) error
- func (s *Store) UpdateEnvironment(ctx context.Context, e *environment.Environment) error
- func (s *Store) UpdateFormConfig(ctx context.Context, fc *formconfig.FormConfig) error
- func (s *Store) UpdateInvitation(ctx context.Context, inv *organization.Invitation) error
- func (s *Store) UpdateMember(ctx context.Context, mem *organization.Member) error
- func (s *Store) UpdateOrganization(ctx context.Context, o *organization.Organization) error
- func (s *Store) UpdateServiceAccount(ctx context.Context, svc *serviceaccount.ServiceAccount) error
- func (s *Store) UpdateSession(ctx context.Context, sess *session.Session) error
- func (s *Store) UpdateTeam(ctx context.Context, t *organization.Team) error
- func (s *Store) UpdateUser(ctx context.Context, u *user.User) error
- func (s *Store) UpdateVerification(ctx context.Context, v *account.Verification) error
- func (s *Store) UpdateWebhook(ctx context.Context, w *webhook.Webhook) error
- func (s *Store) WithTx(_ context.Context, fn func(tx organization.Store) error) error
Constants ¶
This section is empty.
Variables ¶
var Migrations = migrate.NewGroup("authsome")
Migrations is the grove migration group for the AuthSome mongo store.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store implements store.Store using MongoDB via Grove ORM.
func (*Store) AddUserEmail ¶
func (*Store) BatchResolve ¶
func (*Store) ConsumePasswordReset ¶
ConsumePasswordReset marks a password reset token as consumed.
func (*Store) ConsumeVerification ¶
ConsumeVerification marks a verification token as consumed.
func (*Store) CreateAPIKey ¶
CreateAPIKey persists a new API key.
func (*Store) CreateDelegation ¶
CreateDelegation stores a new grant, refusing one that would duplicate a grant already live for the same (app, actor, subject, kind).
The liveness check runs here rather than in the index. Live means principal.Delegation.IsActive: not revoked AND not past its expiry, and a partialFilterExpression has no way to name the current time, so the unique index (see delegation_live_index_excludes_expired) now covers only grants that never expire and this covers the rest.
Read-then-write, not atomic, so two concurrent creates for the same tuple can both land. That trade is deliberate: filtering on revoked_at alone meant an impersonation grant that merely lapsed blocked every later impersonation of that user by that admin forever, because nothing but StopImpersonation ever writes revoked_at.
func (*Store) CreateDevice ¶
CreateDevice persists a new device.
func (*Store) CreateEnvironment ¶
func (s *Store) CreateEnvironment(ctx context.Context, e *environment.Environment) error
CreateEnvironment persists a new environment.
func (*Store) CreateFormConfig ¶
func (s *Store) CreateFormConfig(ctx context.Context, fc *formconfig.FormConfig) error
func (*Store) CreateInvitation ¶
func (s *Store) CreateInvitation(ctx context.Context, inv *organization.Invitation) error
CreateInvitation persists a new invitation.
func (*Store) CreateMember ¶
CreateMember persists a new organization member.
func (*Store) CreateNotification ¶
func (s *Store) CreateNotification(ctx context.Context, n *notification.Notification) error
CreateNotification persists a new notification.
func (*Store) CreateOrganization ¶
func (s *Store) CreateOrganization(ctx context.Context, o *organization.Organization) error
CreateOrganization persists a new organization.
func (*Store) CreatePasswordReset ¶
CreatePasswordReset persists a new password reset token.
func (*Store) CreateServiceAccount ¶
func (s *Store) CreateServiceAccount(ctx context.Context, svc *serviceaccount.ServiceAccount) error
CreateServiceAccount persists a new service account.
func (*Store) CreateSession ¶
CreateSession persists a new session.
func (*Store) CreateTeam ¶
CreateTeam persists a new team.
func (*Store) CreateUser ¶
CreateUser persists a new user.
func (*Store) CreateUserWithPrimaryEmail ¶
func (*Store) CreateVerification ¶
CreateVerification persists a new verification token.
func (*Store) CreateWebhook ¶
CreateWebhook persists a new webhook.
func (*Store) DeleteAPIKey ¶
func (*Store) DeleteApp ¶
DeleteApp removes an app. DeleteApp removes an app and cascades to every app-scoped collection, so a deleted app leaves no orphaned users, sessions, org memberships, API keys, etc. behind (which the SQL backends achieve via ON DELETE CASCADE / explicit deletes). Runs inside a MongoTx for atomicity — this requires the deployment to run against a replica set or sharded cluster.
func (*Store) DeleteAppClientConfig ¶
DeleteAppClientConfig removes the per-app client config override.
func (*Store) DeleteAppSessionConfig ¶
DeleteAppSessionConfig removes the per-app session config override.
func (*Store) DeleteBranding ¶
func (*Store) DeleteDevice ¶
DeleteDevice removes a device.
func (*Store) DeleteEnvironment ¶
DeleteEnvironment removes an environment by ID. Returns an error if the environment is the default for its app.
func (*Store) DeleteExpiredPasswordResets ¶
func (s *Store) DeleteExpiredPasswordResets(ctx context.Context, before time.Time, batch int) (int64, error)
DeleteExpiredPasswordResets implements store.Retention.
func (*Store) DeleteExpiredRevokedRefreshTokens ¶
func (s *Store) DeleteExpiredRevokedRefreshTokens(ctx context.Context, before time.Time, batch int) (int64, error)
DeleteExpiredRevokedRefreshTokens implements store.Retention.
func (*Store) DeleteExpiredSessions ¶
func (s *Store) DeleteExpiredSessions(ctx context.Context, before time.Time, batch int) (int64, error)
DeleteExpiredSessions implements store.Retention.
func (*Store) DeleteExpiredVerifications ¶
func (s *Store) DeleteExpiredVerifications(ctx context.Context, before time.Time, batch int) (int64, error)
DeleteExpiredVerifications implements store.Retention.
func (*Store) DeleteFormConfig ¶
func (*Store) DeleteInvitation ¶
DeleteInvitation removes an invitation by ID.
func (*Store) DeleteMember ¶
DeleteMember removes a member.
func (*Store) DeleteOrganization ¶
DeleteOrganization removes an organization.
func (*Store) DeleteOrganizationCascade ¶
DeleteOrganizationCascade deletes the organization and all of its dependent rows (members, teams, invitations) inside a single MongoTx session. On any error the entire transaction is aborted; the orgs row is the last delete so a failure mid-cascade leaves the org row visible (callers can retry).
MongoDB transactions require a replica set (or sharded cluster). On a standalone mongod the StartTransaction call returns ErrUnsupportedDeployment — callers running against standalone instances should treat that as a configuration issue rather than a code defect.
func (*Store) DeleteServiceAccount ¶
DeleteServiceAccount removes a service account.
func (*Store) DeleteSession ¶
DeleteSession removes a session by ID.
func (*Store) DeleteSessionsByGrant ¶
DeleteSessionsByGrant removes every session issued under grantID. Revoking an agent's delegation must also kill the session it minted, or the session keeps authenticating as the delegating human until it separately expires.
func (*Store) DeleteSetting ¶
func (*Store) DeleteSettingsByNamespace ¶
func (*Store) DeleteTeam ¶
DeleteTeam removes a team.
func (*Store) DeleteUser ¶
DeleteUser soft-deletes a user by setting the deleted_at timestamp.
func (*Store) DeleteUserEmail ¶
func (*Store) DeleteUserSessions ¶
DeleteUserSessions removes all sessions for a user.
func (*Store) DeleteWebhook ¶
DeleteWebhook removes a webhook.
func (*Store) EnsureTTLIndexes ¶
EnsureTTLIndexes implements store.TTLIndexer. MongoDB's TTL monitor then removes rows as they pass their window, and the engine's sweeper only has to catch what the monitor has not reached yet.
func (*Store) FindActiveDelegation ¶
func (s *Store) FindActiveDelegation( ctx context.Context, appID id.AppID, actor, subject principal.Ref, grantKind principal.GrantKind, ) (*principal.Delegation, error)
FindActiveDelegation resolves the live grant letting actor act for subject.
Liveness is evaluated in the query rather than by loading and filtering in Go: this runs on the authentication path for every delegated request, and the partial unique index means at most one document can match.
func (*Store) FindByPrefix ¶
FindByPrefix returns an API key by prefix alone, ignoring app scoping. Used by the introspection endpoint where the caller doesn't know the appID.
func (*Store) GetAPIKeyByPrefix ¶
func (s *Store) GetAPIKeyByPrefix(ctx context.Context, appID id.AppID, prefix string) (*apikey.APIKey, error)
GetAPIKeyByPrefix returns an API key by app ID and key prefix.
func (*Store) GetAPIKeyByPublicKey ¶
func (s *Store) GetAPIKeyByPublicKey(ctx context.Context, appID id.AppID, publicKey string) (*apikey.APIKey, error)
GetAPIKeyByPublicKey returns an API key by app ID and public key.
func (*Store) GetActiveEmailVerification ¶
func (s *Store) GetActiveEmailVerification(ctx context.Context, userID id.UserID) (*account.Verification, error)
GetActiveEmailVerification returns the most recent unconsumed, unexpired email verification for a user (OTP lookup by user, not token).
func (*Store) GetAppByPublishableKey ¶
GetAppByPublishableKey returns an app by its publishable key.
func (*Store) GetAppBySlug ¶
GetAppBySlug returns an app by its slug.
func (*Store) GetAppClientConfig ¶
func (s *Store) GetAppClientConfig(ctx context.Context, appID id.AppID) (*appclientconfig.Config, error)
GetAppClientConfig returns the client config override for the given app.
func (*Store) GetAppSessionConfig ¶
func (s *Store) GetAppSessionConfig(ctx context.Context, appID id.AppID) (*appsessionconfig.Config, error)
GetAppSessionConfig returns the session config override for the given app.
func (*Store) GetBranding ¶
func (s *Store) GetBranding(ctx context.Context, orgID id.OrgID) (*formconfig.BrandingConfig, error)
func (*Store) GetDefaultEnvironment ¶
func (s *Store) GetDefaultEnvironment(ctx context.Context, appID id.AppID) (*environment.Environment, error)
GetDefaultEnvironment returns the default environment for an app.
func (*Store) GetDelegation ¶
func (s *Store) GetDelegation(ctx context.Context, delID id.DelegationID) (*principal.Delegation, error)
func (*Store) GetDeviceByFingerprint ¶
func (s *Store) GetDeviceByFingerprint(ctx context.Context, userID id.UserID, fingerprint string) (*device.Device, error)
GetDeviceByFingerprint returns a device by user ID and fingerprint.
func (*Store) GetEnvironment ¶
func (s *Store) GetEnvironment(ctx context.Context, envID id.EnvironmentID) (*environment.Environment, error)
GetEnvironment returns an environment by ID.
func (*Store) GetEnvironmentBySlug ¶
func (s *Store) GetEnvironmentBySlug(ctx context.Context, appID id.AppID, slug string) (*environment.Environment, error)
GetEnvironmentBySlug returns an environment by app ID and slug.
func (*Store) GetFormConfig ¶
func (s *Store) GetFormConfig(ctx context.Context, appID id.AppID, formType string) (*formconfig.FormConfig, error)
func (*Store) GetInvitation ¶
func (s *Store) GetInvitation(ctx context.Context, invID id.InvitationID) (*organization.Invitation, error)
GetInvitation returns an invitation by ID.
func (*Store) GetInvitationByToken ¶
func (s *Store) GetInvitationByToken(ctx context.Context, token string) (*organization.Invitation, error)
GetInvitationByToken returns an invitation by its token.
func (*Store) GetMemberByUserAndOrg ¶
func (s *Store) GetMemberByUserAndOrg(ctx context.Context, userID id.UserID, orgID id.OrgID) (*organization.Member, error)
GetMemberByUserAndOrg returns a member by user ID and org ID.
func (*Store) GetNotification ¶
func (s *Store) GetNotification(ctx context.Context, notifID id.NotificationID) (*notification.Notification, error)
GetNotification returns a notification by ID.
func (*Store) GetOrganization ¶
func (s *Store) GetOrganization(ctx context.Context, orgID id.OrgID) (*organization.Organization, error)
GetOrganization returns an organization by ID.
func (*Store) GetOrganizationBySlug ¶
func (s *Store) GetOrganizationBySlug(ctx context.Context, appID id.AppID, slug string) (*organization.Organization, error)
GetOrganizationBySlug returns an organization by app ID and slug.
func (*Store) GetPasswordReset ¶
GetPasswordReset returns a password reset by token.
func (*Store) GetPlatformApp ¶
GetPlatformApp returns the single platform app (is_platform=true).
func (*Store) GetPrincipal ¶
GetPrincipal resolves any principal by ref. A user ref is assembled from the users collection; every other kind comes from the service accounts one, looked up by id alone. The ref's Kind only routes which collection to read, matching how the memory and postgres backends resolve a principal.
func (*Store) GetRevokedRefreshTokenFamily ¶
func (s *Store) GetRevokedRefreshTokenFamily(ctx context.Context, tokenHash string) (id.SessionFamilyID, error)
GetRevokedRefreshTokenFamily returns the family bound to a revoked token, or store.ErrNotFound if the hash is unknown.
func (*Store) GetServiceAccount ¶
func (s *Store) GetServiceAccount(ctx context.Context, svcID id.ServiceAccountID) (*serviceaccount.ServiceAccount, error)
GetServiceAccount returns a service account by ID.
func (*Store) GetSession ¶
GetSession returns a session by ID.
func (*Store) GetSessionByRefreshToken ¶
func (s *Store) GetSessionByRefreshToken(ctx context.Context, refreshToken string) (*session.Session, error)
GetSessionByRefreshToken returns a session by its refresh token.
func (*Store) GetSessionByToken ¶
GetSessionByToken returns a session by its access token.
func (*Store) GetSetting ¶
func (*Store) GetUserByAnyEmail ¶
func (*Store) GetUserByEmail ¶
func (s *Store) GetUserByEmail(ctx context.Context, appID id.AppID, envID id.EnvironmentID, email string) (*user.User, error)
GetUserByEmail returns a user by app ID, environment and email, excluding soft-deleted users. A nil envID matches app-wide.
func (*Store) GetUserByPhone ¶
func (s *Store) GetUserByPhone(ctx context.Context, appID id.AppID, envID id.EnvironmentID, phone string) (*user.User, error)
GetUserByPhone returns a user by app ID, environment and phone number, excluding soft-deleted users. A nil envID matches app-wide.
func (*Store) GetUserByUsername ¶
func (s *Store) GetUserByUsername(ctx context.Context, appID id.AppID, envID id.EnvironmentID, username string) (*user.User, error)
GetUserByUsername returns a user by app ID, environment and username, excluding soft-deleted users. A nil envID matches app-wide.
func (*Store) GetUserEmailRecord ¶
func (*Store) GetUserEmails ¶
func (*Store) GetVerification ¶
GetVerification returns a verification by token.
func (*Store) GetWebhook ¶
GetWebhook returns a webhook by ID.
func (*Store) HashLegacyTokens ¶
HashLegacyTokens implements store.LegacyTokenHasher. Each collection is swept with a bounded find of documents whose hash is absent or empty and whose plaintext is present, then rewritten one by one. A document with neither plaintext nor hash is unusable and left alone.
func (*Store) IsRefreshTokenRevoked ¶
IsRefreshTokenRevoked reports whether tokenHash has been recorded as revoked.
func (*Store) KVDeleteExpired ¶
KVDeleteExpired implements store.KV.
func (*Store) KVIncrement ¶
KVIncrement implements store.KV.
func (*Store) KVSetNX ¶
func (s *Store) KVSetNX(ctx context.Context, key string, value []byte, ttl time.Duration) (bool, error)
KVSetNX implements store.KV.
func (*Store) ListAPIKeysByApp ¶
ListAPIKeysByApp returns all API keys for an app, ordered by creation date descending.
func (*Store) ListAPIKeysByUser ¶
func (s *Store) ListAPIKeysByUser(ctx context.Context, appID id.AppID, userID id.UserID) ([]*apikey.APIKey, error)
ListAPIKeysByUser returns all API keys for a user within an app, ordered by creation date descending.
func (*Store) ListDelegations ¶
func (s *Store) ListDelegations(ctx context.Context, q *principal.DelegationQuery) ([]*principal.Delegation, error)
func (*Store) ListDevices ¶
func (*Store) ListEnvironments ¶
func (s *Store) ListEnvironments(ctx context.Context, appID id.AppID) ([]*environment.Environment, error)
ListEnvironments returns all environments for an app, ordered by creation date ascending.
func (*Store) ListFormConfigs ¶
func (s *Store) ListFormConfigs(ctx context.Context, appID id.AppID) ([]*formconfig.FormConfig, error)
func (*Store) ListInvitations ¶
func (s *Store) ListInvitations(ctx context.Context, orgID id.OrgID) ([]*organization.Invitation, error)
ListInvitations returns all invitations for an organization, ordered by creation date descending.
func (*Store) ListInvitationsPage ¶
func (*Store) ListMembers ¶
ListMembers returns all members of an organization, ordered by creation date ascending.
func (*Store) ListMembersPage ¶
func (*Store) ListOrganizations ¶
func (s *Store) ListOrganizations(ctx context.Context, appID id.AppID) ([]*organization.Organization, error)
ListOrganizations returns all organizations for an app, ordered by creation date descending.
func (*Store) ListOrganizationsPage ¶
func (*Store) ListPrincipals ¶
func (s *Store) ListPrincipals(ctx context.Context, q *principal.Query) ([]*principal.Principal, error)
ListPrincipals returns principals matching q. Only non-human principals live in the service accounts collection, so this never returns users.
func (*Store) ListServiceAccounts ¶
func (s *Store) ListServiceAccounts(ctx context.Context, q *serviceaccount.Query) (*serviceaccount.List, error)
ListServiceAccounts returns service accounts matching the query.
func (*Store) ListSessions ¶
func (*Store) ListSettings ¶
func (*Store) ListTeams ¶
ListTeams returns all teams for an organization, ordered by name ascending.
func (*Store) ListTeamsPage ¶
func (*Store) ListUserDevices ¶
ListUserDevices returns all devices for a user, ordered by last seen descending.
func (*Store) ListUserNotifications ¶
func (s *Store) ListUserNotifications(ctx context.Context, userID id.UserID) ([]*notification.Notification, error)
ListUserNotifications returns all notifications for a user, ordered by creation date descending.
func (*Store) ListUserOrganizations ¶
func (s *Store) ListUserOrganizations(ctx context.Context, userID id.UserID) ([]*organization.Organization, error)
ListUserOrganizations returns all organizations a user belongs to.
func (*Store) ListUserOrganizationsPage ¶
func (*Store) ListUserSessions ¶
ListUserSessions returns all sessions for a user, ordered by creation date descending.
func (*Store) ListUserSessionsPage ¶
func (*Store) ListUsers ¶
ListUsers returns a paginated list of users for an app, with optional email search.
func (*Store) ListWebhooks ¶
ListWebhooks returns all webhooks for an app, ordered by creation date descending.
func (*Store) MarkRefreshTokenReplayed ¶
MarkRefreshTokenReplayed flips an already-revoked token's reason to "replay_detected", returning whether this call made the change. The filter excludes tokens already flagged, so a match is a real transition — the engine's once-per-family storm guard.
func (*Store) MarkRefreshTokenRevoked ¶
func (s *Store) MarkRefreshTokenRevoked(ctx context.Context, tokenHash string, familyID id.SessionFamilyID, reason string) error
MarkRefreshTokenRevoked records tokenHash as revoked. Idempotent: a duplicate-key error is swallowed (the original record wins).
func (*Store) MarkUserEmailVerified ¶
func (*Store) Migrate ¶
Migrate runs the mongo migration orchestrator (the authoritative path for index/schema changes — every entry in Migrations runs exactly once and is tracked) and then ensures baseline indexes exist for any collection that doesn't yet have them.
The two paths coexist deliberately:
- The orchestrator is the only path that can RESHAPE an existing index (drop + recreate with different options). Repair migrations like fix_username_index_partial_filter live here.
- The eager ensureBaselineIndexes path is the only path that runs when an operator boots with WithDisableMigrate() (used in tests and some custom-control deployments). It tolerates index-shape conflicts so a stale index from a prior deployment doesn't block boot — the migration system is expected to repair it.
extraGroups are concatenated after the mongo Migrations group so plugins can register their own migration groups via the standard MigrationProvider interface (mirrors the postgres + sqlite stores).
func (*Store) ResolveSettings ¶
func (*Store) RevokeDelegation ¶
RevokeDelegation marks a grant revoked. The revoked_at guard makes a repeat call a no-op rather than moving the timestamp, so a retried revocation cannot rewrite when the revocation actually happened.
func (*Store) RevokeRefreshTokenFamily ¶
func (s *Store) RevokeRefreshTokenFamily(ctx context.Context, familyID id.SessionFamilyID, reason string) error
RevokeRefreshTokenFamily revokes every active session sharing familyID, recording each refresh-token hash as revoked. Runs inside a MongoTx.
MongoDB transactions require a replica set or sharded cluster. On a standalone mongod this returns ErrUnsupportedDeployment.
func (*Store) RotateSession ¶
func (s *Store) RotateSession(ctx context.Context, sess *session.Session, expectedTokenHash string) (bool, error)
RotateSession atomically persists sess only if the stored access token hash still equals expectedTokenHash. Returns false when no document matched (a concurrent refresh already rotated the session), which prevents two concurrent refreshes from both winning.
func (*Store) SaveBranding ¶
func (s *Store) SaveBranding(ctx context.Context, b *formconfig.BrandingConfig) error
func (*Store) SeedLegacyInvitation ¶
func (s *Store) SeedLegacyInvitation(ctx context.Context, inv *organization.Invitation) error
func (*Store) SeedLegacyPasswordReset ¶
func (*Store) SeedLegacySession ¶
SeedLegacySession writes sess exactly as a release before token hashing did: plaintext tokens and no hashes. It exists so the conformance suite can prove the upgrade path and is refused outside `go test`.
func (*Store) SeedLegacyVerification ¶
SeedLegacyVerification, SeedLegacyPasswordReset and SeedLegacyInvitation write documents the way releases before token hashing did: plaintext and no hash. They exist for the conformance suite and are refused outside `go test`.
func (*Store) SetAppClientConfig ¶
SetAppClientConfig creates or updates the client config for an app.
func (*Store) SetAppSessionConfig ¶
SetAppSessionConfig creates or updates the session config for an app.
func (*Store) SetDefaultEnvironment ¶
func (s *Store) SetDefaultEnvironment(ctx context.Context, appID id.AppID, envID id.EnvironmentID) error
SetDefaultEnvironment sets the given environment as the default for its app, clearing the default flag on any previously default environment.
func (*Store) SetPrimaryEmail ¶
func (*Store) SetSetting ¶
func (*Store) TouchAPIKey ¶
DeleteAPIKey removes an API key. TouchAPIKey writes last_used_at alone.
func (*Store) TouchSession ¶
func (s *Store) TouchSession(ctx context.Context, sessionID id.SessionID, lastActivityAt, expiresAt time.Time) error
TouchSession performs a lightweight update of last_activity_at, expires_at, and updated_at.
func (*Store) UpdateAPIKey ¶
UpdateAPIKey modifies an existing API key.
func (*Store) UpdateDevice ¶
UpdateDevice modifies an existing device.
func (*Store) UpdateEnvironment ¶
func (s *Store) UpdateEnvironment(ctx context.Context, e *environment.Environment) error
UpdateEnvironment modifies an existing environment.
func (*Store) UpdateFormConfig ¶
func (s *Store) UpdateFormConfig(ctx context.Context, fc *formconfig.FormConfig) error
func (*Store) UpdateInvitation ¶
func (s *Store) UpdateInvitation(ctx context.Context, inv *organization.Invitation) error
UpdateInvitation modifies an existing invitation.
func (*Store) UpdateMember ¶
UpdateMember modifies an existing member.
func (*Store) UpdateOrganization ¶
func (s *Store) UpdateOrganization(ctx context.Context, o *organization.Organization) error
UpdateOrganization modifies an existing organization.
func (*Store) UpdateServiceAccount ¶
func (s *Store) UpdateServiceAccount(ctx context.Context, svc *serviceaccount.ServiceAccount) error
UpdateServiceAccount modifies an existing service account.
func (*Store) UpdateSession ¶
UpdateSession modifies an existing session.
func (*Store) UpdateTeam ¶
UpdateTeam modifies an existing team.
func (*Store) UpdateUser ¶
UpdateUser modifies an existing user.
func (*Store) UpdateVerification ¶
UpdateVerification persists mutable fields (attempts, consumed).
func (*Store) UpdateWebhook ¶
UpdateWebhook modifies an existing webhook.
func (*Store) WithTx ¶
WithTx is a best-effort no-op wrapper for now. Real backend transactions require plumbing driver.Tx through every Store method, which is a multi- day refactor deferred to a follow-up PR. Callers that need true atomic cascade semantics should use the dedicated DeleteOrganizationCascade method below — it uses MongoTx natively without requiring the full every-method-takes-a-tx refactor.
Source Files
¶
- account.go
- apikey.go
- app.go
- appclientconfig.go
- appsessionconfig.go
- delegations.go
- device.go
- email.go
- environment.go
- formconfig.go
- kv.go
- migrations.go
- models.go
- notification.go
- organization.go
- paged.go
- refresh_replay.go
- retention.go
- service_accounts.go
- session.go
- settings.go
- store.go
- tokens.go
- ttl.go
- user.go
- webhook.go
- webhook_migrations.go