Documentation
¶
Overview ¶
Package auth provides authentication primitives (JWT issuance, stateful repositories, HTTP helpers) plus lifecycle extension points for downstream admin workflows.
User lifecycle:
- Users carry a UserStatus field that is persisted via Bun. Statuses cover pending, active, suspended, disabled, and archived flows so every product can opt into the same invariants.
- UserStateMachine centralizes the transition graph, timestamp handling, hooks, and persistence. Embed the shared Users repository and invoke Transition with ActorRef metadata whenever an admin moves an account. Hook failures route through a configurable error handler so production services can translate panics into domain errors.
Activity sinks:
- ActivitySink is a light-weight audit emitter used by Auther and the state machine to describe lifecycle, login, impersonation, and password reset events. Sinks run best-effort (errors are logged) so you can forward to a database or queue without blocking authentication.
Claims decoration:
- ClaimsDecorator is invoked before JWTs are signed. Decorators may enrich extension fields such as resource roles or metadata while protected claims (sub, iss, aud, exp, etc.) remain immutable. Combine WithClaimsDecorator with ActivitySink to keep lifecycle state and issued tokens consistent.
Index ¶
- Constants
- Variables
- func Can(ctx context.Context, resource, permission string) bool
- func CanFromRouter(ctx router.Context, resource, permission string) bool
- func ClearTemporaryPasswordMetadata(metadata map[string]any) map[string]any
- func ComparePasswordAndHash(password, hash string) error
- func ContextEnricherAdapter(c context.Context, claims jwtware.AuthClaims) context.Context
- func CredentialModeGuard(cfg RouteCredentialConfig) (router.MiddlewareFunc, error)
- func DefaultPermissionsCacheKeyFromContext(ctx context.Context) (string, bool)
- func DeriveBrowserCSRFSecureKey(authCfg Config) []byte
- func EncodeProviderSessionReason(reason ProviderSessionReason) string
- func GetAuthExtrasMigrationsFS() fs.FS
- func GetCoreMigrationsFS() fs.FS
- func GetMigrationsFS() fs.FS
- func GetTemplateUser(ctx router.Context, userKey string) (any, bool)
- func HasTemporaryPasswordMetadata(metadata map[string]any) bool
- func HasUserUUID(session Session) bool
- func HashPassword(password string) (string, error)
- func IsMalformedError(err error) bool
- func IsOutsideThresholdPeriod(t time.Time, pattern string) (bool, error)
- func IsProviderLifecycleActivity(eventType ActivityEventType) bool
- func IsProviderSessionActivity(eventType ActivityEventType) bool
- func IsTokenExpiredError(err error) bool
- func IsWithinThresholdPeriod(t time.Time, pattern string) (bool, error)
- func MergeTemplateData(ctx router.Context, data router.ViewContext) router.ViewContext
- func MintScopedToken(tokenService TokenService, identity Identity, resourceRoles map[string]string, ...) (string, time.Time, error)
- func MustValidateResolverConfigured(strict bool, resolver PermissionResolverFunc)
- func NewPasswordResetsRepository(db *bun.DB) repository.Repository[*PasswordReset]
- func NewTemplateViews(views router.Views) router.Views
- func PermissionsVersionFromClaims(claims AuthClaims) string
- func PermissionsVersionFromContext(ctx context.Context) string
- func RandomPasswordHash() string
- func RegisterAuthRoutes[T any](app router.Router[T], opts ...AuthControllerOption)
- func RegisterSecureAuthRoutes[T any](app router.Router[T], cfg AuthRouteSecurityConfig, ...) error
- func RegisterValidationListeners(cfg *jwtware.Config, listeners ...ValidationListener)
- func RequireTokenUse(claims AuthClaims, expected string) error
- func ResolveLogger(name string, provider LoggerProvider, logger Logger) (LoggerProvider, Logger)
- func SetPermissionsVersionMetadata(claims *JWTClaims, version string)
- func TemplateHelpers() map[string]any
- func TemplateHelpersForPongo2V7() map[string]any
- func TemplateHelpersWithRouter(ctx router.Context, userKey string) map[string]any
- func TemplateHelpersWithUser(user *User) map[string]any
- func TokenIDFromContext(ctx context.Context) (string, bool)
- func ValidateResolverConfigured(strict bool, resolver PermissionResolverFunc) error
- func ValidateStringEquals(str string) validation.RuleFunc
- func WithActorContext(ctx context.Context, actor *ActorContext) context.Context
- func WithAssuranceContext(ctx context.Context, assurance AssuranceContext) context.Context
- func WithClaimsContext(r context.Context, claims AuthClaims) context.Context
- func WithContext(r context.Context, user *User) context.Context
- func WithCurrentPermissionsRequest(ctx context.Context, request CurrentPermissionsRequest) (context.Context, error)
- func WithProviderSessionContext(ctx context.Context, session ProviderSession, principal AuthenticatedPrincipal) context.Context
- func WithResolvedPermissionsCache(ctx context.Context) context.Context
- type AESGCMTokenCipher
- type AccountLifecycle
- type AccountLifecycleRequest
- type AccountRegistrerer
- type AccountState
- type AccountStateInvalidator
- type AccountStateObservation
- type AccountStateRequest
- type AccountStateResolution
- type AccountStateResolver
- type AccountStateResult
- type AccountStateScopeInvalidator
- type AccountStateSource
- type AccountStateSourceFunc
- type AccountVerificationHandler
- type AccountVerificationMesage
- type AccountVerificationResponse
- type ActivityEvent
- type ActivityEventType
- type ActivitySink
- type ActivitySinkFunc
- type ActorContext
- type ActorRef
- type AssuranceContext
- type AssuranceDecision
- type AssuranceGuard
- type AssuranceLevel
- type AssuranceReason
- type AssuranceRequirement
- type AssuranceResult
- type AtomicIndexedPermissionCacheStore
- type AtomicLoginAttemptRepository
- type AtomicLoginAttemptTracker
- type AuthClaims
- type AuthController
- func (a *AuthController) LogOut(ctx router.Context) error
- func (a *AuthController) LoginPost(ctx router.Context) error
- func (a *AuthController) LoginShow(ctx router.Context) error
- func (a *AuthController) PasswordResetExecute(ctx router.Context) error
- func (a *AuthController) PasswordResetForm(ctx router.Context) error
- func (a *AuthController) PasswordResetGet(ctx router.Context) error
- func (a *AuthController) PasswordResetPost(ctx router.Context) error
- func (a *AuthController) RegistrationCreate(ctx router.Context) error
- func (a *AuthController) RegistrationShow(ctx router.Context) error
- func (a *AuthController) WithLogger(l Logger) *AuthController
- type AuthControllerOption
- func WithAuthControllerActivitySink(sink ActivitySink) AuthControllerOption
- func WithAuthControllerRedirect(r string) AuthControllerOption
- func WithAuthControllerRoutes(r *AuthControllerRoutes) AuthControllerOption
- func WithAuthControllerUseHashID(v bool) AuthControllerOption
- func WithAuthControllerViews(v *AuthControllerViews) AuthControllerOption
- func WithControllerLogger(logger Logger) AuthControllerOption
- func WithControllerLoggerProvider(provider LoggerProvider) AuthControllerOption
- func WithErrorHandler(errHandler router.ErrorHandler) AuthControllerOption
- func WithFeatureGate(featureGate gate.FeatureGate) AuthControllerOption
- func WithPasswordResetDelivery(delivery PasswordResetDelivery) AuthControllerOption
- type AuthControllerRoutes
- type AuthControllerViews
- type AuthCookieOption
- type AuthRouteSecurityConfig
- type AuthenticatedPrincipal
- func (p AuthenticatedPrincipal) ApplicationSubject() string
- func (p AuthenticatedPrincipal) AssuranceLevel() string
- func (p AuthenticatedPrincipal) AssuranceMethods() []string
- func (p AuthenticatedPrincipal) AuthenticationAt() time.Time
- func (p AuthenticatedPrincipal) BindLocalSessionID(localSessionID string) (AuthenticatedPrincipal, error)
- func (p AuthenticatedPrincipal) ClientID() string
- func (p AuthenticatedPrincipal) Clone() AuthenticatedPrincipal
- func (p AuthenticatedPrincipal) ExpiresAt() time.Time
- func (p AuthenticatedPrincipal) IssuedAt() time.Time
- func (p AuthenticatedPrincipal) LocalSessionID() string
- func (p AuthenticatedPrincipal) Metadata() map[string]string
- func (p AuthenticatedPrincipal) OrganizationID() string
- func (p AuthenticatedPrincipal) PermissionVersion() string
- func (p AuthenticatedPrincipal) Provider() string
- func (p AuthenticatedPrincipal) ProviderSessionID() string
- func (p AuthenticatedPrincipal) ProviderSubject() string
- func (p AuthenticatedPrincipal) TenantID() string
- func (p AuthenticatedPrincipal) TokenID() string
- type AuthenticatedPrincipalInput
- type Authenticator
- type Auther
- func (s *Auther) IdentityFromSession(ctx context.Context, session Session) (Identity, error)
- func (s *Auther) Impersonate(ctx context.Context, identifier string) (string, error)
- func (s *Auther) Login(ctx context.Context, identifier, password string) (string, error)
- func (a *Auther) NewWSAuthMiddleware(config ...router.WSAuthConfig) router.WebSocketMiddleware
- func (s Auther) SessionFromToken(raw string) (Session, error)
- func (s Auther) SessionFromTokenContext(ctx context.Context, raw string) (Session, error)
- func (s *Auther) TokenService() TokenService
- func (s *Auther) WithActivitySink(sink ActivitySink) *Auther
- func (s *Auther) WithClaimsDecorator(decorator ClaimsDecorator) *Auther
- func (s *Auther) WithLogger(logger Logger) *Auther
- func (s *Auther) WithLoggerProvider(provider LoggerProvider) *Auther
- func (s *Auther) WithResourceRoleProvider(provider ResourceRoleProvider) *Auther
- func (s *Auther) WithTokenSizeGuardrails(warnThresholdBytes, hardLimitBytes int) *Auther
- func (s *Auther) WithTokenValidator(validator TokenValidator) *Auther
- type AuthorizationContinuation
- type AuthorizationDecisionRequest
- type AuthorizationDecisionResult
- func (r AuthorizationDecisionResult) Format(state fmt.State, _ rune)
- func (r AuthorizationDecisionResult) GoString() string
- func (r AuthorizationDecisionResult) HTTPRedirectURL() string
- func (r AuthorizationDecisionResult) LogValue() slog.Value
- func (r AuthorizationDecisionResult) MarshalJSON() ([]byte, error)
- func (r AuthorizationDecisionResult) String() string
- func (r AuthorizationDecisionResult) ValidateRedirect(allow func(*url.URL) bool) error
- type AuthorizationDecisionService
- type AuthorizationDetails
- type AuthorizationDetailsRequest
- type AuthorizationFreshnessGuard
- type AuthorizationFreshnessGuardConfig
- type AuthorizationFreshnessRequest
- type AuthorizationFreshnessResult
- type AuthorizationMutation
- type AuthorizationVersionEvent
- type AuthorizationVersionPublisher
- type AuthorizationVersionPublisherFunc
- type AuthorizationVersionStore
- type AuthorizationVersionWriteResult
- type AuthorizationVersionWriter
- type AuthorizedOperationContext
- type BrowserProtectionConfig
- type CachedPermissionsResolver
- func (r *CachedPermissionsResolver) Invalidate(ctx context.Context, key string) error
- func (r *CachedPermissionsResolver) InvalidateScope(ctx context.Context, scope PermissionInvalidationScope, limit int) (deleted int, more bool, err error)
- func (r *CachedPermissionsResolver) PurgeExpired(ctx context.Context) (int, error)
- func (r *CachedPermissionsResolver) ResolvePermissions(ctx context.Context) ([]string, error)
- func (r *CachedPermissionsResolver) ResolverFunc() PermissionResolverFunc
- func (r *CachedPermissionsResolver) Stats() PermissionResolverStats
- func (r *CachedPermissionsResolver) Store() PermissionCacheStore
- type CachedPermissionsResolverConfig
- type ClaimsDecorator
- type ClaimsDecoratorFunc
- type CompositeAccountStateResolver
- func (r *CompositeAccountStateResolver) InvalidateAccountState(_ context.Context, applicationSubject, tenantID string) error
- func (r *CompositeAccountStateResolver) InvalidateAccountStates(_ context.Context, scope PermissionInvalidationScope, limit int) (int, bool, error)
- func (r *CompositeAccountStateResolver) ResolveCurrentAccountState(ctx context.Context, request AccountStateRequest) (AccountStateResolution, error)
- type CompositeAccountStateResolverConfig
- type Config
- type CoordinatedProviderOperationExecutor
- type CoordinatedProviderOperationExecutorFunc
- type CurrentPermissionsRequest
- type EmergencyAccessDecision
- type EmergencyAccessGrant
- type EmergencyAccessGrantResolver
- type EmergencyAccessGrantResolverFunc
- type EmergencyAccessPolicy
- func (p *EmergencyAccessPolicy) Authorize(ctx context.Context, grant EmergencyAccessGrant, ...) (EmergencyAccessResult, error)deprecated
- func (p *EmergencyAccessPolicy) AuthorizeGrant(ctx context.Context, grantID, operation string, presentedProof Secret) (EmergencyAccessResult, error)
- func (p *EmergencyAccessPolicy) Revoke(ctx context.Context, grantID, actorID, reason string) errordeprecated
- func (p *EmergencyAccessPolicy) RevokeIssuedGrant(ctx context.Context, grantID, grantVersion, actorID, reason string) error
- type EmergencyAccessPolicyConfig
- type EmergencyAccessReason
- type EmergencyAccessResult
- type EmergencyAccessRevocationResolver
- type EmergencyAccessRevocationResolverFunc
- type EmergencyAccessRevoker
- type EmergencyAccessRevokerFunc
- type EmergencyCredentialVerification
- type EmergencyCredentialVerifier
- type EmergencyCredentialVerifierFunc
- type FactorLifecycle
- type FactorListRequest
- type FactorRemoveRequest
- type FieldsLogger
- type FinalizePasswordResetHandler
- func (h *FinalizePasswordResetHandler) Execute(ctx context.Context, event FinalizePasswordResetMesasge) error
- func (h *FinalizePasswordResetHandler) WithActivitySink(sink ActivitySink) *FinalizePasswordResetHandler
- func (h *FinalizePasswordResetHandler) WithFeatureGate(featureGate gate.FeatureGate) *FinalizePasswordResetHandler
- func (h *FinalizePasswordResetHandler) WithLogger(logger Logger) *FinalizePasswordResetHandler
- func (h *FinalizePasswordResetHandler) WithLoggerProvider(provider LoggerProvider) *FinalizePasswordResetHandler
- type FinalizePasswordResetMesasge
- type FormattedLogger
- type FreshnessDecision
- type FreshnessInvalidationCoordinator
- func (c *FreshnessInvalidationCoordinator) ConsumeAuthorizationVersion(ctx context.Context, event AuthorizationVersionEvent, revokeSessions bool) (FreshnessInvalidationResult, error)
- func (c *FreshnessInvalidationCoordinator) ConsumeLifecycleResult(ctx context.Context, request LifecycleFreshnessRequest) (FreshnessInvalidationResult, error)
- func (c *FreshnessInvalidationCoordinator) InvalidateLifecycleFreshness(ctx context.Context, request LifecycleFreshnessRequest) error
- type FreshnessInvalidationCoordinatorConfig
- type FreshnessInvalidationResult
- type FreshnessOperationPolicy
- type FreshnessPolicy
- type FreshnessPolicyConfig
- type FreshnessReason
- type HTTPAuthenticator
- type HTTPAuthenticatorOption
- type HookErrorHandler
- type IdentifierStore
- type Identity
- type IdentityLifecycle
- type IdentityProvider
- type ImmutableIdentifierStore
- type InMemoryAuthorizationVersionStore
- func (s *InMemoryAuthorizationVersionStore) AdvanceAuthorizationVersion(ctx context.Context, applicationSubject, tenantID, operationID string, ...) (PermissionVersionResult, error)
- func (s *InMemoryAuthorizationVersionStore) CurrentAuthorizationVersion(_ context.Context, applicationSubject, tenantID string) (PermissionVersionResult, error)
- type InMemoryLifecycleOperationStore
- func (s *InMemoryLifecycleOperationStore) Advance(_ context.Context, expectedRevision int64, next LifecycleOperationRecord) (LifecycleOperationRecord, error)
- func (s *InMemoryLifecycleOperationStore) Claim(_ context.Context, claim LifecycleOperationClaim) (LifecycleOperationRecord, LifecycleOperationClaimDisposition, error)
- func (s *InMemoryLifecycleOperationStore) ClaimPending(_ context.Context, policy LifecycleOperationPendingPolicy) ([]LifecycleOperationRecord, error)
- func (s *InMemoryLifecycleOperationStore) Durable() bool
- func (s *InMemoryLifecycleOperationStore) Load(_ context.Context, operationID string) (LifecycleOperationRecord, error)
- type InMemoryPermissionCacheStore
- func (s *InMemoryPermissionCacheStore) Delete(_ context.Context, key string) error
- func (s *InMemoryPermissionCacheStore) DeletePermissionCacheScope(_ context.Context, scope PermissionInvalidationScope, limit int) (int, bool, error)
- func (s *InMemoryPermissionCacheStore) Get(_ context.Context, key string) ([]string, bool, error)
- func (s *InMemoryPermissionCacheStore) IndexPermissionCacheKey(_ context.Context, key string, scope PermissionInvalidationScope) error
- func (s *InMemoryPermissionCacheStore) PurgeExpired(_ context.Context) (int, error)
- func (s *InMemoryPermissionCacheStore) Set(_ context.Context, key string, permissions []string, ttl time.Duration) error
- func (s *InMemoryPermissionCacheStore) SetPermissionCacheEntry(_ context.Context, key string, permissions []string, ttl time.Duration, ...) error
- type InMemoryPermissionCacheStoreConfig
- type IndexedPermissionCacheStore
- type InitializePasswordResetHandler
- func (h *InitializePasswordResetHandler) Execute(ctx context.Context, event InitializePasswordResetMessage) error
- func (h *InitializePasswordResetHandler) WithDelivery(delivery PasswordResetDelivery) *InitializePasswordResetHandler
- func (h *InitializePasswordResetHandler) WithFeatureGate(featureGate gate.FeatureGate) *InitializePasswordResetHandler
- func (h *InitializePasswordResetHandler) WithLogger(logger Logger) *InitializePasswordResetHandler
- func (h *InitializePasswordResetHandler) WithLoggerProvider(provider LoggerProvider) *InitializePasswordResetHandler
- type InitializePasswordResetMessage
- type InitializePasswordResetResponse
- type InviteRequest
- type IssuedEmergencyAccessGrant
- type JWTClaims
- func (c *JWTClaims) CanCreate(resource string) bool
- func (c *JWTClaims) CanDelete(resource string) bool
- func (c *JWTClaims) CanEdit(resource string) bool
- func (c *JWTClaims) CanRead(resource string) bool
- func (c *JWTClaims) ClaimsMetadata() map[string]any
- func (c *JWTClaims) Expires() time.Time
- func (c *JWTClaims) HasRole(role string) bool
- func (c *JWTClaims) IsAtLeast(minRole string) bool
- func (c *JWTClaims) IssuedAt() time.Time
- func (c *JWTClaims) ResourceRoles() map[string]string
- func (c *JWTClaims) Role() string
- func (c *JWTClaims) Subject() string
- func (c *JWTClaims) TokenID() string
- func (c *JWTClaims) TokenUse() string
- func (c *JWTClaims) UserID() string
- type LegacyLogger
- type LifecycleActionPolicy
- type LifecycleCoordinationRequest
- type LifecycleCoordinationResult
- type LifecycleCoordinator
- func (c *LifecycleCoordinator) Coordinate(ctx context.Context, request LifecycleCoordinationRequest) (LifecycleCoordinationResult, error)
- func (c *LifecycleCoordinator) ReconcileLifecycleOperation(ctx context.Context, reconciliation LifecycleOperationReconciliation) (LifecycleCoordinationResult, error)
- type LifecycleCoordinatorConfig
- type LifecycleExecutionPermit
- func (p LifecycleExecutionPermit) Consume(ctx context.Context, operation AuthorizedOperationContext) error
- func (p LifecycleExecutionPermit) ConsumeForHardenedMutation(ctx context.Context, operation AuthorizedOperationContext) error
- func (p LifecycleExecutionPermit) IdempotencyKey() string
- func (p LifecycleExecutionPermit) Validate(operation AuthorizedOperationContext) error
- type LifecycleFreshnessInvalidator
- type LifecycleFreshnessInvalidatorFunc
- type LifecycleFreshnessRequest
- type LifecycleOperationClaim
- type LifecycleOperationClaimDisposition
- type LifecycleOperationPendingPolicy
- type LifecycleOperationPhase
- type LifecycleOperationReconciliation
- type LifecycleOperationRecord
- type LifecycleOperationStore
- type Logger
- type LoggerProvider
- type LoginAttemptPolicy
- type LoginAttemptReservation
- type LoginPayload
- type LoginRequest
- type Middleware
- type MultiTokenValidator
- type NamedAccountStateSource
- type OperationRisk
- type PasswordAuthenticator
- type PasswordReset
- type PasswordResetDelivery
- type PasswordResetDeliveryFunc
- type PasswordResetDeliveryRequest
- type PasswordResetRequestPayload
- type PasswordResetStep
- type PasswordResetVerifyPayload
- type PermissionCacheErrorMode
- type PermissionCacheKeyFunc
- type PermissionCacheStore
- type PermissionInvalidationScope
- type PermissionResolverFunc
- type PermissionResolverStats
- type PermissionScopeInvalidator
- type PermissionVersionResolver
- type PermissionVersionResolverFunc
- type PermissionVersionResult
- type PrincipalSnapshot
- type ProviderAccountState
- type ProviderAuditFingerprint
- type ProviderDeliveryOutcome
- type ProviderDeliveryStatus
- type ProviderFactor
- type ProviderFactorState
- type ProviderFactorType
- type ProviderFactorsResult
- type ProviderOperationAction
- type ProviderOperationAuthorizationRequest
- type ProviderOperationAuthorizer
- type ProviderOperationExecutor
- type ProviderOperationExecutorFunc
- type ProviderOperationFingerprintContributor
- type ProviderOperationFingerprintField
- type ProviderOperationOutcome
- type ProviderOperationStatus
- type ProviderOperationTarget
- type ProviderProfileSyncRepository
- type ProviderRefreshClaim
- type ProviderRefreshCommit
- type ProviderRefreshReconcileRequest
- type ProviderRefreshReconcileResult
- type ProviderRefreshReconcileStatus
- type ProviderRefreshRequest
- type ProviderRefreshResult
- type ProviderRemoteRevocationClaim
- type ProviderRemoteRevocationClaimPolicy
- type ProviderRemoteRevocationCompletion
- type ProviderRemoteRevocationOutcome
- type ProviderRemoteRevocationRepository
- type ProviderRemoteRevocationRetryResult
- type ProviderRemoteRevocationStatus
- type ProviderRevocationHook
- type ProviderRevocationRequest
- type ProviderSession
- type ProviderSessionActivityMetadata
- type ProviderSessionBinding
- type ProviderSessionCleanupPolicy
- type ProviderSessionCleanupResult
- type ProviderSessionContext
- type ProviderSessionCreate
- type ProviderSessionCreation
- type ProviderSessionCreator
- type ProviderSessionDeployment
- type ProviderSessionEffect
- type ProviderSessionHTTP
- func (h *ProviderSessionHTTP) ClearCookie(c router.Context)
- func (h *ProviderSessionHTTP) Middleware() router.MiddlewareFunc
- func (h *ProviderSessionHTTP) RotateCookie(c router.Context, manager *ProviderSessionManager) error
- func (h *ProviderSessionHTTP) SetCookie(c router.Context, handle Secret) error
- type ProviderSessionHTTPConfig
- type ProviderSessionInvalidationScope
- type ProviderSessionLifecycleFence
- type ProviderSessionLifecycleInvalidator
- type ProviderSessionLifecycleOrdering
- type ProviderSessionLifecycleRepository
- type ProviderSessionLifecycleState
- type ProviderSessionLifecycleTransition
- type ProviderSessionLocalInvalidator
- type ProviderSessionManager
- func (m *ProviderSessionManager) AccessToken(ctx context.Context, request UserTokenRequest) (Secret, error)
- func (m *ProviderSessionManager) ApplyProviderSessionLifecycle(ctx context.Context, transition ProviderSessionLifecycleTransition) (ProviderSessionLifecycleFence, []ProviderSession, error)
- func (m *ProviderSessionManager) CreateProviderSession(ctx context.Context, principal AuthenticatedPrincipal, tokens ProviderTokenSet) (ProviderSessionCreation, error)
- func (m *ProviderSessionManager) InvalidateProviderSession(ctx context.Context, sessionID, reason string) error
- func (m *ProviderSessionManager) InvalidateProviderSessions(ctx context.Context, scope ProviderSessionInvalidationScope, limit int, ...) (int, bool, error)
- func (m *ProviderSessionManager) InvalidateUserProviderSessions(ctx context.Context, applicationSubject, reason string) error
- func (m *ProviderSessionManager) ReencryptProviderSession(ctx context.Context, handle Secret, binding ProviderSessionBinding) (ProviderSession, error)
- func (m *ProviderSessionManager) RefreshProviderSession(ctx context.Context, handle Secret, binding ProviderSessionBinding) (ProviderSession, error)
- func (m *ProviderSessionManager) ResolveProviderSession(ctx context.Context, handle Secret, binding ProviderSessionBinding) (ProviderSession, AuthenticatedPrincipal, error)
- func (m *ProviderSessionManager) RetryRemoteRevocations(ctx context.Context, policy ProviderRemoteRevocationClaimPolicy) (ProviderRemoteRevocationRetryResult, error)
- func (m *ProviderSessionManager) RevokeCurrentProviderSession(ctx context.Context, handle Secret, binding ProviderSessionBinding, ...) error
- func (m *ProviderSessionManager) RevokeProviderSession(ctx context.Context, sessionID, reason string) error
- func (m *ProviderSessionManager) RevokeUserProviderSessions(ctx context.Context, applicationSubject, reason string) error
- func (m *ProviderSessionManager) RotateProviderSessionHandle(ctx context.Context, handle Secret, binding ProviderSessionBinding) (Secret, ProviderSession, error)
- type ProviderSessionManagerConfig
- type ProviderSessionOperationsConfig
- type ProviderSessionReason
- type ProviderSessionReasonCode
- type ProviderSessionRepository
- type ProviderSessionResolution
- type ProviderSessionResolver
- type ProviderSessionRevoker
- type ProviderSessionScopeInvalidator
- type ProviderSessionScopeRepository
- type ProviderSessionStatus
- type ProviderSessionStore
- type ProviderTokenReconciler
- type ProviderTokenRefresher
- type ProviderTokenSet
- func (s ProviderTokenSet) AccessContext() (ValidatedTokenContext, bool)
- func (s ProviderTokenSet) AccessExpiresAt() time.Time
- func (s ProviderTokenSet) AccessToken() Secret
- func (s ProviderTokenSet) AcquiredAt() time.Time
- func (s ProviderTokenSet) Format(state fmt.State, _ rune)
- func (s ProviderTokenSet) GoString() string
- func (s ProviderTokenSet) IDContext() (ValidatedTokenContext, bool)
- func (s ProviderTokenSet) IDExpiresAt() time.Time
- func (s ProviderTokenSet) IDToken() Secret
- func (s ProviderTokenSet) LogValue() slog.Value
- func (s ProviderTokenSet) MarshalJSON() ([]byte, error)
- func (s ProviderTokenSet) MarshalText() ([]byte, error)
- func (s ProviderTokenSet) Metadata() map[string]string
- func (s ProviderTokenSet) RefreshExpiresAt() time.Time
- func (s ProviderTokenSet) RefreshToken() Secret
- func (s ProviderTokenSet) Scopes() []string
- func (s ProviderTokenSet) String() string
- func (s ProviderTokenSet) TokenType() string
- type ProviderTokenSetInput
- type ProviderTokenVault
- type ProviderUserSession
- type PurgeablePermissionCacheStore
- type RecoveryRequest
- type RegisterUserHandler
- type RegisterUserMessage
- type RegistrationCreatePayload
- type RepositoryManager
- type ResourceRoleProvider
- type RoleCapableSession
- type RoleFreshnessPolicy
- type RoleValidator
- type RouteAuthenticationMode
- type RouteAuthenticator
- func (a *RouteAuthenticator) AuthCookieName() string
- func (a RouteAuthenticator) GetCookieDuration() time.Duration
- func (a RouteAuthenticator) GetExtendedCookieDuration() time.Duration
- func (a *RouteAuthenticator) GetRedirect(ctx router.Context, def ...string) string
- func (a *RouteAuthenticator) GetRedirectOrDefault(ctx router.Context) string
- func (a *RouteAuthenticator) Impersonate(c router.Context, identifier string) error
- func (a *RouteAuthenticator) Login(ctx router.Context, payload LoginPayload) error
- func (a *RouteAuthenticator) Logout(ctx router.Context)
- func (a *RouteAuthenticator) MakeClientRouteAuthErrorHandler(optional bool) func(router.Context, error) error
- func (a *RouteAuthenticator) ProtectedBrowserRoute(cfg Config, errorHandler func(router.Context, error) error, ...) router.MiddlewareFunc
- func (a *RouteAuthenticator) ProtectedRoute(cfg Config, errorHandler func(router.Context, error) error) router.MiddlewareFunc
- func (a *RouteAuthenticator) SetAuthCookie(ctx router.Context, token string, opts ...AuthCookieOption) error
- func (a *RouteAuthenticator) SetRedirect(ctx router.Context)
- func (a *RouteAuthenticator) WithLogger(l Logger) *RouteAuthenticator
- func (a *RouteAuthenticator) WithLoggerProvider(provider LoggerProvider) *RouteAuthenticator
- func (a *RouteAuthenticator) WithValidationListeners(listeners ...ValidationListener) *RouteAuthenticator
- type RouteCredentialConfig
- type ScopedTokenOptions
- type Secret
- func (s Secret) Format(state fmt.State, _ rune)
- func (s Secret) GoString() string
- func (s Secret) IsZero() bool
- func (s Secret) LogValue() slog.Value
- func (s Secret) MarshalJSON() ([]byte, error)
- func (s Secret) MarshalText() ([]byte, error)
- func (s Secret) Reveal() string
- func (s Secret) String() string
- func (s *Secret) UnmarshalText([]byte) error
- type Session
- type SessionObject
- func (s *SessionObject) CanCreate(resource string) bool
- func (s *SessionObject) CanDelete(resource string) bool
- func (s *SessionObject) CanEdit(resource string) bool
- func (s *SessionObject) CanRead(resource string) bool
- func (s *SessionObject) GetAudience() []string
- func (s *SessionObject) GetData() map[string]any
- func (s *SessionObject) GetIssuedAt() *time.Time
- func (s *SessionObject) GetIssuer() string
- func (s *SessionObject) GetUserID() string
- func (s *SessionObject) GetUserUUID() (uuid.UUID, error)
- func (s *SessionObject) HasRole(role string) bool
- func (s *SessionObject) IsAtLeast(minRole UserRole) bool
- func (s SessionObject) String() string
- type StateMachineOption
- func WithStateMachineActivitySink(sink ActivitySink) StateMachineOption
- func WithStateMachineClock(clock func() time.Time) StateMachineOption
- func WithStateMachineHookErrorHandler(handler HookErrorHandler) StateMachineOption
- func WithStateMachineLogger(logger Logger) StateMachineOption
- func WithStateMachineLoggerProvider(provider LoggerProvider) StateMachineOption
- type StateStoreMaintenance
- type StaticTokenKeyProvider
- func (p *StaticTokenKeyProvider) ActiveKey(context.Context) (TokenEncryptionKey, error)
- func (p *StaticTokenKeyProvider) Key(_ context.Context, keyID string) (TokenEncryptionKey, error)
- func (p *StaticTokenKeyProvider) Retire(keyID string) error
- func (p *StaticTokenKeyProvider) Rotate(active TokenEncryptionKey) error
- type StatusAwareIdentity
- type StatusUpdateOption
- type StorePermissionVersionResolver
- type TemporaryPasswordResetRepository
- type TemporaryPasswordState
- type TokenAccessPolicy
- type TokenAccessPolicyRequest
- type TokenCipher
- type TokenEncryptionKey
- func (k TokenEncryptionKey) Format(state fmt.State, _ rune)
- func (k TokenEncryptionKey) GoString() string
- func (k TokenEncryptionKey) ID() string
- func (k TokenEncryptionKey) LogValue() slog.Value
- func (k TokenEncryptionKey) MarshalJSON() ([]byte, error)
- func (k TokenEncryptionKey) Material() []byte
- func (k TokenEncryptionKey) Retired() bool
- func (k TokenEncryptionKey) String() string
- type TokenEnvelope
- type TokenIDer
- type TokenKeyProvider
- type TokenService
- type TokenServiceAdapter
- type TokenServiceImpl
- func (ts *TokenServiceImpl) Generate(identity Identity, resourceRoles map[string]string) (string, error)
- func (ts *TokenServiceImpl) SignClaims(claims *JWTClaims) (string, error)
- func (ts *TokenServiceImpl) SignClaimsWithType(claims *JWTClaims, tokenType string) (string, error)
- func (ts *TokenServiceImpl) Stats() TokenServiceStats
- func (ts *TokenServiceImpl) Validate(tokenString string) (AuthClaims, error)
- func (ts *TokenServiceImpl) ValidateSession(tokenString string) (AuthClaims, error)
- type TokenServiceOption
- type TokenServiceStats
- type TokenTarget
- type TokenTargetCapability
- type TokenTargetRegistry
- type TokenUseClaimer
- type TokenValidator
- type TokenValidatorFunc
- type TransactionalIdentifierStore
- type TransactionalIdentifierSyncStore
- type TransitionContext
- type TransitionHook
- type TransitionHookPhase
- type TransitionMetadata
- type TransitionOption
- func WithAfterTransitionHook(h TransitionHook) TransitionOption
- func WithBeforeTransitionHook(h TransitionHook) TransitionOption
- func WithForceTransition() TransitionOption
- func WithSuspensionTime(t time.Time) TransitionOption
- func WithTransitionMetadata(metadata map[string]any) TransitionOption
- func WithTransitionReason(reason string) TransitionOption
- type User
- func (u *User) AddMetadata(key string, val any) *User
- func (u *User) EnsureStatus() *User
- func (u *User) HasStatus(status UserStatus) bool
- func (u *User) IsActive() bool
- func (u *User) IsArchived() bool
- func (u *User) IsDisabled() bool
- func (u *User) IsPending() bool
- func (u *User) IsSuspended() bool
- type UserIdentity
- type UserProvider
- func (u UserProvider) FindIdentityByIdentifier(ctx context.Context, identfier string) (Identity, error)
- func (u UserProvider) VerifyIdentity(ctx context.Context, identifier, password string) (Identity, error)
- func (u *UserProvider) WithLogger(l Logger) *UserProvider
- func (u *UserProvider) WithLoggerProvider(provider LoggerProvider) *UserProvider
- func (u *UserProvider) WithLoginAttemptPolicy(policy LoginAttemptPolicy) *UserProvider
- type UserRole
- type UserStateMachine
- type UserStatus
- type UserTokenProvider
- type UserTokenRequest
- type UserTracker
- type Users
- type UsersOption
- type ValidatedTokenContext
- type ValidationListener
- type WSAuthClaimsAdapter
- func (w *WSAuthClaimsAdapter) CanCreate(resource string) bool
- func (w *WSAuthClaimsAdapter) CanDelete(resource string) bool
- func (w *WSAuthClaimsAdapter) CanEdit(resource string) bool
- func (w *WSAuthClaimsAdapter) CanRead(resource string) bool
- func (w *WSAuthClaimsAdapter) HasRole(role string) bool
- func (w *WSAuthClaimsAdapter) IsAtLeast(minRole string) bool
- func (w *WSAuthClaimsAdapter) Role() string
- func (w *WSAuthClaimsAdapter) Subject() string
- func (w *WSAuthClaimsAdapter) UserID() string
- type WSTokenValidator
Constants ¶
const ( TextCodeIdentityProviderRequired = "IDENTITY_PROVIDER_REQUIRED" TextCodeInvalidCreds = "INVALID_CREDENTIALS" // #nosec G101 -- Error text code, not a credential. TextCodeTooManyAttempts = "TOO_MANY_ATTEMPTS" TextCodeSessionNotFound = "SESSION_NOT_FOUND" TextCodeSessionDecodeError = "SESSION_DECODE_ERROR" TextCodeClaimsMappingError = "CLAIMS_MAPPING_ERROR" TextCodeDataParseError = "DATA_PARSE_ERROR" TextCodeEmptyPassword = "EMPTY_PASSWORD_NOT_ALLOWED" TextCodeTokenExpired = "TOKEN_EXPIRED" TextCodeTokenMalformed = "TOKEN_MALFORMED" // #nosec G101 -- Error text code, not a credential. TextCodeTokenTooLarge = "TOKEN_TOO_LARGE" TextCodeImmutableClaim = "IMMUTABLE_CLAIM_MUTATION" TextCodeAccountSuspended = "ACCOUNT_SUSPENDED" TextCodeAccountDisabled = "ACCOUNT_DISABLED" TextCodeAccountArchived = "ACCOUNT_ARCHIVED" TextCodeAccountPending = "ACCOUNT_PENDING" TextCodeSignupDisabled = "SIGNUP_DISABLED" TextCodePasswordResetDisabled = "PASSWORD_RESET_DISABLED" TextCodePermissionResolverRequired = "PERMISSION_RESOLVER_REQUIRED" TextCodeTemporaryPasswordExpired = "TEMPORARY_PASSWORD_EXPIRED" TextCodeIdentifierConflict = "IDENTIFIER_CONFLICT" TextCodeAssuranceMissing = "ASSURANCE_MISSING" TextCodeAssuranceUnknown = "ASSURANCE_UNKNOWN" TextCodeAssuranceInsufficient = "ASSURANCE_INSUFFICIENT" TextCodeAssuranceStale = "ASSURANCE_STALE" TextCodeAssuranceStepUpRequired = "ASSURANCE_STEP_UP_REQUIRED" TextCodeAccountStateUnknown = "ACCOUNT_STATE_UNKNOWN" TextCodeAccountStateConflict = "ACCOUNT_STATE_CONFLICT" TextCodePermissionVersionMismatch = "PERMISSION_VERSION_MISMATCH" TextCodePermissionVersionMissing = "PERMISSION_VERSION_MISSING" TextCodeAuthorizationRoleMissing = "AUTHORIZATION_ROLE_MISSING" TextCodeFreshnessPolicyInvalid = "FRESHNESS_POLICY_INVALID" TextCodeAuthorizationFreshnessDeny = "AUTHORIZATION_FRESHNESS_DENIED" TextCodeFreshnessInvalidationFailed = "FRESHNESS_INVALIDATION_FAILED" TextCodeEmergencyAccessDenied = "EMERGENCY_ACCESS_DENIED" )
const ( MaxNormalAccountStateCache = 15 * time.Minute MaxPrivilegedStateCache = time.Minute MaxAssuranceAuthenticationAge = 24 * time.Hour MaxAuthorizationPropagation = time.Hour )
const ( // ResetUnknownStatus is the unknown status ResetUnknownStatus = "unknown" // ResetRequestedStatus is the requested status ResetRequestedStatus = "requested" // ResetExpiredStatus is the expired status ResetExpiredStatus = "expired" // ResetChangedStatus is the changed status ResetChangedStatus = "changed" )
const ( DefaultPermissionResolutionTimeout = 5 * time.Second MaxPermissionResolutionTimeout = 30 * time.Second )
const ( TokenEnvelopeVersion1 = uint8(1) TokenEnvelopeAES256GCM = "AES-256-GCM" // #nosec G101 -- Algorithm identifier, not a credential. )
const ( DefaultProviderSessionCookieName = "__Host-go_auth_ps" DefaultProviderSessionTouch = 5 * time.Minute DefaultProviderRefreshLease = 30 * time.Second DefaultProviderSessionRetention = 30 * 24 * time.Hour DefaultProviderTokenRetention = 24 * time.Hour MaxProviderTokenPayloadBytes = 64 * 1024 MaxProviderTokenKeyIDBytes = 128 )
const ( DefaultPrincipalMetadataEntries = 32 DefaultPrincipalMetadataBytes = 16 * 1024 )
const ( TemporaryPasswordMetadataKey = "password_temporary" PasswordChangeRequiredMetadataKey = "password_change_required" TemporaryPasswordIssuedAtMetadataKey = "password_temporary_issued_at" TemporaryPasswordExpiresAtMetadataKey = "password_temporary_expires_at" )
const ( // DefaultTokenWarnThresholdBytes emits a warning log when a signed JWT reaches // this size. It remains valid unless the hard limit is exceeded. DefaultTokenWarnThresholdBytes = 2048 // DefaultTokenHardLimitBytes rejects tokens larger than this size to reduce // oversized cookie risk in downstream applications. DefaultTokenHardLimitBytes = 4096 )
const ( // TokenTypeSession labels regular auth/session JWTs. TokenTypeSession = "session" // TokenTypeScoped labels short-lived scoped JWTs minted by MintScopedToken. TokenTypeScoped = "scoped" // TokenTypeCustom labels direct TokenService.SignClaims calls. TokenTypeCustom = "custom" )
const ( DefaultMaxLoginAttempts = 5 DefaultLoginAttemptWindow = 24 * time.Hour )
const MaxEmergencyAccessDuration = time.Hour
const MinimumHMACSigningKeyBytes = 32
const ( // PermissionsVersionMetadataKey is the preferred claim metadata key used to // carry permission-set version/etag values across requests. PermissionsVersionMetadataKey = "permissions_version" )
Variables ¶
var ( ErrProviderOperationInvalid = errors.New("auth: invalid provider operation") ErrProviderOperationUnsupported = errors.New("auth: provider operation is unsupported") ErrProviderOperationConflict = errors.New("auth: provider operation conflicts with current state") ErrProviderOperationPending = errors.New("auth: provider operation outcome is pending") )
var ( ErrLifecycleOperationConflict = errors.New("auth: lifecycle operation revision conflict") )
var ( ErrProviderSessionInvalid = errors.New("auth: invalid provider session") ErrProviderSessionNotFound = errors.New("auth: provider session not found") ErrProviderSessionExpired = errors.New("auth: provider session expired") ErrProviderSessionRevoked = errors.New("auth: provider session revoked") ErrProviderSessionUncertain = errors.New("auth: provider session refresh outcome is uncertain") ErrProviderSessionConflict = errors.New("auth: provider session revision conflict") ErrProviderSessionBinding = errors.New("auth: provider session binding mismatch") ErrProviderSessionCredential = errors.New("auth: conflicting authentication credentials") ErrProviderRefreshInProgress = errors.New("auth: provider session refresh in progress") ErrProviderRefreshRejected = errors.New("auth: provider refresh rejected") ErrProviderRefreshAmbiguous = errors.New("auth: provider refresh outcome ambiguous") ErrProviderTokenCipher = errors.New("auth: provider token cipher failure") ErrProviderTokenKeyNotFound = errors.New("auth: provider token key not found") ErrProviderTokenKeyRetired = errors.New("auth: provider token key is retired") ErrProviderTokenEnvelope = errors.New("auth: invalid provider token envelope") ErrProviderTokenTarget = errors.New("auth: invalid provider token target") ErrProviderTokenPolicy = errors.New("auth: provider token access denied") )
var ( ErrSecretSerialization = errors.New("auth: secret serialization is disabled") ErrInvalidTokenSet = errors.New("auth: invalid provider token set") ErrInvalidPrincipal = errors.New("auth: invalid authenticated principal") )
var ( MaxLoginAttempts = DefaultMaxLoginAttempts CoolDownPeriod = "24h" )
MaxLoginAttempts and CoolDownPeriod remain variables for source compatibility. NewUserProvider uses immutable defaults; configure an instance with WithLoginAttemptPolicy instead.
var ErrAccountStateConflict = errors.New("account state sources conflict", errors.CategoryAuthz). WithTextCode(TextCodeAccountStateConflict). WithCode(errors.CodeForbidden)
WithTextCode(TextCodeAccountStateUnavailable). WithCode(errors.CodeInternal)
var ErrAccountStateUnknown = errors.New("account state is unknown", errors.CategoryAuthz). WithTextCode(TextCodeAccountStateUnknown). WithCode(errors.CodeForbidden)
var ErrAssuranceInsufficient = errors.New("authentication assurance is insufficient", errors.CategoryAuthz). WithTextCode(TextCodeAssuranceInsufficient). WithCode(errors.CodeForbidden)
var ErrAssuranceMissing = errors.New("authentication assurance is missing", errors.CategoryAuth). WithTextCode(TextCodeAssuranceMissing). WithCode(errors.CodeUnauthorized)
var ErrAssuranceStale = errors.New("authentication assurance is stale", errors.CategoryAuthz). WithTextCode(TextCodeAssuranceStale). WithCode(errors.CodeForbidden)
var ErrAssuranceStepUpRequired = errors.New("authentication step-up is required", errors.CategoryAuth). WithTextCode(TextCodeAssuranceStepUpRequired). WithCode(errors.CodeUnauthorized)
var ErrAssuranceUnknown = errors.New("authentication assurance is unknown", errors.CategoryAuthz). WithTextCode(TextCodeAssuranceUnknown). WithCode(errors.CodeForbidden)
var ErrAuthorizationFreshnessDenied = errors.New("authorization freshness requirement was denied", errors.CategoryAuthz). WithTextCode(TextCodeAuthorizationFreshnessDeny). WithCode(errors.CodeForbidden)
var ErrAuthorizationRoleMissing = errors.New("authorization role is unavailable", errors.CategoryExternal). WithTextCode(TextCodeAuthorizationRoleMissing). WithCode(errors.CodeInternal)
var ErrEmergencyAccessDenied = errors.New("emergency access denied", errors.CategoryAuthz). WithTextCode(TextCodeEmergencyAccessDenied). WithCode(errors.CodeForbidden)
WithTextCode(TextCodeEmergencyAccessUnavailable). WithCode(errors.CodeInternal)
var ErrFreshnessInvalidationFailed = errors.New("freshness invalidation failed", errors.CategoryInternal). WithTextCode(TextCodeFreshnessInvalidationFailed). WithCode(errors.CodeInternal)
var ErrFreshnessPolicyInvalid = errors.New("authorization freshness policy is invalid", errors.CategoryValidation). WithTextCode(TextCodeFreshnessPolicyInvalid). WithCode(errors.CodeBadRequest)
var ErrIdentifierConflict = errors.New("external identifier is already bound", errors.CategoryConflict). WithTextCode(TextCodeIdentifierConflict). WithCode(errors.CodeConflict)
ErrIdentifierConflict is returned when an immutable external identifier is already bound to another local user.
var ErrIdentityNotFound = errors.New("identity not found", errors.CategoryNotFound). WithCode(errors.CodeNotFound)
ErrIdentityNotFound is returned when an identity cannot be found.
var ErrIdentityProviderRequired = errors.New("identity provider is required", errors.CategoryInternal). WithCode(errors.CodeInternal). WithTextCode(TextCodeIdentityProviderRequired)
ErrIdentityProviderRequired indicates missing authenticator configuration. NewAuthenticator remains compatible with token-validation-only callers; credential operations require a non-nil IdentityProvider.
var ErrImmutableClaimMutation = errors.New("claims decorator attempted to mutate immutable claim", errors.CategoryValidation). WithTextCode(TextCodeImmutableClaim). WithCode(errors.CodeBadRequest)
ErrImmutableClaimMutation is returned when a decorator tampers with protected claims.
var ErrInvalidTransition = goerrors.New("invalid user state transition", goerrors.CategoryValidation). WithTextCode(textCodeInvalidTransition). WithCode(goerrors.CodeBadRequest)
ErrInvalidTransition is returned when a requested status change is not allowed.
var ErrMismatchedHashAndPassword = errors.New("the credentials provided are invalid", errors.CategoryAuth). WithTextCode(TextCodeInvalidCreds). WithCode(errors.CodeUnauthorized)
ErrMismatchedHashAndPassword is returned on a failure to check a password hash. The message is generic to avoid leaking information.
var ErrNoEmptyString = errors.New("password can't be an empty string", errors.CategoryValidation). WithTextCode(TextCodeEmptyPassword). WithCode(errors.CodeBadRequest)
ErrNoEmptyString is returned when an empty string is provided for a value that must not be empty, like a password.
var ErrPasswordResetDisabled = errors.New("password reset is currently disabled", errors.CategoryAuthz). WithTextCode(TextCodePasswordResetDisabled). WithCode(errors.CodeForbidden)
ErrPasswordResetDisabled is returned when password reset flows are disabled.
var ErrPermissionResolverRequired = errors.New("permission resolver is required in strict mode", errors.CategoryValidation). WithTextCode(TextCodePermissionResolverRequired). WithCode(errors.CodeBadRequest)
ErrPermissionResolverRequired is returned when strict resolver mode is enabled without a resolver.
var ErrPermissionVersionMismatch = errors.New("permission version is stale", errors.CategoryAuthz). WithTextCode(TextCodePermissionVersionMismatch). WithCode(errors.CodeForbidden)
var ErrPermissionVersionMissing = errors.New("permission version is unavailable", errors.CategoryExternal). WithTextCode(TextCodePermissionVersionMissing). WithCode(errors.CodeInternal)
var ErrSignupDisabled = errors.New("signups are currently disabled", errors.CategoryAuthz). WithTextCode(TextCodeSignupDisabled). WithCode(errors.CodeForbidden)
ErrSignupDisabled is returned when registrations are turned off by feature gates.
var ErrTemporaryPasswordExpired = errors.New("temporary password expired", errors.CategoryAuth). WithTextCode(TextCodeTemporaryPasswordExpired). WithCode(errors.CodeForbidden)
ErrTemporaryPasswordExpired is returned when a temporary bootstrap password is no longer valid.
var ErrTerminalState = goerrors.New("user state is terminal", goerrors.CategoryConflict). WithTextCode(textCodeTerminalState). WithCode(goerrors.CodeConflict)
ErrTerminalState is returned when attempting to move away from a terminal status (e.g., archived).
var ErrTokenExpired = errors.New("token is expired", errors.CategoryAuth). WithTextCode(TextCodeTokenExpired). WithCode(errors.CodeUnauthorized)
ErrTokenExpired is returned when a JWT token has expired.
var ErrTokenMalformed = errors.New("token is malformed", errors.CategoryAuth). WithTextCode(TextCodeTokenMalformed). WithCode(errors.CodeBadRequest)
ErrTokenMalformed is returned when a JWT token is malformed.
var ErrTokenTooLarge = errors.New("token exceeds maximum allowed size", errors.CategoryValidation). WithTextCode(TextCodeTokenTooLarge). WithCode(errors.CodeBadRequest)
ErrTokenTooLarge is returned when a signed JWT exceeds configured guardrails.
var ErrTooManyLoginAttempts = errors.New("too many login attempts, please try again later", errors.CategoryRateLimit). WithTextCode(TextCodeTooManyAttempts). WithCode(errors.CodeTooManyRequests)
ErrTooManyLoginAttempts indicates the user has tried to log in too many times.
var ErrUnableToDecodeSession = errors.New("unable to decode session", errors.CategoryAuth). WithTextCode(TextCodeSessionDecodeError). WithCode(errors.CodeUnauthorized)
ErrUnableToDecodeSession is returned when a session token (e.g., JWT) cannot be decoded or parsed.
var ErrUnableToFindSession = errors.New("unable to find session", errors.CategoryAuth). WithTextCode(TextCodeSessionNotFound). WithCode(errors.CodeUnauthorized)
ErrUnableToFindSession is returned when a session (e.g., a cookie) is missing from a request.
var ErrUnableToMapClaims = errors.New("unable to map claims from token", errors.CategoryAuth). WithTextCode(TextCodeClaimsMappingError). WithCode(errors.CodeUnauthorized)
ErrUnableToMapClaims is returned when claims cannot be extracted from a parsed token.
var ErrUnableToParseData = errors.New("unable to parse authentication data", errors.CategoryBadInput). WithTextCode(TextCodeDataParseError). WithCode(errors.CodeBadRequest)
ErrUnableToParseData is returned on a generic data parsing error within the auth context.
var ErrUserArchived = errors.New("user account is archived", errors.CategoryAuth). WithTextCode(TextCodeAccountArchived). WithCode(errors.CodeForbidden)
ErrUserArchived is returned when an account is archived.
var ErrUserDisabled = errors.New("user account is disabled", errors.CategoryAuth). WithTextCode(TextCodeAccountDisabled). WithCode(errors.CodeForbidden)
ErrUserDisabled is returned when an account is disabled.
var ErrUserPending = errors.New("user account is pending activation", errors.CategoryAuth). WithTextCode(TextCodeAccountPending). WithCode(errors.CodeForbidden)
ErrUserPending is returned when an account is pending activation.
var ErrUserSuspended = errors.New("user account is suspended", errors.CategoryAuth). WithTextCode(TextCodeAccountSuspended). WithCode(errors.CodeForbidden)
ErrUserSuspended is returned when an account is suspended.
var ResetUserPasswordSQL = `` /* 148-byte string literal not displayed */
#nosec G101 -- SQL updates a password hash but does not embed credentials.
var TemplateUserKey = "current_user"
Functions ¶
func Can ¶ added in v0.7.0
Can is a convenience function to check permissions directly from the standard context Use CanFromRouter for router-based contexts.
func CanFromRouter ¶ added in v0.7.0
CanFromRouter is a convenience function to check permissions directly from the router context
func ClearTemporaryPasswordMetadata ¶ added in v0.42.0
ClearTemporaryPasswordMetadata removes temporary-password state from a cloned metadata map.
func ComparePasswordAndHash ¶
ComparePasswordAndHash will validate the given cleartext password matches the hashed password
func ContextEnricherAdapter ¶ added in v0.23.0
ContextEnricherAdapter adapts jwtware.AuthClaims to auth.AuthClaims and stores claims + actor context in the standard context for downstream guard usage.
func CredentialModeGuard ¶ added in v0.45.0
func CredentialModeGuard(cfg RouteCredentialConfig) (router.MiddlewareFunc, error)
func DefaultPermissionsCacheKeyFromContext ¶ added in v0.32.0
DefaultPermissionsCacheKeyFromContext builds a stable resolver key from identity/tenant context plus permission-affecting discriminators (version, token, scopes, impersonation, session). It bypasses caching when no discriminator is available.
func DeriveBrowserCSRFSecureKey ¶ added in v0.45.0
DeriveBrowserCSRFSecureKey derives a stable, domain-separated CSRF key from the host's authentication configuration. It keeps browser CSRF signatures aligned across package-managed auth routes and application instances without reusing the raw authentication signing key.
func EncodeProviderSessionReason ¶ added in v0.45.0
func EncodeProviderSessionReason(reason ProviderSessionReason) string
func GetAuthExtrasMigrationsFS ¶ added in v0.36.0
GetAuthExtrasMigrationsFS returns optional auth extras migrations.
func GetCoreMigrationsFS ¶ added in v0.36.0
GetCoreMigrationsFS returns the canonical core auth schema migrations.
func GetMigrationsFS ¶
GetMigrationsFS returns the migration files for this package
func GetTemplateUser ¶ added in v0.10.0
GetTemplateUser is a convenience function to extract user data from router context for template usage. It returns the user object and a boolean indicating if it was found.
Usage:
if user, ok := auth.GetTemplateUser(ctx, auth.TemplateUserKey); ok {
// Use user in template data
data["user"] = user
}
func HasTemporaryPasswordMetadata ¶ added in v0.42.0
HasTemporaryPasswordMetadata reports whether the metadata carries any temporary-password markers that must be cleared during a permanent password change.
func HasUserUUID ¶ added in v0.24.0
HasUserUUID reports whether Session.GetUserUUID will succeed.
func HashPassword ¶
HashPassword will generate a password hash
func IsMalformedError ¶
func IsOutsideThresholdPeriod ¶
IsOutsideThresholdPeriod is the negation of IsWithinThresholdPeriod
func IsProviderLifecycleActivity ¶ added in v0.45.0
func IsProviderLifecycleActivity(eventType ActivityEventType) bool
func IsProviderSessionActivity ¶ added in v0.45.0
func IsProviderSessionActivity(eventType ActivityEventType) bool
func IsTokenExpiredError ¶
func IsWithinThresholdPeriod ¶
IsWithinThresholdPeriod checks if the given time is within the threshold
func MergeTemplateData ¶ added in v0.16.0
func MergeTemplateData(ctx router.Context, data router.ViewContext) router.ViewContext
MergeTemplateData ensures every render includes the latest template helpers (current user, CSRF helpers, etc.) merged with the provided view context. It evaluates helper closures that return strings or template.HTML so request- scoped helpers are always materialized before hitting the renderer.
func MintScopedToken ¶ added in v0.29.0
func MintScopedToken(tokenService TokenService, identity Identity, resourceRoles map[string]string, opts ScopedTokenOptions) (string, time.Time, error)
MintScopedToken mints a short-lived JWT with optional scopes and TTL override. It uses TokenService defaults for issuer, audience, and TTL when available.
func MustValidateResolverConfigured ¶ added in v0.34.0
func MustValidateResolverConfigured(strict bool, resolver PermissionResolverFunc)
MustValidateResolverConfigured is a panic wrapper around ValidateResolverConfigured.
func NewPasswordResetsRepository ¶
func NewPasswordResetsRepository(db *bun.DB) repository.Repository[*PasswordReset]
func NewTemplateViews ¶ added in v0.45.5
NewTemplateViews wraps a configured engine with an opt-in auth view boundary. Claims in plain render maps/slices expose identity and permission checks, not raw JWT metadata or extension methods. Request locals and context are untouched. Configure engine-specific helpers/extensions before wrapping. Nil stays nil.
func PermissionsVersionFromClaims ¶ added in v0.32.0
func PermissionsVersionFromClaims(claims AuthClaims) string
PermissionsVersionFromClaims extracts the permissions version from claims metadata.
func PermissionsVersionFromContext ¶ added in v0.32.0
PermissionsVersionFromContext extracts the permissions version from actor/claims metadata.
func RandomPasswordHash ¶
func RandomPasswordHash() string
RandomPasswordHash is a temporary password
func RegisterAuthRoutes ¶
func RegisterAuthRoutes[T any](app router.Router[T], opts ...AuthControllerOption)
func RegisterSecureAuthRoutes ¶ added in v0.45.0
func RegisterSecureAuthRoutes[T any](app router.Router[T], cfg AuthRouteSecurityConfig, opts ...AuthControllerOption) error
RegisterSecureAuthRoutes registers browser authentication routes with CSRF and origin protection. Logout is POST-only in this secure route set.
func RegisterValidationListeners ¶ added in v0.23.0
func RegisterValidationListeners(cfg *jwtware.Config, listeners ...ValidationListener)
RegisterValidationListeners appends listeners to a jwtware.Config in a safe, reusable way.
func RequireTokenUse ¶ added in v0.45.0
func RequireTokenUse(claims AuthClaims, expected string) error
RequireTokenUse enforces an explicit token-use boundary. Scoped-token consumers should call this with TokenTypeScoped after general validation.
func ResolveLogger ¶ added in v0.31.0
func ResolveLogger(name string, provider LoggerProvider, logger Logger) (LoggerProvider, Logger)
ResolveLogger resolves provider and logger with precedence provider > logger > nop.
func SetPermissionsVersionMetadata ¶ added in v0.32.0
SetPermissionsVersionMetadata stores a compact permission-version marker in claims metadata.
func TemplateHelpers ¶ added in v0.10.0
TemplateHelpers returns a map of helper functions and data that can be used with go-template's WithGlobalData option for authentication-related template functionality.
Usage:
renderer, err := template.NewRenderer(
template.WithBaseDir("./templates"),
template.WithGlobalData(auth.TemplateHelpers()),
)
In templates, you can then use:
{% if current_user %}
{% if current_user|has_role:"admin" %}
{% if current_user|can_create:"posts" %}
{{ csrf_field }}
{{ csrf_token }}
func TemplateHelpersForPongo2V7 ¶ added in v0.45.5
TemplateHelpersForPongo2V7 returns auth helpers for a pongo2/v7 renderer, such as go-router's explicit Fiber v3 view engine. CSRF values are resolved from each execution context and returned as plain strings; the renderer owns escaping. This does not change TemplateHelpers or the default CSRF helper factory.
func TemplateHelpersWithRouter ¶ added in v0.10.0
TemplateHelpersWithRouter returns template helpers with user data extracted from router context. This is useful for automatically injecting the current user from JWT middleware context. It also includes CSRF token helpers when a CSRF token is available in the context.
Usage:
// In your route handler globalData := auth.TemplateHelpersWithRouter(ctx, auth.TemplateUserKey) // Merge with request-specific data and render template
Or with a reusable render helper:
func renderTemplate(ctx router.Context, name string, data map[string]any) (string, error) {
globalData := auth.TemplateHelpersWithRouter(ctx, auth.TemplateUserKey)
// Create renderer with current context or use a cached one
return renderer.RenderTemplate(name, data)
}
func TemplateHelpersWithUser ¶ added in v0.10.0
TemplateHelpersWithUser returns template helpers with a specific user set as current_user. This is useful when you want to inject the current user directly into the global context.
Usage:
currentUser := getCurrentUser(ctx)
renderer, err := template.NewRenderer(
template.WithBaseDir("./templates"),
template.WithGlobalData(auth.TemplateHelpersWithUser(currentUser)),
)
func TokenIDFromContext ¶ added in v0.29.0
TokenIDFromContext extracts the token ID (jti) from the standard context.
func ValidateResolverConfigured ¶ added in v0.34.0
func ValidateResolverConfigured(strict bool, resolver PermissionResolverFunc) error
ValidateResolverConfigured enforces resolver presence when strict mode is enabled.
func ValidateStringEquals ¶
func ValidateStringEquals(str string) validation.RuleFunc
ValidateStringEquals will check that both values match
func WithActorContext ¶ added in v0.15.0
func WithActorContext(ctx context.Context, actor *ActorContext) context.Context
WithActorContext stores the ActorContext in the provided context.
func WithAssuranceContext ¶ added in v0.45.0
func WithAssuranceContext(ctx context.Context, assurance AssuranceContext) context.Context
WithAssuranceContext stores isolated normalized assurance evidence.
func WithClaimsContext ¶ added in v0.7.0
func WithClaimsContext(r context.Context, claims AuthClaims) context.Context
WithClaimsContext sets the AuthClaims in the given context
func WithContext ¶ added in v0.4.0
WithContext sets the User in the given context
func WithCurrentPermissionsRequest ¶ added in v0.45.0
func WithCurrentPermissionsRequest( ctx context.Context, request CurrentPermissionsRequest, ) (context.Context, error)
WithCurrentPermissionsRequest returns a context whose permission cache keys and invalidation scope are derived from current normalized authorization state rather than stale token hints.
func WithProviderSessionContext ¶ added in v0.45.0
func WithProviderSessionContext(ctx context.Context, session ProviderSession, principal AuthenticatedPrincipal) context.Context
func WithResolvedPermissionsCache ¶ added in v0.34.0
WithResolvedPermissionsCache seeds a request-scoped permission resolver cache in the provided context. The cache deduplicates repeated permission lookups within the same request context.
Types ¶
type AESGCMTokenCipher ¶ added in v0.45.0
type AESGCMTokenCipher struct {
// contains filtered or unexported fields
}
func NewAESGCMTokenCipher ¶ added in v0.45.0
func NewAESGCMTokenCipher(keys TokenKeyProvider) (*AESGCMTokenCipher, error)
func (*AESGCMTokenCipher) Open ¶ added in v0.45.0
func (c *AESGCMTokenCipher) Open(ctx context.Context, envelope TokenEnvelope, associatedData []byte) ([]byte, error)
func (*AESGCMTokenCipher) Seal ¶ added in v0.45.0
func (c *AESGCMTokenCipher) Seal(ctx context.Context, plaintext, associatedData []byte) (TokenEnvelope, error)
type AccountLifecycle ¶ added in v0.45.0
type AccountLifecycle interface {
Suspend(context.Context, AccountLifecycleRequest) (AccountStateResult, error)
Activate(context.Context, AccountLifecycleRequest) (AccountStateResult, error)
GetAccountState(context.Context, AccountLifecycleRequest) (AccountStateResult, error)
}
type AccountLifecycleRequest ¶ added in v0.45.0
type AccountLifecycleRequest struct {
Operation AuthorizedOperationContext
}
type AccountRegistrerer ¶
type AccountRegistrerer interface {
RegisterUser(ctx context.Context, email, username, password string) (*User, error)
}
AccountRegistrerer is the interface we need to handle new user registrations
type AccountState ¶ added in v0.45.0
type AccountState string
AccountState is the provider-neutral lifecycle state used by freshness policy. Unknown and unsupported never imply active.
const ( AccountStateActive AccountState = "active" AccountStateSuspended AccountState = "suspended" AccountStateDisabled AccountState = "disabled" AccountStatePending AccountState = "pending" AccountStateArchived AccountState = "archived" AccountStateUnknown AccountState = "unknown" AccountStateUnsupported AccountState = "unsupported" )
func AccountStateFromProvider ¶ added in v0.45.0
func AccountStateFromProvider(state ProviderAccountState) AccountState
func ParseAccountState ¶ added in v0.45.0
func ParseAccountState(value string) (AccountState, error)
type AccountStateInvalidator ¶ added in v0.45.0
type AccountStateObservation ¶ added in v0.45.0
type AccountStateObservation struct {
State AccountState
Source string
ObservedAt time.Time
}
type AccountStateRequest ¶ added in v0.45.0
type AccountStateRequest struct {
Principal AuthenticatedPrincipal
MaximumStaleness time.Duration
Privileged bool
}
type AccountStateResolution ¶ added in v0.45.0
type AccountStateResolution struct {
State AccountState
ObservedAt time.Time
Sources []AccountStateObservation
FromCache bool
Conflict bool
InvalidEvidence bool
}
type AccountStateResolver ¶ added in v0.45.0
type AccountStateResolver interface {
ResolveCurrentAccountState(context.Context, AccountStateRequest) (AccountStateResolution, error)
}
type AccountStateResult ¶ added in v0.45.0
type AccountStateResult struct {
ProviderOperationOutcome
State ProviderAccountState
UpdatedAt time.Time
}
type AccountStateScopeInvalidator ¶ added in v0.45.0
type AccountStateSource ¶ added in v0.45.0
type AccountStateSource interface {
ResolveAccountState(context.Context, AuthenticatedPrincipal) (AccountStateObservation, error)
}
type AccountStateSourceFunc ¶ added in v0.45.0
type AccountStateSourceFunc func(context.Context, AuthenticatedPrincipal) (AccountStateObservation, error)
func (AccountStateSourceFunc) ResolveAccountState ¶ added in v0.45.0
func (f AccountStateSourceFunc) ResolveAccountState(ctx context.Context, principal AuthenticatedPrincipal) (AccountStateObservation, error)
type AccountVerificationHandler ¶
type AccountVerificationHandler struct {
// contains filtered or unexported fields
}
func (*AccountVerificationHandler) Execute ¶
func (h *AccountVerificationHandler) Execute(ctx context.Context, event AccountVerificationMesage) error
type AccountVerificationMesage ¶
type AccountVerificationMesage struct {
Session string `json:"session" example:"350399bc-c095-4bdc-a59c-3352d44848e4" doc:"Reset password session token"`
OnResponse func(a *AccountVerificationResponse)
}
type AccountVerificationResponse ¶
type AccountVerificationResponse struct {
Stage string `json:"stage" example:"Rone" doc:"Customer last name."`
Redirect string `json:"redirect" example:"Rone" doc:"Customer last name."`
Expired bool `json:"expired" example:"true" doc:"Has the request expired?"`
Found bool `json:"found" example:"true" doc:"Has the request been found?"`
Errors []string `json:"errors" example:"['invalid username']" doc:"Error messages."`
}
type ActivityEvent ¶ added in v0.14.0
type ActivityEvent struct {
EventType ActivityEventType
Actor ActorRef
UserID string
FromStatus UserStatus
ToStatus UserStatus
Metadata map[string]any
OccurredAt time.Time
}
ActivityEvent captures producer-side information about an action. Metadata is not a persistence-safe payload: login events may include the raw, unverified submitted identifier and provider error text. Consumers must apply their own retention/redaction policy before storage, forwarding or display. An attempted identifier must never be treated as verified actor identity.
func NewProviderLifecycleActivityEvent ¶ added in v0.45.0
func NewProviderLifecycleActivityEvent( operation AuthorizedOperationContext, outcome ProviderOperationOutcome, occurredAt time.Time, ) (ActivityEvent, error)
NewProviderLifecycleActivityEvent constructs a secret-free audit event from typed lifecycle inputs. Security-state delivery remains the coordinator's responsibility; this event is best-effort audit context only.
func NewProviderSessionActivityEvent ¶ added in v0.45.0
func NewProviderSessionActivityEvent( eventType ActivityEventType, session ProviderSession, metadata ProviderSessionActivityMetadata, occurredAt time.Time, ) (ActivityEvent, error)
type ActivityEventType ¶ added in v0.14.0
type ActivityEventType string
ActivityEventType enumerates supported activity categories.
const ( ActivityEventUserStatusChanged ActivityEventType = "user.status.changed" ActivityEventLoginSuccess ActivityEventType = "auth.login.success" ActivityEventLoginFailure ActivityEventType = "auth.login.failure" ActivityEventSocialLogin ActivityEventType = "auth.social.login" ActivityEventSSOLoginSuccess ActivityEventType = "auth.sso.login.success" ActivityEventSSOLoginFailure ActivityEventType = "auth.sso.login.failure" ActivityEventSSOLinkAutomatic ActivityEventType = "auth.sso.link.automatic" ActivityEventSSOLinkManual ActivityEventType = "auth.sso.link.manual" ActivityEventSSOLinkRejected ActivityEventType = "auth.sso.link.rejected" ActivityEventSSOUnlink ActivityEventType = "auth.sso.unlink" ActivityEventSSOLogout ActivityEventType = "auth.sso.logout" ActivityEventProviderSessionCreated ActivityEventType = "auth.provider_session.created" ActivityEventProviderSessionRefreshed ActivityEventType = "auth.provider_session.refreshed" ActivityEventProviderSessionUncertain ActivityEventType = "auth.provider_session.uncertain" ActivityEventProviderSessionRevoked ActivityEventType = "auth.provider_session.revoked" ActivityEventProviderTokenAccessed ActivityEventType = "auth.provider_token.accessed" ActivityEventProviderInvite ActivityEventType = "auth.provider.identity.invite" ActivityEventProviderRecovery ActivityEventType = "auth.provider.identity.recovery" ActivityEventProviderAccountSuspend ActivityEventType = "auth.provider.account.suspend" ActivityEventProviderAccountActivate ActivityEventType = "auth.provider.account.activate" ActivityEventProviderAccountState ActivityEventType = "auth.provider.account.state" ActivityEventProviderFactorList ActivityEventType = "auth.provider.factor.list" ActivityEventProviderFactorRemove ActivityEventType = "auth.provider.factor.remove" ActivityEventProviderAuthDetails ActivityEventType = "auth.provider.authorization.details" ActivityEventProviderAuthApprove ActivityEventType = "auth.provider.authorization.approve" ActivityEventProviderAuthDeny ActivityEventType = "auth.provider.authorization.deny" ActivityEventImpersonationSuccess ActivityEventType = "auth.impersonation.success" ActivityEventImpersonationFailure ActivityEventType = "auth.impersonation.failure" ActivityEventPasswordResetSuccess ActivityEventType = "auth.password.reset" ActivityEventAssuranceDenied ActivityEventType = "auth.assurance.denied" ActivityEventAssuranceStepUp ActivityEventType = "auth.assurance.step_up" ActivityEventAuthorizationFreshness ActivityEventType = "auth.authorization.freshness" ActivityEventFreshnessInvalidation ActivityEventType = "auth.freshness.invalidation" ActivityEventEmergencyAccess ActivityEventType = "auth.emergency_access" )
type ActivitySink ¶ added in v0.14.0
type ActivitySink interface {
Record(ctx context.Context, event ActivityEvent) error
}
ActivitySink consumes activity events for auditing/telemetry purposes.
type ActivitySinkFunc ¶ added in v0.14.0
type ActivitySinkFunc func(ctx context.Context, event ActivityEvent) error
ActivitySinkFunc adapts a function to the ActivitySink interface.
func (ActivitySinkFunc) Record ¶ added in v0.14.0
func (f ActivitySinkFunc) Record(ctx context.Context, event ActivityEvent) error
Record implements ActivitySink.
type ActorContext ¶ added in v0.15.0
type ActorContext struct {
ActorID string
Subject string
Role string
ResourceRoles map[string]string
TenantID string
OrganizationID string
Metadata map[string]any
ImpersonatorID string
IsImpersonated bool
}
ActorContext captures normalized actor metadata for downstream policy/guard layers.
func ActorContextFromClaims ¶ added in v0.15.0
func ActorContextFromClaims(claims AuthClaims) *ActorContext
ActorContextFromClaims normalizes actor metadata from AuthClaims into an ActorContext structure.
func ActorFromContext ¶ added in v0.15.0
func ActorFromContext(ctx context.Context) (*ActorContext, bool)
ActorFromContext extracts the ActorContext from the standard context.
func ActorFromRouterContext ¶ added in v0.15.0
func ActorFromRouterContext(ctx router.Context) (*ActorContext, bool)
ActorFromRouterContext extracts the ActorContext from a router context by reading the underlying standard context.
type AssuranceContext ¶ added in v0.45.0
type AssuranceContext struct {
Level AssuranceLevel
Methods []string
AuthenticationAt time.Time
}
AssuranceContext contains normalized, non-secret authentication evidence.
func AssuranceFromContext ¶ added in v0.45.0
func AssuranceFromContext(ctx context.Context) (AssuranceContext, error)
AssuranceFromContext returns explicit assurance evidence or derives it from the normalized provider-session principal.
type AssuranceDecision ¶ added in v0.45.0
type AssuranceDecision string
const ( AssuranceAllowed AssuranceDecision = "allowed" AssuranceDenied AssuranceDecision = "denied" AssuranceStepUpRequired AssuranceDecision = "step_up_required" )
type AssuranceGuard ¶ added in v0.45.0
type AssuranceGuard struct {
Now func() time.Time
ActivitySink ActivitySink
}
AssuranceGuard evaluates assurance and emits denial/step-up audit events.
func (AssuranceGuard) Require ¶ added in v0.45.0
func (g AssuranceGuard) Require(ctx context.Context, requirement AssuranceRequirement) (AssuranceResult, error)
type AssuranceLevel ¶ added in v0.45.0
type AssuranceLevel string
AssuranceLevel is a provider-neutral ordered authentication assurance level.
const ( AssuranceUnknown AssuranceLevel = "unknown" AssuranceAAL1 AssuranceLevel = "aal1" AssuranceAAL2 AssuranceLevel = "aal2" )
func ParseAssuranceLevel ¶ added in v0.45.0
func ParseAssuranceLevel(value string) (AssuranceLevel, error)
ParseAssuranceLevel parses only supported provider-neutral values.
func (AssuranceLevel) Meets ¶ added in v0.45.0
func (l AssuranceLevel) Meets(required AssuranceLevel) bool
Meets reports whether a known level satisfies another known level.
type AssuranceReason ¶ added in v0.45.0
type AssuranceReason string
const ( AssuranceReasonSatisfied AssuranceReason = "satisfied" AssuranceReasonMissing AssuranceReason = "missing" AssuranceReasonUnknown AssuranceReason = "unknown" AssuranceReasonInsufficient AssuranceReason = "insufficient" AssuranceReasonStale AssuranceReason = "stale" AssuranceReasonInvalid AssuranceReason = "invalid_requirement" )
type AssuranceRequirement ¶ added in v0.45.0
type AssuranceRequirement struct {
Level AssuranceLevel
MaxAuthenticationAge time.Duration
Operation string
AllowStepUp bool
}
AssuranceRequirement is policy input for a single operation.
type AssuranceResult ¶ added in v0.45.0
type AssuranceResult struct {
Decision AssuranceDecision
Reason AssuranceReason
Required AssuranceLevel
Current AssuranceLevel
Methods []string
AuthenticationAt time.Time
Operation string
}
AssuranceResult is safe to log and contains no provider tokens.
func RequireAssurance ¶ added in v0.45.0
func RequireAssurance(ctx context.Context, level AssuranceLevel) (AssuranceResult, error)
RequireAssurance performs the compatibility-friendly level-only check.
type AtomicIndexedPermissionCacheStore ¶ added in v0.45.0
type AtomicIndexedPermissionCacheStore interface {
IndexedPermissionCacheStore
SetPermissionCacheEntry(
ctx context.Context,
key string,
permissions []string,
ttl time.Duration,
scope PermissionInvalidationScope,
) error
}
AtomicIndexedPermissionCacheStore publishes a permission value and all of its invalidation indexes as one operation. Implementations must leave neither the value nor its indexes visible when this method returns an error.
type AtomicLoginAttemptRepository ¶ added in v0.45.0
type AtomicLoginAttemptRepository interface {
AtomicLoginAttemptTracker
ReserveLoginAttemptTx(ctx context.Context, tx bun.IDB, userID uuid.UUID, policy LoginAttemptPolicy) (LoginAttemptReservation, error)
}
AtomicLoginAttemptRepository is the optional repository capability for reserving login attempts atomically, including inside an existing transaction. It is separate from Users to preserve compatibility for custom Users implementations.
type AtomicLoginAttemptTracker ¶ added in v0.45.0
type AtomicLoginAttemptTracker interface {
ReserveLoginAttempt(context.Context, uuid.UUID, LoginAttemptPolicy) (LoginAttemptReservation, error)
}
AtomicLoginAttemptTracker reserves password-verification attempts with one database operation so parallel requests cannot exceed the configured budget.
type AuthClaims ¶ added in v0.7.0
type AuthClaims interface {
Subject() string
UserID() string
Role() string
CanRead(resource string) bool
CanEdit(resource string) bool
CanCreate(resource string) bool
CanDelete(resource string) bool
HasRole(role string) bool
IsAtLeast(minRole string) bool
Expires() time.Time
IssuedAt() time.Time
}
AuthClaims represents structured JWT claims with enhanced permission checking
func GetClaims ¶ added in v0.7.0
func GetClaims(ctx context.Context) (AuthClaims, bool)
GetClaims extracts the AuthClaims from the standard context
func GetRouterClaims ¶ added in v0.7.0
func GetRouterClaims(ctx router.Context, key string) (AuthClaims, bool)
GetRouterClaims extracts the AuthClaims from the router context
func WSAuthClaimsFromContext ¶ added in v0.9.0
func WSAuthClaimsFromContext(ctx context.Context) (AuthClaims, bool)
WSAuthClaimsFromContext is a convenience function to retrieve auth claims from WebSocket context. It returns the underlying go-auth AuthClaims for easier access to go-auth specific functionality.
type AuthController ¶
type AuthController struct {
Debug bool
Logger Logger
LoggerProvider LoggerProvider
Repo RepositoryManager
Routes *AuthControllerRoutes
Views *AuthControllerViews
Auther HTTPAuthenticator
ErrorHandler router.ErrorHandler
RegisterRedirect string
UseHashID bool
PasswordResetDelivery PasswordResetDelivery
// contains filtered or unexported fields
}
func NewAuthController ¶
func NewAuthController(opts ...AuthControllerOption) *AuthController
func (*AuthController) PasswordResetExecute ¶
func (a *AuthController) PasswordResetExecute(ctx router.Context) error
func (*AuthController) PasswordResetForm ¶
func (a *AuthController) PasswordResetForm(ctx router.Context) error
func (*AuthController) PasswordResetGet ¶
func (a *AuthController) PasswordResetGet(ctx router.Context) error
func (*AuthController) PasswordResetPost ¶
func (a *AuthController) PasswordResetPost(ctx router.Context) error
func (*AuthController) RegistrationCreate ¶
func (a *AuthController) RegistrationCreate(ctx router.Context) error
func (*AuthController) RegistrationShow ¶
func (a *AuthController) RegistrationShow(ctx router.Context) error
func (*AuthController) WithLogger ¶ added in v0.4.0
func (a *AuthController) WithLogger(l Logger) *AuthController
type AuthControllerOption ¶
type AuthControllerOption func(*AuthController) *AuthController
func WithAuthControllerActivitySink ¶ added in v0.14.0
func WithAuthControllerActivitySink(sink ActivitySink) AuthControllerOption
func WithAuthControllerRedirect ¶ added in v0.3.0
func WithAuthControllerRedirect(r string) AuthControllerOption
func WithAuthControllerRoutes ¶ added in v0.3.0
func WithAuthControllerRoutes(r *AuthControllerRoutes) AuthControllerOption
func WithAuthControllerUseHashID ¶ added in v0.3.0
func WithAuthControllerUseHashID(v bool) AuthControllerOption
func WithAuthControllerViews ¶ added in v0.3.0
func WithAuthControllerViews(v *AuthControllerViews) AuthControllerOption
func WithControllerLogger ¶ added in v0.1.1
func WithControllerLogger(logger Logger) AuthControllerOption
func WithControllerLoggerProvider ¶ added in v0.31.0
func WithControllerLoggerProvider(provider LoggerProvider) AuthControllerOption
func WithErrorHandler ¶ added in v0.3.0
func WithErrorHandler(errHandler router.ErrorHandler) AuthControllerOption
func WithFeatureGate ¶ added in v0.26.0
func WithFeatureGate(featureGate gate.FeatureGate) AuthControllerOption
func WithPasswordResetDelivery ¶ added in v0.45.0
func WithPasswordResetDelivery(delivery PasswordResetDelivery) AuthControllerOption
type AuthControllerRoutes ¶
type AuthControllerViews ¶
type AuthCookieOption ¶ added in v0.44.0
type AuthCookieOption func(*authCookieOptions)
func WithAuthCookieDuration ¶ added in v0.44.0
func WithAuthCookieDuration(duration time.Duration) AuthCookieOption
WithAuthCookieDuration overrides the default session-cookie duration used by SetAuthCookie for externally authenticated browser flows.
func WithExtendedAuthCookieDuration ¶ added in v0.44.0
func WithExtendedAuthCookieDuration() AuthCookieOption
WithExtendedAuthCookieDuration uses the configured extended session duration when SetAuthCookie writes a session cookie.
type AuthRouteSecurityConfig ¶ added in v0.45.0
type AuthRouteSecurityConfig struct {
CSRF csfmw.Config
Origin router.OriginProtectionConfig
}
AuthRouteSecurityConfig configures CSRF and origin checks for the package's browser-facing authentication routes.
type AuthenticatedPrincipal ¶ added in v0.45.0
type AuthenticatedPrincipal struct {
// contains filtered or unexported fields
}
func NewAuthenticatedPrincipal ¶ added in v0.45.0
func NewAuthenticatedPrincipal(input AuthenticatedPrincipalInput) (AuthenticatedPrincipal, error)
func (AuthenticatedPrincipal) ApplicationSubject ¶ added in v0.45.0
func (p AuthenticatedPrincipal) ApplicationSubject() string
func (AuthenticatedPrincipal) AssuranceLevel ¶ added in v0.45.0
func (p AuthenticatedPrincipal) AssuranceLevel() string
func (AuthenticatedPrincipal) AssuranceMethods ¶ added in v0.45.0
func (p AuthenticatedPrincipal) AssuranceMethods() []string
func (AuthenticatedPrincipal) AuthenticationAt ¶ added in v0.45.0
func (p AuthenticatedPrincipal) AuthenticationAt() time.Time
func (AuthenticatedPrincipal) BindLocalSessionID ¶ added in v0.45.0
func (p AuthenticatedPrincipal) BindLocalSessionID(localSessionID string) (AuthenticatedPrincipal, error)
BindLocalSessionID returns a copy associated with the host session created after provider identity linking. Rebinding to a different session fails.
func (AuthenticatedPrincipal) ClientID ¶ added in v0.45.0
func (p AuthenticatedPrincipal) ClientID() string
func (AuthenticatedPrincipal) Clone ¶ added in v0.45.0
func (p AuthenticatedPrincipal) Clone() AuthenticatedPrincipal
func (AuthenticatedPrincipal) ExpiresAt ¶ added in v0.45.0
func (p AuthenticatedPrincipal) ExpiresAt() time.Time
func (AuthenticatedPrincipal) IssuedAt ¶ added in v0.45.0
func (p AuthenticatedPrincipal) IssuedAt() time.Time
func (AuthenticatedPrincipal) LocalSessionID ¶ added in v0.45.0
func (p AuthenticatedPrincipal) LocalSessionID() string
func (AuthenticatedPrincipal) Metadata ¶ added in v0.45.0
func (p AuthenticatedPrincipal) Metadata() map[string]string
func (AuthenticatedPrincipal) OrganizationID ¶ added in v0.45.0
func (p AuthenticatedPrincipal) OrganizationID() string
func (AuthenticatedPrincipal) PermissionVersion ¶ added in v0.45.0
func (p AuthenticatedPrincipal) PermissionVersion() string
func (AuthenticatedPrincipal) Provider ¶ added in v0.45.0
func (p AuthenticatedPrincipal) Provider() string
func (AuthenticatedPrincipal) ProviderSessionID ¶ added in v0.45.0
func (p AuthenticatedPrincipal) ProviderSessionID() string
func (AuthenticatedPrincipal) ProviderSubject ¶ added in v0.45.0
func (p AuthenticatedPrincipal) ProviderSubject() string
func (AuthenticatedPrincipal) TenantID ¶ added in v0.45.0
func (p AuthenticatedPrincipal) TenantID() string
func (AuthenticatedPrincipal) TokenID ¶ added in v0.45.0
func (p AuthenticatedPrincipal) TokenID() string
type AuthenticatedPrincipalInput ¶ added in v0.45.0
type AuthenticatedPrincipalInput struct {
ApplicationSubject string
Provider string
ProviderSubject string
ProviderSessionID string
LocalSessionID string
ClientID string
AssuranceLevel string
AssuranceMethods []string
AuthenticationAt time.Time
IssuedAt time.Time
ExpiresAt time.Time
TokenID string
TenantID string
OrganizationID string
PermissionVersion string
Metadata map[string]string
}
AuthenticatedPrincipalInput is accepted only after provider identity linking.
type Authenticator ¶
type Authenticator interface {
Login(ctx context.Context, identifier, password string) (string, error)
Impersonate(ctx context.Context, identifier string) (string, error)
SessionFromToken(token string) (Session, error)
IdentityFromSession(ctx context.Context, session Session) (Identity, error)
TokenService() TokenService
}
Authenticator holds methods to deal with authentication
type Auther ¶
type Auther struct {
// contains filtered or unexported fields
}
func NewAuthenticator ¶
func NewAuthenticator(provider IdentityProvider, opts Config) *Auther
NewAuthenticator returns a new Authenticator. A nil or typed-nil provider supports token-validation-only use; Login and Impersonate return ErrIdentityProviderRequired until a valid provider is configured.
func (*Auther) IdentityFromSession ¶
func (*Auther) Impersonate ¶
func (*Auther) NewWSAuthMiddleware ¶ added in v0.9.0
func (a *Auther) NewWSAuthMiddleware(config ...router.WSAuthConfig) router.WebSocketMiddleware
NewWSAuthMiddleware creates a fully configured WebSocket authentication middleware using the go-auth TokenService. This is a convenience function for go-auth users.
func (Auther) SessionFromToken ¶
SessionFromToken validates a session token and, when a provider is configured, checks that its current identity still exists and is active. For request-scoped cancellation, use SessionFromTokenContext.
func (Auther) SessionFromTokenContext ¶ added in v0.45.3
SessionFromTokenContext validates a token before checking current account state. Authenticators without an identity provider retain token-validation-only mode.
func (*Auther) TokenService ¶ added in v0.11.0
func (s *Auther) TokenService() TokenService
TokenService returns the TokenService instance used by this Authenticator
func (*Auther) WithActivitySink ¶ added in v0.14.0
func (s *Auther) WithActivitySink(sink ActivitySink) *Auther
WithActivitySink configures an ActivitySink for emitting auth events.
func (*Auther) WithClaimsDecorator ¶ added in v0.14.0
func (s *Auther) WithClaimsDecorator(decorator ClaimsDecorator) *Auther
WithClaimsDecorator configures a ClaimsDecorator for enriching JWTs.
func (*Auther) WithLogger ¶ added in v0.1.1
func (*Auther) WithLoggerProvider ¶ added in v0.31.0
func (s *Auther) WithLoggerProvider(provider LoggerProvider) *Auther
WithLoggerProvider overrides the logger provider used by the authenticator.
func (*Auther) WithResourceRoleProvider ¶ added in v0.7.0
func (s *Auther) WithResourceRoleProvider(provider ResourceRoleProvider) *Auther
WithResourceRoleProvider sets a custom ResourceRoleProvider for the Auther. This enables resource-level permissions in JWT tokens.
func (*Auther) WithTokenSizeGuardrails ¶ added in v0.34.0
WithTokenSizeGuardrails configures signed JWT size warning/rejection thresholds.
func (*Auther) WithTokenValidator ¶ added in v0.24.0
func (s *Auther) WithTokenValidator(validator TokenValidator) *Auther
WithTokenValidator sets a custom token validator for externally issued tokens.
type AuthorizationContinuation ¶ added in v0.45.0
type AuthorizationDecisionRequest ¶ added in v0.45.0
type AuthorizationDecisionRequest struct {
Operation AuthorizedOperationContext
AuthorizationID string
ClientID string
Session ProviderUserSession
Scopes []string
CSRFBinding string
// DecisionProof must be the server-held proof returned by details retrieval.
DecisionProof Secret
}
func (AuthorizationDecisionRequest) Validate ¶ added in v0.45.0
func (r AuthorizationDecisionRequest) Validate(action ProviderOperationAction, provider, environment string, now time.Time) error
type AuthorizationDecisionResult ¶ added in v0.45.0
type AuthorizationDecisionResult struct {
ProviderOperationOutcome
RedirectURL string
}
func (AuthorizationDecisionResult) Format ¶ added in v0.45.0
func (r AuthorizationDecisionResult) Format(state fmt.State, _ rune)
func (AuthorizationDecisionResult) GoString ¶ added in v0.45.0
func (r AuthorizationDecisionResult) GoString() string
func (AuthorizationDecisionResult) HTTPRedirectURL ¶ added in v0.45.0
func (r AuthorizationDecisionResult) HTTPRedirectURL() string
func (AuthorizationDecisionResult) LogValue ¶ added in v0.45.0
func (r AuthorizationDecisionResult) LogValue() slog.Value
func (AuthorizationDecisionResult) MarshalJSON ¶ added in v0.45.0
func (r AuthorizationDecisionResult) MarshalJSON() ([]byte, error)
func (AuthorizationDecisionResult) String ¶ added in v0.45.0
func (r AuthorizationDecisionResult) String() string
func (AuthorizationDecisionResult) ValidateRedirect ¶ added in v0.45.0
func (r AuthorizationDecisionResult) ValidateRedirect(allow func(*url.URL) bool) error
type AuthorizationDecisionService ¶ added in v0.45.0
type AuthorizationDecisionService interface {
GetAuthorizationDetails(context.Context, AuthorizationDetailsRequest) (AuthorizationDetails, error)
ApproveAuthorization(context.Context, AuthorizationDecisionRequest) (AuthorizationDecisionResult, error)
DenyAuthorization(context.Context, AuthorizationDecisionRequest) (AuthorizationDecisionResult, error)
}
type AuthorizationDetails ¶ added in v0.45.0
type AuthorizationDetails struct {
AuthorizationID string
ClientID string
ClientName string
Scopes []string
RedirectURL string
ExpiresAt time.Time
// DecisionProof is server-held, tamper-evident continuity state. It is
// intentionally omitted from JSON and default formatting.
DecisionProof Secret
}
func (AuthorizationDetails) Clone ¶ added in v0.45.0
func (d AuthorizationDetails) Clone() AuthorizationDetails
func (AuthorizationDetails) MarshalJSON ¶ added in v0.45.0
func (d AuthorizationDetails) MarshalJSON() ([]byte, error)
type AuthorizationDetailsRequest ¶ added in v0.45.0
type AuthorizationDetailsRequest struct {
Operation AuthorizedOperationContext
Continuation AuthorizationContinuation
Session ProviderUserSession
}
type AuthorizationFreshnessGuard ¶ added in v0.45.0
type AuthorizationFreshnessGuard struct {
// contains filtered or unexported fields
}
AuthorizationFreshnessGuard composes current session, assurance, account state, permission version, and current permission checks.
func NewAuthorizationFreshnessGuard ¶ added in v0.45.0
func NewAuthorizationFreshnessGuard(cfg AuthorizationFreshnessGuardConfig) (*AuthorizationFreshnessGuard, error)
func (*AuthorizationFreshnessGuard) Authorize ¶ added in v0.45.0
func (g *AuthorizationFreshnessGuard) Authorize( ctx context.Context, request AuthorizationFreshnessRequest, ) (AuthorizationFreshnessResult, error)
type AuthorizationFreshnessGuardConfig ¶ added in v0.45.0
type AuthorizationFreshnessGuardConfig struct {
Policy *FreshnessPolicy
AccountStates AccountStateResolver
PermissionVersions PermissionVersionResolver
Permissions PermissionResolverFunc
Assurance AssuranceGuard
ActivitySink ActivitySink
Now func() time.Time
}
type AuthorizationFreshnessRequest ¶ added in v0.45.0
type AuthorizationFreshnessRequest struct {
Operation string
// Role is retained for source compatibility but is not authorization
// evidence. The guard selects policy from PermissionVersionResult.Role.
// Deprecated: populate the authoritative role in PermissionVersionResult.
Role string
Principal AuthenticatedPrincipal
}
type AuthorizationFreshnessResult ¶ added in v0.45.0
type AuthorizationFreshnessResult struct {
Decision FreshnessDecision
Reason FreshnessReason
Operation string
Policy FreshnessOperationPolicy
Assurance AssuranceResult
AccountState AccountStateResolution
SessionVersion string
CurrentVersion string
CurrentRole string
Permissions []string
PermissionsRefreshed bool
}
type AuthorizationMutation ¶ added in v0.45.0
AuthorizationMutation is executed inside the host authorization transaction that also advances the permission version.
type AuthorizationVersionEvent ¶ added in v0.45.0
type AuthorizationVersionPublisher ¶ added in v0.45.0
type AuthorizationVersionPublisher interface {
PublishAuthorizationVersion(context.Context, AuthorizationVersionEvent) error
}
type AuthorizationVersionPublisherFunc ¶ added in v0.45.0
type AuthorizationVersionPublisherFunc func(context.Context, AuthorizationVersionEvent) error
func (AuthorizationVersionPublisherFunc) PublishAuthorizationVersion ¶ added in v0.45.0
func (f AuthorizationVersionPublisherFunc) PublishAuthorizationVersion(ctx context.Context, event AuthorizationVersionEvent) error
type AuthorizationVersionStore ¶ added in v0.45.0
type AuthorizationVersionStore interface {
CurrentAuthorizationVersion(context.Context, string, string) (PermissionVersionResult, error)
AdvanceAuthorizationVersion(context.Context, string, string, string, AuthorizationMutation) (PermissionVersionResult, error)
}
AuthorizationVersionStore is the host-owned atomic transaction boundary.
type AuthorizationVersionWriteResult ¶ added in v0.45.0
type AuthorizationVersionWriteResult struct {
Event AuthorizationVersionEvent
Committed bool
Published bool
}
type AuthorizationVersionWriter ¶ added in v0.45.0
type AuthorizationVersionWriter struct {
Store AuthorizationVersionStore
Publisher AuthorizationVersionPublisher
Now func() time.Time
}
AuthorizationVersionWriter publishes only after the store's atomic mutation and version advance have committed.
func (AuthorizationVersionWriter) Advance ¶ added in v0.45.0
func (w AuthorizationVersionWriter) Advance( ctx context.Context, operationID, applicationSubject, tenantID string, mutation AuthorizationMutation, ) (AuthorizationVersionWriteResult, error)
type AuthorizedOperationContext ¶ added in v0.45.0
type AuthorizedOperationContext struct {
OperationID string
Action ProviderOperationAction
Permission string
Actor ActorRef
Target ProviderOperationTarget
Reason string
Environment string
RequestID string
ProviderSessionID string
AuthorizedAt time.Time
}
AuthorizedOperationContext is a typed proof that the host authorized one exact provider operation. It deliberately contains no credential or token.
func (AuthorizedOperationContext) Validate ¶ added in v0.45.0
func (c AuthorizedOperationContext) Validate(expected ProviderOperationAction, environment, provider string) error
Validate verifies that the proof is complete and bound to the expected action, environment, and target provider before any transport work occurs.
type BrowserProtectionConfig ¶ added in v0.37.0
type BrowserProtectionConfig struct {
AuthCookieName string
CSRF csrf.Config
Origin router.OriginProtectionConfig
}
type CachedPermissionsResolver ¶ added in v0.32.0
type CachedPermissionsResolver struct {
// contains filtered or unexported fields
}
CachedPermissionsResolver wraps a permission resolver with key-based TTL caching and singleflight deduplication to prevent query amplification under load.
func NewCachedPermissionsResolver ¶ added in v0.32.0
func NewCachedPermissionsResolver(cfg CachedPermissionsResolverConfig) *CachedPermissionsResolver
NewCachedPermissionsResolver builds a CachedPermissionsResolver. When cfg.TTL <= 0, cross-request storage is disabled but singleflight deduplication still applies.
func (*CachedPermissionsResolver) Invalidate ¶ added in v0.32.0
func (r *CachedPermissionsResolver) Invalidate(ctx context.Context, key string) error
Invalidate removes a single cache key.
func (*CachedPermissionsResolver) InvalidateScope ¶ added in v0.45.0
func (r *CachedPermissionsResolver) InvalidateScope( ctx context.Context, scope PermissionInvalidationScope, limit int, ) (deleted int, more bool, err error)
InvalidateScope removes at most limit indexed entries. Callers retry while more=true; no implementation is allowed to fall back to a full key scan.
func (*CachedPermissionsResolver) PurgeExpired ¶ added in v0.32.0
func (r *CachedPermissionsResolver) PurgeExpired(ctx context.Context) (int, error)
PurgeExpired deletes stale cache entries when the configured store supports it.
func (*CachedPermissionsResolver) ResolvePermissions ¶ added in v0.32.0
func (r *CachedPermissionsResolver) ResolvePermissions(ctx context.Context) ([]string, error)
ResolvePermissions resolves permissions with cache + singleflight safeguards.
func (*CachedPermissionsResolver) ResolverFunc ¶ added in v0.32.0
func (r *CachedPermissionsResolver) ResolverFunc() PermissionResolverFunc
ResolverFunc returns the wrapped resolver function.
func (*CachedPermissionsResolver) Stats ¶ added in v0.32.0
func (r *CachedPermissionsResolver) Stats() PermissionResolverStats
Stats returns a copy of the internal counters.
func (*CachedPermissionsResolver) Store ¶ added in v0.33.0
func (r *CachedPermissionsResolver) Store() PermissionCacheStore
Store returns the configured cache store implementation.
type CachedPermissionsResolverConfig ¶ added in v0.32.0
type CachedPermissionsResolverConfig struct {
Resolver PermissionResolverFunc
KeyFunc PermissionCacheKeyFunc
Store PermissionCacheStore
TTL time.Duration
// ResolutionTimeout bounds shared backend work independently from any one
// caller. Zero uses DefaultPermissionResolutionTimeout.
ResolutionTimeout time.Duration
CacheErrorMode PermissionCacheErrorMode
Logger Logger
}
CachedPermissionsResolverConfig configures the cross-request resolver cache.
type ClaimsDecorator ¶ added in v0.14.0
type ClaimsDecorator interface {
Decorate(ctx context.Context, identity Identity, claims *JWTClaims) error
}
ClaimsDecorator can mutate allowed JWT claim extensions before a token is signed. Implementations may only touch extension fields (e.g. Resources, Metadata) and must leave registered/identity claims untouched so core auth semantics stay stable.
func TemporaryPasswordClaimsDecorator ¶ added in v0.41.0
func TemporaryPasswordClaimsDecorator() ClaimsDecorator
TemporaryPasswordClaimsDecorator copies compact temporary-password hints into JWT metadata.
type ClaimsDecoratorFunc ¶ added in v0.14.0
ClaimsDecoratorFunc adapts a function into a ClaimsDecorator.
type CompositeAccountStateResolver ¶ added in v0.45.0
type CompositeAccountStateResolver struct {
// contains filtered or unexported fields
}
CompositeAccountStateResolver evaluates every configured authoritative source. Hard denies win; privileged ambiguity and outage fail closed.
func NewCompositeAccountStateResolver ¶ added in v0.45.0
func NewCompositeAccountStateResolver(cfg CompositeAccountStateResolverConfig) (*CompositeAccountStateResolver, error)
func (*CompositeAccountStateResolver) InvalidateAccountState ¶ added in v0.45.0
func (r *CompositeAccountStateResolver) InvalidateAccountState(_ context.Context, applicationSubject, tenantID string) error
func (*CompositeAccountStateResolver) InvalidateAccountStates ¶ added in v0.45.0
func (r *CompositeAccountStateResolver) InvalidateAccountStates( _ context.Context, scope PermissionInvalidationScope, limit int, ) (int, bool, error)
func (*CompositeAccountStateResolver) ResolveCurrentAccountState ¶ added in v0.45.0
func (r *CompositeAccountStateResolver) ResolveCurrentAccountState( ctx context.Context, request AccountStateRequest, ) (AccountStateResolution, error)
type CompositeAccountStateResolverConfig ¶ added in v0.45.0
type CompositeAccountStateResolverConfig struct {
Sources []NamedAccountStateSource
CacheTTL time.Duration
Now func() time.Time
}
type Config ¶
type Config interface {
GetSigningKey() string
GetSigningMethod() string
GetContextKey() string
GetTokenExpiration() int
GetExtendedTokenDuration() int
GetTokenLookup() string
GetAuthScheme() string
GetIssuer() string
GetAudience() []string
GetRejectedRouteKey() string
GetRejectedRouteDefault() string
}
Config holds auth options
type CoordinatedProviderOperationExecutor ¶ added in v0.45.0
type CoordinatedProviderOperationExecutor interface {
ExecuteCoordinatedProviderOperation(
context.Context,
AuthorizedOperationContext,
LifecycleExecutionPermit,
) (ProviderOperationOutcome, error)
}
type CoordinatedProviderOperationExecutorFunc ¶ added in v0.45.0
type CoordinatedProviderOperationExecutorFunc func( context.Context, AuthorizedOperationContext, LifecycleExecutionPermit, ) (ProviderOperationOutcome, error)
func (CoordinatedProviderOperationExecutorFunc) ExecuteCoordinatedProviderOperation ¶ added in v0.45.0
func (f CoordinatedProviderOperationExecutorFunc) ExecuteCoordinatedProviderOperation( ctx context.Context, operation AuthorizedOperationContext, permit LifecycleExecutionPermit, ) (ProviderOperationOutcome, error)
type CurrentPermissionsRequest ¶ added in v0.45.0
type CurrentPermissionsRequest struct {
Principal AuthenticatedPrincipal
Version string
Role string
SessionID string
// ForceRefresh bypasses every cross-request cache lookup. A successful
// authoritative result may still replace the entry under the current key.
ForceRefresh bool
}
CurrentPermissionsRequest binds permission resolution to the normalized principal and authoritative authorization version selected by the freshness guard. SessionID is the local provider-session ID when one is available.
func CurrentPermissionsRequestFromContext ¶ added in v0.45.0
func CurrentPermissionsRequestFromContext(ctx context.Context) (CurrentPermissionsRequest, bool)
CurrentPermissionsRequestFromContext returns a defensive copy of the authoritative permission-resolution request.
type EmergencyAccessDecision ¶ added in v0.45.0
type EmergencyAccessDecision string
const ( EmergencyAccessAllowed EmergencyAccessDecision = "allowed" EmergencyAccessDenied EmergencyAccessDecision = "denied" )
type EmergencyAccessGrant ¶ added in v0.45.0
type EmergencyAccessGrantResolver ¶ added in v0.45.0
type EmergencyAccessGrantResolver interface {
ResolveEmergencyAccessGrant(context.Context, string) (IssuedEmergencyAccessGrant, error)
}
type EmergencyAccessGrantResolverFunc ¶ added in v0.45.0
type EmergencyAccessGrantResolverFunc func(context.Context, string) (IssuedEmergencyAccessGrant, error)
func (EmergencyAccessGrantResolverFunc) ResolveEmergencyAccessGrant ¶ added in v0.45.0
func (f EmergencyAccessGrantResolverFunc) ResolveEmergencyAccessGrant( ctx context.Context, grantID string, ) (IssuedEmergencyAccessGrant, error)
type EmergencyAccessPolicy ¶ added in v0.45.0
type EmergencyAccessPolicy struct {
// contains filtered or unexported fields
}
func NewEmergencyAccessPolicy ¶ added in v0.45.0
func NewEmergencyAccessPolicy(cfg EmergencyAccessPolicyConfig) (*EmergencyAccessPolicy, error)
func (*EmergencyAccessPolicy) Authorize
deprecated
added in
v0.45.0
func (p *EmergencyAccessPolicy) Authorize( ctx context.Context, grant EmergencyAccessGrant, operation, credentialClass string, ) (EmergencyAccessResult, error)
Authorize validates a caller-constructed compatibility grant.
Deprecated: use AuthorizeGrant with an authoritative resolver and isolated credential verifier.
func (*EmergencyAccessPolicy) AuthorizeGrant ¶ added in v0.45.0
func (p *EmergencyAccessPolicy) AuthorizeGrant( ctx context.Context, grantID, operation string, presentedProof Secret, ) (EmergencyAccessResult, error)
AuthorizeGrant resolves immutable issuance data and independently verifies opaque isolated-credential evidence. Caller-supplied labels are never used as authority.
func (*EmergencyAccessPolicy) Revoke
deprecated
added in
v0.45.0
func (p *EmergencyAccessPolicy) Revoke( ctx context.Context, grantID, actorID, reason string, ) error
Revoke revokes a caller-constructed compatibility grant by logical ID.
Deprecated: authoritative policies require RevokeIssuedGrant so revocation is bound to the same immutable grant version checked by AuthorizeGrant.
func (*EmergencyAccessPolicy) RevokeIssuedGrant ¶ added in v0.45.0
func (p *EmergencyAccessPolicy) RevokeIssuedGrant( ctx context.Context, grantID, grantVersion, actorID, reason string, ) error
RevokeIssuedGrant revokes one immutable grant version without affecting a separately issued version with the same logical grant identifier.
type EmergencyAccessPolicyConfig ¶ added in v0.45.0
type EmergencyAccessPolicyConfig struct {
Owner string
ApprovedAt time.Time
PolicyVersion string
CredentialClass string
AllowedOperations []string
ApprovedApprovers []string
RequiredApprovals int
MaxDuration time.Duration
MonitoringDestination string
ExerciseCadence time.Duration
Revocations EmergencyAccessRevocationResolver
Revoker EmergencyAccessRevoker
GrantResolver EmergencyAccessGrantResolver
CredentialVerifier EmergencyCredentialVerifier
// AllowLegacyAuthorize permits the deprecated caller-constructed grant API.
// Hardened deployments must leave it false.
AllowLegacyAuthorize bool
ActivitySink ActivitySink
Now func() time.Time
}
type EmergencyAccessReason ¶ added in v0.45.0
type EmergencyAccessReason string
const ( EmergencyAccessReasonAllowed EmergencyAccessReason = "allowed" EmergencyAccessReasonInvalidGrant EmergencyAccessReason = "invalid_grant" EmergencyAccessReasonCredential EmergencyAccessReason = "credential_isolation" // #nosec G101 -- Audit reason code, not a credential. EmergencyAccessReasonScope EmergencyAccessReason = "scope_violation" EmergencyAccessReasonExpired EmergencyAccessReason = "expired" EmergencyAccessReasonRevoked EmergencyAccessReason = "revoked" EmergencyAccessReasonDependencyOutage EmergencyAccessReason = "dependency_outage" EmergencyAccessReasonAuditFailure EmergencyAccessReason = "audit_failure" )
type EmergencyAccessResult ¶ added in v0.45.0
type EmergencyAccessResult struct {
Decision EmergencyAccessDecision
Reason EmergencyAccessReason
GrantID string
GrantVersion string
ActorID string
Operation string
ExpiresAt time.Time
}
type EmergencyAccessRevocationResolver ¶ added in v0.45.0
type EmergencyAccessRevocationResolverFunc ¶ added in v0.45.0
func (EmergencyAccessRevocationResolverFunc) EmergencyAccessRevoked ¶ added in v0.45.0
type EmergencyAccessRevoker ¶ added in v0.45.0
type EmergencyAccessRevokerFunc ¶ added in v0.45.0
func (EmergencyAccessRevokerFunc) RevokeEmergencyAccess ¶ added in v0.45.0
func (f EmergencyAccessRevokerFunc) RevokeEmergencyAccess(ctx context.Context, grantID, reason string) error
type EmergencyCredentialVerification ¶ added in v0.45.0
type EmergencyCredentialVerifier ¶ added in v0.45.0
type EmergencyCredentialVerifier interface {
VerifyEmergencyCredential(
context.Context,
IssuedEmergencyAccessGrant,
Secret,
) (EmergencyCredentialVerification, error)
}
type EmergencyCredentialVerifierFunc ¶ added in v0.45.0
type EmergencyCredentialVerifierFunc func( context.Context, IssuedEmergencyAccessGrant, Secret, ) (EmergencyCredentialVerification, error)
func (EmergencyCredentialVerifierFunc) VerifyEmergencyCredential ¶ added in v0.45.0
func (f EmergencyCredentialVerifierFunc) VerifyEmergencyCredential( ctx context.Context, grant IssuedEmergencyAccessGrant, proof Secret, ) (EmergencyCredentialVerification, error)
type FactorLifecycle ¶ added in v0.45.0
type FactorLifecycle interface {
ListFactors(context.Context, FactorListRequest) (ProviderFactorsResult, error)
RemoveFactor(context.Context, FactorRemoveRequest) (ProviderOperationOutcome, error)
}
type FactorListRequest ¶ added in v0.45.0
type FactorListRequest struct {
Operation AuthorizedOperationContext
}
type FactorRemoveRequest ¶ added in v0.45.0
type FactorRemoveRequest struct {
Operation AuthorizedOperationContext
FactorID string
// KnownState is an optional optimistic-concurrency expectation. Provider
// implementations must derive security behavior from authoritative state.
KnownState ProviderFactorState
// RemainingVerifiedFactors is an optional expectation for the authoritative
// verified-factor count. A zero value means no caller expectation.
RemainingVerifiedFactors int
AllowLastVerified bool
}
type FieldsLogger ¶ added in v0.31.0
type FieldsLogger = glog.FieldsLogger
type FinalizePasswordResetHandler ¶
type FinalizePasswordResetHandler struct {
// contains filtered or unexported fields
}
func NewFinalizePasswordResetHandler ¶ added in v0.14.0
func NewFinalizePasswordResetHandler(repo RepositoryManager) *FinalizePasswordResetHandler
NewFinalizePasswordResetHandler creates a handler with sane defaults.
func (*FinalizePasswordResetHandler) Execute ¶
func (h *FinalizePasswordResetHandler) Execute(ctx context.Context, event FinalizePasswordResetMesasge) error
func (*FinalizePasswordResetHandler) WithActivitySink ¶ added in v0.14.0
func (h *FinalizePasswordResetHandler) WithActivitySink(sink ActivitySink) *FinalizePasswordResetHandler
WithActivitySink sets the sink used to emit password reset events.
func (*FinalizePasswordResetHandler) WithFeatureGate ¶ added in v0.26.0
func (h *FinalizePasswordResetHandler) WithFeatureGate(featureGate gate.FeatureGate) *FinalizePasswordResetHandler
WithFeatureGate sets the feature gate used to authorize reset completion.
func (*FinalizePasswordResetHandler) WithLogger ¶ added in v0.14.0
func (h *FinalizePasswordResetHandler) WithLogger(logger Logger) *FinalizePasswordResetHandler
WithLogger overrides the logger used by the handler.
func (*FinalizePasswordResetHandler) WithLoggerProvider ¶ added in v0.31.0
func (h *FinalizePasswordResetHandler) WithLoggerProvider(provider LoggerProvider) *FinalizePasswordResetHandler
WithLoggerProvider overrides the logger provider used by the handler.
type FormattedLogger ¶ added in v0.31.0
type FormattedLogger = compat.FormattedLogger
func ToFormattedLogger ¶ added in v0.31.0
func ToFormattedLogger(logger Logger) FormattedLogger
ToFormattedLogger adapts a glog.Logger into a format-style logger.
type FreshnessDecision ¶ added in v0.45.0
type FreshnessDecision string
const ( FreshnessAllowed FreshnessDecision = "allowed" FreshnessDenied FreshnessDecision = "denied" FreshnessStepUp FreshnessDecision = "step_up_required" )
type FreshnessInvalidationCoordinator ¶ added in v0.45.0
type FreshnessInvalidationCoordinator struct {
// contains filtered or unexported fields
}
FreshnessInvalidationCoordinator consumes normalized results only. It never calls a remote provider, and lifecycle consumption never repeats the coordinator's local-first session revocation.
func NewFreshnessInvalidationCoordinator ¶ added in v0.45.0
func NewFreshnessInvalidationCoordinator( cfg FreshnessInvalidationCoordinatorConfig, ) (*FreshnessInvalidationCoordinator, error)
func (*FreshnessInvalidationCoordinator) ConsumeAuthorizationVersion ¶ added in v0.45.0
func (c *FreshnessInvalidationCoordinator) ConsumeAuthorizationVersion( ctx context.Context, event AuthorizationVersionEvent, revokeSessions bool, ) (FreshnessInvalidationResult, error)
func (*FreshnessInvalidationCoordinator) ConsumeLifecycleResult ¶ added in v0.45.0
func (c *FreshnessInvalidationCoordinator) ConsumeLifecycleResult( ctx context.Context, request LifecycleFreshnessRequest, ) (FreshnessInvalidationResult, error)
func (*FreshnessInvalidationCoordinator) InvalidateLifecycleFreshness ¶ added in v0.45.0
func (c *FreshnessInvalidationCoordinator) InvalidateLifecycleFreshness( ctx context.Context, request LifecycleFreshnessRequest, ) error
type FreshnessInvalidationCoordinatorConfig ¶ added in v0.45.0
type FreshnessInvalidationCoordinatorConfig struct {
Permissions PermissionScopeInvalidator
AccountStates AccountStateScopeInvalidator
Sessions ProviderSessionScopeInvalidator
BatchLimit int
ResultTTL time.Duration
MaxResults int
ActivitySink ActivitySink
Now func() time.Time
}
type FreshnessInvalidationResult ¶ added in v0.45.0
type FreshnessOperationPolicy ¶ added in v0.45.0
type FreshnessPolicy ¶ added in v0.45.0
type FreshnessPolicy struct {
// contains filtered or unexported fields
}
FreshnessPolicy is immutable after construction.
func NewFreshnessPolicy ¶ added in v0.45.0
func NewFreshnessPolicy(cfg FreshnessPolicyConfig) (*FreshnessPolicy, error)
func (*FreshnessPolicy) ApprovedAt ¶ added in v0.45.0
func (p *FreshnessPolicy) ApprovedAt() time.Time
func (*FreshnessPolicy) Operation ¶ added in v0.45.0
func (p *FreshnessPolicy) Operation(operation, role string) (FreshnessOperationPolicy, error)
func (*FreshnessPolicy) Owner ¶ added in v0.45.0
func (p *FreshnessPolicy) Owner() string
func (*FreshnessPolicy) PropagationTarget ¶ added in v0.45.0
func (p *FreshnessPolicy) PropagationTarget() time.Duration
type FreshnessPolicyConfig ¶ added in v0.45.0
type FreshnessPolicyConfig struct {
Owner string
ApprovedAt time.Time
PropagationTarget time.Duration
Operations []FreshnessOperationPolicy
RoleOverrides []RoleFreshnessPolicy
}
type FreshnessReason ¶ added in v0.45.0
type FreshnessReason string
const ( FreshnessReasonSatisfied FreshnessReason = "satisfied" FreshnessReasonUnknownOperation FreshnessReason = "unknown_operation" FreshnessReasonSessionInvalid FreshnessReason = "session_invalid" FreshnessReasonAssurance FreshnessReason = "assurance" FreshnessReasonAccountState FreshnessReason = "account_state" FreshnessReasonPermissionVersion FreshnessReason = "permission_version" FreshnessReasonPermissionDenied FreshnessReason = "permission_denied" FreshnessReasonDependencyOutage FreshnessReason = "dependency_outage" )
type HTTPAuthenticator ¶
type HTTPAuthenticator interface {
Middleware
Login(c router.Context, payload LoginPayload) error
Logout(c router.Context)
SetRedirect(c router.Context)
GetRedirect(c router.Context, def ...string) string
GetRedirectOrDefault(c router.Context) string
MakeClientRouteAuthErrorHandler(optionalAuth bool) func(c router.Context, err error) error
}
type HTTPAuthenticatorOption ¶ added in v0.37.0
type HTTPAuthenticatorOption func(*RouteAuthenticator) error
func WithAuthCookieTemplate ¶ added in v0.37.0
func WithAuthCookieTemplate(cookie router.Cookie) HTTPAuthenticatorOption
func WithRedirectCookieTemplate ¶ added in v0.37.0
func WithRedirectCookieTemplate(cookie router.Cookie) HTTPAuthenticatorOption
type HookErrorHandler ¶ added in v0.15.0
type HookErrorHandler func(ctx context.Context, phase TransitionHookPhase, err error, tc TransitionContext) error
HookErrorHandler handles errors surfaced by transition hooks.
type IdentifierStore ¶ added in v0.44.0
type IdentifierStore interface {
FindUserID(ctx context.Context, provider, identifier string) (string, error)
Upsert(ctx context.Context, userID, provider, identifier string) error
Delete(ctx context.Context, userID, provider, identifier string) error
}
IdentifierStore maps external provider identifiers to local user IDs.
type Identity ¶
Identity holds the attributes of an identity
func NewIdentityFromUser ¶ added in v0.24.0
NewIdentityFromUser returns an Identity adapter for the provided user.
type IdentityLifecycle ¶ added in v0.45.0
type IdentityLifecycle interface {
Invite(context.Context, InviteRequest) (ProviderDeliveryOutcome, error)
StartRecovery(context.Context, RecoveryRequest) (ProviderDeliveryOutcome, error)
}
type IdentityProvider ¶
type IdentityProvider interface {
VerifyIdentity(ctx context.Context, identifier, password string) (Identity, error)
FindIdentityByIdentifier(ctx context.Context, identifier string) (Identity, error)
}
IdentityProvider ensure we have a store to retrieve auth identity
type ImmutableIdentifierStore ¶ added in v0.45.0
type ImmutableIdentifierStore interface {
IdentifierStore
Bind(ctx context.Context, userID, provider, identifier string) error
}
ImmutableIdentifierStore binds an external provider identifier exactly once. Repeating the same binding is idempotent; binding it to a different user must return ErrIdentifierConflict.
type InMemoryAuthorizationVersionStore ¶ added in v0.45.0
type InMemoryAuthorizationVersionStore struct {
// contains filtered or unexported fields
}
InMemoryAuthorizationVersionStore is a concurrency-safe reference store for tests and single-process hosts. Durable hosts should implement the same transaction boundary in their authorization database.
func NewInMemoryAuthorizationVersionStore ¶ added in v0.45.0
func NewInMemoryAuthorizationVersionStore(now func() time.Time) *InMemoryAuthorizationVersionStore
func (*InMemoryAuthorizationVersionStore) AdvanceAuthorizationVersion ¶ added in v0.45.0
func (s *InMemoryAuthorizationVersionStore) AdvanceAuthorizationVersion( ctx context.Context, applicationSubject, tenantID, operationID string, mutation AuthorizationMutation, ) (PermissionVersionResult, error)
func (*InMemoryAuthorizationVersionStore) CurrentAuthorizationVersion ¶ added in v0.45.0
func (s *InMemoryAuthorizationVersionStore) CurrentAuthorizationVersion( _ context.Context, applicationSubject, tenantID string, ) (PermissionVersionResult, error)
type InMemoryLifecycleOperationStore ¶ added in v0.45.0
type InMemoryLifecycleOperationStore struct {
// contains filtered or unexported fields
}
InMemoryLifecycleOperationStore is an explicit development and compatibility store. It is process-local and must not be used when durable coordination is required.
func NewInMemoryLifecycleOperationStore ¶ added in v0.45.0
func NewInMemoryLifecycleOperationStore(now func() time.Time) *InMemoryLifecycleOperationStore
func (*InMemoryLifecycleOperationStore) Advance ¶ added in v0.45.0
func (s *InMemoryLifecycleOperationStore) Advance( _ context.Context, expectedRevision int64, next LifecycleOperationRecord, ) (LifecycleOperationRecord, error)
func (*InMemoryLifecycleOperationStore) Claim ¶ added in v0.45.0
func (s *InMemoryLifecycleOperationStore) Claim( _ context.Context, claim LifecycleOperationClaim, ) (LifecycleOperationRecord, LifecycleOperationClaimDisposition, error)
func (*InMemoryLifecycleOperationStore) ClaimPending ¶ added in v0.45.0
func (s *InMemoryLifecycleOperationStore) ClaimPending( _ context.Context, policy LifecycleOperationPendingPolicy, ) ([]LifecycleOperationRecord, error)
func (*InMemoryLifecycleOperationStore) Durable ¶ added in v0.45.0
func (s *InMemoryLifecycleOperationStore) Durable() bool
func (*InMemoryLifecycleOperationStore) Load ¶ added in v0.45.0
func (s *InMemoryLifecycleOperationStore) Load( _ context.Context, operationID string, ) (LifecycleOperationRecord, error)
type InMemoryPermissionCacheStore ¶ added in v0.33.0
type InMemoryPermissionCacheStore struct {
// contains filtered or unexported fields
}
InMemoryPermissionCacheStore is the default PermissionCacheStore implementation.
func NewInMemoryPermissionCacheStore ¶ added in v0.33.0
func NewInMemoryPermissionCacheStore(cfg InMemoryPermissionCacheStoreConfig) *InMemoryPermissionCacheStore
NewInMemoryPermissionCacheStore builds an in-memory permission cache store.
func (*InMemoryPermissionCacheStore) Delete ¶ added in v0.33.0
func (s *InMemoryPermissionCacheStore) Delete(_ context.Context, key string) error
Delete removes a key from the store.
func (*InMemoryPermissionCacheStore) DeletePermissionCacheScope ¶ added in v0.45.0
func (s *InMemoryPermissionCacheStore) DeletePermissionCacheScope( _ context.Context, scope PermissionInvalidationScope, limit int, ) (int, bool, error)
func (*InMemoryPermissionCacheStore) Get ¶ added in v0.33.0
Get returns cached permissions when the key exists and has not expired.
func (*InMemoryPermissionCacheStore) IndexPermissionCacheKey ¶ added in v0.45.0
func (s *InMemoryPermissionCacheStore) IndexPermissionCacheKey( _ context.Context, key string, scope PermissionInvalidationScope, ) error
func (*InMemoryPermissionCacheStore) PurgeExpired ¶ added in v0.33.0
func (s *InMemoryPermissionCacheStore) PurgeExpired(_ context.Context) (int, error)
PurgeExpired removes all expired entries and returns the number of keys removed.
func (*InMemoryPermissionCacheStore) Set ¶ added in v0.33.0
func (s *InMemoryPermissionCacheStore) Set(_ context.Context, key string, permissions []string, ttl time.Duration) error
Set stores permissions for the provided key and ttl. ttl<=0 removes the key.
func (*InMemoryPermissionCacheStore) SetPermissionCacheEntry ¶ added in v0.45.0
func (s *InMemoryPermissionCacheStore) SetPermissionCacheEntry( _ context.Context, key string, permissions []string, ttl time.Duration, scope PermissionInvalidationScope, ) error
type InMemoryPermissionCacheStoreConfig ¶ added in v0.33.0
type InMemoryPermissionCacheStoreConfig struct {
// PurgeInterval throttles opportunistic cleanup on writes.
// Zero applies a sensible default.
PurgeInterval time.Duration
// Now can be provided in tests to control time.
Now func() time.Time
}
InMemoryPermissionCacheStoreConfig configures the default in-memory permission cache store.
type IndexedPermissionCacheStore ¶ added in v0.45.0
type IndexedPermissionCacheStore interface {
PermissionCacheStore
IndexPermissionCacheKey(ctx context.Context, key string, scope PermissionInvalidationScope) error
DeletePermissionCacheScope(ctx context.Context, scope PermissionInvalidationScope, limit int) (deleted int, more bool, err error)
}
IndexedPermissionCacheStore is the additive bounded-invalidation contract.
type InitializePasswordResetHandler ¶
type InitializePasswordResetHandler struct {
// contains filtered or unexported fields
}
func NewInitializePasswordResetHandler ¶ added in v0.26.0
func NewInitializePasswordResetHandler(repo RepositoryManager) *InitializePasswordResetHandler
func (*InitializePasswordResetHandler) Execute ¶
func (h *InitializePasswordResetHandler) Execute(ctx context.Context, event InitializePasswordResetMessage) error
func (*InitializePasswordResetHandler) WithDelivery ¶ added in v0.45.0
func (h *InitializePasswordResetHandler) WithDelivery(delivery PasswordResetDelivery) *InitializePasswordResetHandler
WithDelivery configures the trusted out-of-band reset credential delivery.
func (*InitializePasswordResetHandler) WithFeatureGate ¶ added in v0.26.0
func (h *InitializePasswordResetHandler) WithFeatureGate(featureGate gate.FeatureGate) *InitializePasswordResetHandler
func (*InitializePasswordResetHandler) WithLogger ¶ added in v0.45.0
func (h *InitializePasswordResetHandler) WithLogger(logger Logger) *InitializePasswordResetHandler
WithLogger overrides the logger used by the handler.
func (*InitializePasswordResetHandler) WithLoggerProvider ¶ added in v0.45.0
func (h *InitializePasswordResetHandler) WithLoggerProvider(provider LoggerProvider) *InitializePasswordResetHandler
WithLoggerProvider overrides the logger provider used by the handler.
type InitializePasswordResetMessage ¶
type InitializePasswordResetMessage struct {
Stage string `json:"stage" example:"Rone" doc:"Customer last name."`
Session string `json:"session" example:"350399bc-c095-4bdc-a59c-3352d44848e4" doc:"Reset password session token"`
Email string `json:"email" example:"pepe.rone@example.com" doc:"Customer email."`
OnResponse func(resp *InitializePasswordResetResponse)
}
func (InitializePasswordResetMessage) Type ¶
func (p InitializePasswordResetMessage) Type() string
type InitializePasswordResetResponse ¶
type InitializePasswordResetResponse struct {
// Reset is retained for source compatibility. Password reset credentials
// are never returned through command responses.
Reset *PasswordReset
Stage string
Success bool
}
type InviteRequest ¶ added in v0.45.0
type InviteRequest struct {
Operation AuthorizedOperationContext
Email string
ReturnURL string
}
type IssuedEmergencyAccessGrant ¶ added in v0.45.0
type IssuedEmergencyAccessGrant struct {
EmergencyAccessGrant
Version string
PolicyVersion string
}
type JWTClaims ¶ added in v0.7.0
type JWTClaims struct {
jwt.RegisteredClaims
UID string `json:"uid,omitempty"`
UserRole string `json:"role,omitempty"`
Resources map[string]string `json:"res,omitempty"` // resource -> role mapping
Metadata map[string]any `json:"metadata,omitempty"` // extension payload
Scopes []string `json:"scopes,omitempty"` // optional scopes (e.g., debug tokens)
Use string `json:"token_use,omitempty"`
}
JWTClaims is the concrete implementation of AuthClaims
func (*JWTClaims) CanCreate ¶ added in v0.7.0
CanCreate checks if the user can create a specific resource
func (*JWTClaims) CanDelete ¶ added in v0.7.0
CanDelete checks if the user can delete a specific resource
func (*JWTClaims) ClaimsMetadata ¶ added in v0.15.0
ClaimsMetadata exposes metadata extensions for optional context enrichment.
func (*JWTClaims) HasRole ¶ added in v0.7.0
HasRole checks if the user has a specific role (either global or for any resource)
func (*JWTClaims) IsAtLeast ¶ added in v0.7.0
IsAtLeast checks if the user's role is at least the minimum required role
func (*JWTClaims) ResourceRoles ¶ added in v0.15.0
ResourceRoles exposes resource-specific roles for optional context enrichment.
type LegacyLogger ¶ added in v0.31.0
type LegacyLogger interface {
Debug(format string, args ...any)
Info(format string, args ...any)
Warn(format string, args ...any)
Error(format string, args ...any)
}
LegacyLogger matches the historical go-auth logging contract.
type LifecycleActionPolicy ¶ added in v0.45.0
type LifecycleActionPolicy struct {
Action ProviderOperationAction
MutatesProvider bool
SecurityRestricting bool
LocalSessionEffect ProviderSessionEffect
LifecycleState ProviderSessionLifecycleState
CredentialsInvalidating bool
FreshnessRequired bool
QueueSessionRevocation bool
}
func LifecyclePolicyForAction ¶ added in v0.45.0
func LifecyclePolicyForAction(action ProviderOperationAction) (LifecycleActionPolicy, error)
type LifecycleCoordinationRequest ¶ added in v0.45.0
type LifecycleCoordinationRequest struct {
Operation AuthorizedOperationContext
// Deprecated: hardened coordination derives this from the action policy.
SecurityRestricting bool
// Deprecated: hardened coordination derives this from the action policy.
LocalSessionEffect ProviderSessionEffect
Remote ProviderOperationExecutor
}
type LifecycleCoordinationResult ¶ added in v0.45.0
type LifecycleCoordinationResult struct {
OperationID string
Local ProviderOperationOutcome
Remote ProviderOperationOutcome
Freshness ProviderOperationOutcome
}
type LifecycleCoordinator ¶ added in v0.45.0
type LifecycleCoordinator struct {
// contains filtered or unexported fields
}
func NewLifecycleCoordinator ¶ added in v0.45.0
func NewLifecycleCoordinator(config LifecycleCoordinatorConfig) (*LifecycleCoordinator, error)
func (*LifecycleCoordinator) Coordinate ¶ added in v0.45.0
func (c *LifecycleCoordinator) Coordinate( ctx context.Context, request LifecycleCoordinationRequest, ) (LifecycleCoordinationResult, error)
Coordinate advances one durable operation state machine. Completed phases are loaded from the store and are never replayed.
func (*LifecycleCoordinator) ReconcileLifecycleOperation ¶ added in v0.45.0
func (c *LifecycleCoordinator) ReconcileLifecycleOperation( ctx context.Context, reconciliation LifecycleOperationReconciliation, ) (LifecycleCoordinationResult, error)
ReconcileLifecycleOperation persists an authoritative outcome for one leased pending operation, then resumes freshness and completion. It never dispatches the provider mutation.
type LifecycleCoordinatorConfig ¶ added in v0.45.0
type LifecycleCoordinatorConfig struct {
LocalInvalidator ProviderSessionLocalInvalidator
LifecycleInvalidator ProviderSessionLifecycleInvalidator
Freshness LifecycleFreshnessInvalidator
OperationStore LifecycleOperationStore
RequireDurable bool
RequirePermits bool
RemoteLease time.Duration
PhaseLease time.Duration
// Deprecated: retained for source compatibility with the previous
// process-local result cache. Durable stores own retention.
ResultTTL time.Duration
// Deprecated: retained for source compatibility.
MaxResults int
Clock func() time.Time
}
type LifecycleExecutionPermit ¶ added in v0.45.0
type LifecycleExecutionPermit struct {
// contains filtered or unexported fields
}
LifecycleExecutionPermit is an opaque, single-use capability minted only after an operation store claims one exact remote attempt. Copies share the same consumption state.
func (LifecycleExecutionPermit) Consume ¶ added in v0.45.0
func (p LifecycleExecutionPermit) Consume( ctx context.Context, operation AuthorizedOperationContext, ) error
Consume validates this permit against the live operation claim and consumes it before provider transport. It permits an explicitly selected in-memory store for development and compatibility use.
func (LifecycleExecutionPermit) ConsumeForHardenedMutation ¶ added in v0.45.0
func (p LifecycleExecutionPermit) ConsumeForHardenedMutation( ctx context.Context, operation AuthorizedOperationContext, ) error
ConsumeForHardenedMutation additionally requires durable operation authority. Hardened provider adapters must use this method.
func (LifecycleExecutionPermit) IdempotencyKey ¶ added in v0.45.0
func (p LifecycleExecutionPermit) IdempotencyKey() string
func (LifecycleExecutionPermit) Validate ¶ added in v0.45.0
func (p LifecycleExecutionPermit) Validate(operation AuthorizedOperationContext) error
type LifecycleFreshnessInvalidator ¶ added in v0.45.0
type LifecycleFreshnessInvalidator interface {
InvalidateLifecycleFreshness(context.Context, LifecycleFreshnessRequest) error
}
type LifecycleFreshnessInvalidatorFunc ¶ added in v0.45.0
type LifecycleFreshnessInvalidatorFunc func(context.Context, LifecycleFreshnessRequest) error
func (LifecycleFreshnessInvalidatorFunc) InvalidateLifecycleFreshness ¶ added in v0.45.0
func (f LifecycleFreshnessInvalidatorFunc) InvalidateLifecycleFreshness( ctx context.Context, request LifecycleFreshnessRequest, ) error
type LifecycleFreshnessRequest ¶ added in v0.45.0
type LifecycleFreshnessRequest struct {
Operation AuthorizedOperationContext
Remote ProviderOperationOutcome
}
type LifecycleOperationClaim ¶ added in v0.45.0
type LifecycleOperationClaim struct {
OperationID string
Fingerprint string
Action ProviderOperationAction
}
type LifecycleOperationClaimDisposition ¶ added in v0.45.0
type LifecycleOperationClaimDisposition string
const ( LifecycleOperationClaimed LifecycleOperationClaimDisposition = "claimed" LifecycleOperationExisting LifecycleOperationClaimDisposition = "existing" )
type LifecycleOperationPendingPolicy ¶ added in v0.45.0
type LifecycleOperationPhase ¶ added in v0.45.0
type LifecycleOperationPhase string
const ( LifecyclePhasePending LifecycleOperationPhase = "pending" LifecyclePhaseInFlight LifecycleOperationPhase = "in_flight" LifecyclePhaseSucceeded LifecycleOperationPhase = "succeeded" LifecyclePhaseFailed LifecycleOperationPhase = "failed" LifecyclePhasePendingReconcile LifecycleOperationPhase = "pending_reconcile" LifecyclePhaseSkipped LifecycleOperationPhase = "skipped" )
type LifecycleOperationReconciliation ¶ added in v0.45.0
type LifecycleOperationReconciliation struct {
Request LifecycleCoordinationRequest
Claim LifecycleOperationRecord
Remote ProviderOperationOutcome
}
LifecycleOperationReconciliation completes a pending remote phase from an authoritative provider observation. Claim must be a live record returned by LifecycleOperationStore.ClaimPending.
type LifecycleOperationRecord ¶ added in v0.45.0
type LifecycleOperationRecord struct {
OperationID string
Fingerprint string
Action ProviderOperationAction
LocalPhase LifecycleOperationPhase
RemotePhase LifecycleOperationPhase
FreshnessPhase LifecycleOperationPhase
Local ProviderOperationOutcome
Remote ProviderOperationOutcome
Freshness ProviderOperationOutcome
ProviderIdempotencyKey string
LocalLeaseOwner string
LocalLeaseUntil time.Time
RemoteAttempt int
RemoteLeaseOwner string
RemoteLeaseUntil time.Time
FreshnessLeaseOwner string
FreshnessLeaseUntil time.Time
Revision int64
Completed bool
CreatedAt time.Time
UpdatedAt time.Time
}
func (LifecycleOperationRecord) Validate ¶ added in v0.45.0
func (r LifecycleOperationRecord) Validate() error
type LifecycleOperationStore ¶ added in v0.45.0
type LifecycleOperationStore interface {
Claim(
context.Context,
LifecycleOperationClaim,
) (LifecycleOperationRecord, LifecycleOperationClaimDisposition, error)
Load(context.Context, string) (LifecycleOperationRecord, error)
Advance(context.Context, int64, LifecycleOperationRecord) (LifecycleOperationRecord, error)
ClaimPending(context.Context, LifecycleOperationPendingPolicy) ([]LifecycleOperationRecord, error)
Durable() bool
}
type Logger ¶
func EnsureLogger ¶ added in v0.31.0
EnsureLogger guarantees a non-nil logger.
func FromFormattedLogger ¶ added in v0.31.0
func FromFormattedLogger(logger FormattedLogger) Logger
FromFormattedLogger adapts a format-style logger into a glog.Logger.
func FromLegacyLogger ¶ added in v0.31.0
func FromLegacyLogger(logger LegacyLogger) Logger
FromLegacyLogger adapts the historical go-auth logger into a glog.Logger.
type LoggerProvider ¶ added in v0.31.0
type LoggerProvider = glog.LoggerProvider
type LoginAttemptPolicy ¶ added in v0.45.0
type LoginAttemptReservation ¶ added in v0.45.0
type LoginPayload ¶
type LoginRequest ¶
type LoginRequest struct {
Identifier string `form:"identifier" json:"identifier"`
Password string `form:"password" json:"password"`
RememberMe bool `form:"remember_me" json:"remember_me"`
}
LoginRequest payload
func (LoginRequest) GetExtendedSession ¶
func (r LoginRequest) GetExtendedSession() bool
GetExtendedSession will return the password
func (LoginRequest) GetIdentifier ¶
func (r LoginRequest) GetIdentifier() string
GetIdentifier returns the identifier
func (LoginRequest) GetPassword ¶
func (r LoginRequest) GetPassword() string
GetPassword will return the password
func (LoginRequest) Validate ¶
func (r LoginRequest) Validate() *errors.Error
Validate will run validation rules
type Middleware ¶
type Middleware interface {
Impersonate(c router.Context, identifier string) error
ProtectedRoute(cfg Config, errorHandler func(router.Context, error) error) router.MiddlewareFunc
ProtectedBrowserRoute(cfg Config, errorHandler func(router.Context, error) error, config ...BrowserProtectionConfig) router.MiddlewareFunc
}
type MultiTokenValidator ¶ added in v0.24.0
type MultiTokenValidator struct {
// contains filtered or unexported fields
}
MultiTokenValidator tries validators in order until one succeeds. It treats ErrTokenMalformed as "try next" and returns the last malformed error if all validators fail.
func NewMultiTokenValidator ¶ added in v0.24.0
func NewMultiTokenValidator(validators ...TokenValidator) *MultiTokenValidator
NewMultiTokenValidator filters nil validators and returns a composite validator.
func (*MultiTokenValidator) Validate ¶ added in v0.24.0
func (m *MultiTokenValidator) Validate(tokenString string) (AuthClaims, error)
Validate satisfies the TokenValidator interface.
func (*MultiTokenValidator) ValidateSession ¶ added in v0.45.0
func (m *MultiTokenValidator) ValidateSession(tokenString string) (AuthClaims, error)
ValidateSession applies session-use enforcement to validators that expose a session-specific validation boundary while preserving external validators.
type NamedAccountStateSource ¶ added in v0.45.0
type NamedAccountStateSource struct {
Name string
Source AccountStateSource
}
type OperationRisk ¶ added in v0.45.0
type OperationRisk string
const ( OperationRiskNormalRead OperationRisk = "normal_read" OperationRiskPrivileged OperationRisk = "privileged" )
type PasswordAuthenticator ¶
type PasswordAuthenticator interface {
HashPassword(password string) (string, error)
ComparePasswordAndHash(password, hash string) error
}
PasswordAuthenticator authenticates passwords
type PasswordReset ¶
type PasswordReset struct {
bun.BaseModel `bun:"table:password_reset,alias:pwdr"`
ID uuid.UUID `bun:"id,pk,nullzero,type:uuid" json:"id,omitempty"`
UserID *uuid.UUID `bun:"user_id,notnull" json:"user_id,omitempty"`
User *User `bun:"rel:has-one,join:user_id=id" json:"user,omitempty"`
Status string `bun:"status,notnull" json:"status,omitempty"`
Email string `bun:"email,notnull" json:"email,omitempty"`
DeletedAt *time.Time `bun:"deleted_at,soft_delete,nullzero" json:"deleted_at,omitempty"`
ResetedAt *time.Time `bun:"reseted_at,nullzero" json:"reseted_at,omitempty"`
CreatedAt *time.Time `bun:"created_at,nullzero,default:current_timestamp" json:"created_at,omitempty"`
UpdatedAt *time.Time `bun:"updated_at,nullzero,default:current_timestamp" json:"updated_at,omitempty"`
}
PasswordReset is the user model
func MarkPasswordAsReseted ¶
func MarkPasswordAsReseted(id uuid.UUID) *PasswordReset
MarkPasswordAsReseted will create a new instance
type PasswordResetDelivery ¶ added in v0.45.0
type PasswordResetDelivery interface {
DeliverPasswordReset(context.Context, PasswordResetDeliveryRequest) error
}
PasswordResetDelivery delivers a password reset credential over a trusted out-of-band channel, such as email.
type PasswordResetDeliveryFunc ¶ added in v0.45.0
type PasswordResetDeliveryFunc func(context.Context, PasswordResetDeliveryRequest) error
PasswordResetDeliveryFunc adapts a function to PasswordResetDelivery.
func (PasswordResetDeliveryFunc) DeliverPasswordReset ¶ added in v0.45.0
func (f PasswordResetDeliveryFunc) DeliverPasswordReset(ctx context.Context, req PasswordResetDeliveryRequest) error
type PasswordResetDeliveryRequest ¶ added in v0.45.0
PasswordResetDeliveryRequest contains the minimum capability required by a trusted out-of-band delivery implementation. Token is deliberately opaque so common formatting and serialization paths redact it.
type PasswordResetRequestPayload ¶
type PasswordResetRequestPayload struct {
Email string `form:"email" json:"email"`
Stage string `form:"stage" json:"stage"`
}
PasswordResetRequestPayload holds values for password reset
func (PasswordResetRequestPayload) Validate ¶
func (r PasswordResetRequestPayload) Validate() *errors.Error
Validate will validate the payload
type PasswordResetStep ¶
type PasswordResetStep = string
PasswordResetStep step on password reset
const ( // ResetUnknown is the unknown status ResetUnknown PasswordResetStep = "unknown" // ResetInit is the initial step ResetInit PasswordResetStep = "show-reset" //AccountVerification notifiction sent AccountVerification PasswordResetStep = "email-sent" // ChangingPassword user will change password ChangingPassword PasswordResetStep = "change-password" // ChangeFinalized processing change ChangeFinalized PasswordResetStep = "password-changed" )
type PasswordResetVerifyPayload ¶
type PasswordResetVerifyPayload struct {
Stage string `form:"stage" json:"stage"`
Password string `form:"password" json:"password"`
ConfirmPassword string `form:"confirm_password" json:"confirm_password"`
}
PasswordResetVerifyPayload holds values for password reset
func (PasswordResetVerifyPayload) Validate ¶
func (r PasswordResetVerifyPayload) Validate() *errors.Error
Validate will validate the payload
type PermissionCacheErrorMode ¶ added in v0.33.0
type PermissionCacheErrorMode string
PermissionCacheErrorMode defines resolver behavior when cache store operations fail.
const ( // PermissionCacheErrorModeFailOpen bypasses cache errors and continues resolving. PermissionCacheErrorModeFailOpen PermissionCacheErrorMode = "fail_open" // PermissionCacheErrorModeFailClosed returns cache operation errors immediately. PermissionCacheErrorModeFailClosed PermissionCacheErrorMode = "fail_closed" )
type PermissionCacheKeyFunc ¶ added in v0.32.0
PermissionCacheKeyFunc computes a stable cache key for a permission resolution request. Return ok=false to bypass cross-request caching.
type PermissionCacheStore ¶ added in v0.33.0
type PermissionCacheStore interface {
Get(ctx context.Context, key string) (permissions []string, ok bool, err error)
Set(ctx context.Context, key string, permissions []string, ttl time.Duration) error
Delete(ctx context.Context, key string) error
}
PermissionCacheStore is the storage contract used by CachedPermissionsResolver. The interface is intentionally narrow to align with generic cache backends.
type PermissionInvalidationScope ¶ added in v0.45.0
type PermissionInvalidationScope struct {
ApplicationSubject string
TenantID string
SessionID string
}
PermissionInvalidationScope identifies cache entries without requiring unbounded key scans. At least one dimension must be present.
type PermissionResolverFunc ¶ added in v0.32.0
PermissionResolverFunc resolves effective permission keys from a request context.
func (PermissionResolverFunc) ResolveCurrentPermissions ¶ added in v0.45.0
func (f PermissionResolverFunc) ResolveCurrentPermissions( ctx context.Context, request CurrentPermissionsRequest, ) ([]string, error)
ResolveCurrentPermissions resolves permissions for an authoritative version. Existing PermissionResolverFunc implementations remain source compatible and receive the normalized request through context.
type PermissionResolverStats ¶ added in v0.32.0
type PermissionResolverStats struct {
Calls uint64
ResolverRuns uint64
CacheHits uint64
CacheMisses uint64
NoCacheCalls uint64
Errors uint64
StoreGetErrors uint64
StoreSetErrors uint64
StoreDeleteErrors uint64
PurgeRuns uint64
PurgedEntries uint64
}
PermissionResolverStats exposes lightweight runtime counters for observability.
type PermissionScopeInvalidator ¶ added in v0.45.0
type PermissionVersionResolver ¶ added in v0.45.0
type PermissionVersionResolver interface {
ResolvePermissionVersion(context.Context, AuthenticatedPrincipal) (PermissionVersionResult, error)
}
type PermissionVersionResolverFunc ¶ added in v0.45.0
type PermissionVersionResolverFunc func(context.Context, AuthenticatedPrincipal) (PermissionVersionResult, error)
func (PermissionVersionResolverFunc) ResolvePermissionVersion ¶ added in v0.45.0
func (f PermissionVersionResolverFunc) ResolvePermissionVersion( ctx context.Context, principal AuthenticatedPrincipal, ) (PermissionVersionResult, error)
type PermissionVersionResult ¶ added in v0.45.0
type PrincipalSnapshot ¶ added in v0.45.0
type PrincipalSnapshot struct {
ApplicationSubject string
Provider string
ProviderSubject string
ProviderSessionID string
LocalSessionID string
ClientID string
AssuranceLevel string
AssuranceMethods []string
AuthenticationAt time.Time
IssuedAt time.Time
ExpiresAt time.Time
TokenID string
TenantID string
OrganizationID string
PermissionVersion string
Metadata map[string]string
}
PrincipalSnapshot is the non-secret persistence representation of a normalized principal.
func NewPrincipalSnapshot ¶ added in v0.45.0
func NewPrincipalSnapshot(principal AuthenticatedPrincipal) PrincipalSnapshot
func (PrincipalSnapshot) Principal ¶ added in v0.45.0
func (p PrincipalSnapshot) Principal() (AuthenticatedPrincipal, error)
type ProviderAccountState ¶ added in v0.45.0
type ProviderAccountState string
const ( ProviderAccountStateActive ProviderAccountState = "active" ProviderAccountStateSuspended ProviderAccountState = "suspended" ProviderAccountStateDisabled ProviderAccountState = "disabled" ProviderAccountStateUnknown ProviderAccountState = "unknown" )
type ProviderAuditFingerprint ¶ added in v0.45.0
type ProviderAuditFingerprint string
ProviderAuditFingerprint is a one-way correlation value safe for activity payloads. It preserves equality without retaining the source string.
func EnsureProviderAuditFingerprint ¶ added in v0.45.0
func EnsureProviderAuditFingerprint(value string) ProviderAuditFingerprint
func FingerprintProviderAuditValue ¶ added in v0.45.0
func FingerprintProviderAuditValue(value string) ProviderAuditFingerprint
FingerprintProviderAuditValue removes raw free-form values from provider lifecycle audit data. Values are always transformed; callers must retain the ProviderAuditFingerprint type instead of round-tripping it through string.
type ProviderDeliveryOutcome ¶ added in v0.45.0
type ProviderDeliveryOutcome struct {
ProviderOperationOutcome
Delivery ProviderDeliveryStatus
}
type ProviderDeliveryStatus ¶ added in v0.45.0
type ProviderDeliveryStatus string
const ( ProviderDeliverySent ProviderDeliveryStatus = "sent" ProviderDeliveryDuplicate ProviderDeliveryStatus = "duplicate" ProviderDeliveryPending ProviderDeliveryStatus = "pending" ProviderDeliveryFailed ProviderDeliveryStatus = "failed" )
type ProviderFactor ¶ added in v0.45.0
type ProviderFactor struct {
ID string
Type ProviderFactorType
State ProviderFactorState
FriendlyName string
CreatedAt time.Time
UpdatedAt time.Time
}
type ProviderFactorState ¶ added in v0.45.0
type ProviderFactorState string
const ( ProviderFactorVerified ProviderFactorState = "verified" ProviderFactorUnverified ProviderFactorState = "unverified" )
type ProviderFactorType ¶ added in v0.45.0
type ProviderFactorType string
const ( ProviderFactorTOTP ProviderFactorType = "totp" ProviderFactorPhone ProviderFactorType = "phone" ProviderFactorWebAuthn ProviderFactorType = "webauthn" ProviderFactorUnknown ProviderFactorType = "unknown" )
type ProviderFactorsResult ¶ added in v0.45.0
type ProviderFactorsResult struct {
ProviderOperationOutcome
Factors []ProviderFactor
}
type ProviderOperationAction ¶ added in v0.45.0
type ProviderOperationAction string
ProviderOperationAction names a narrow provider-neutral operation. Hosts authorize these actions before invoking a provider implementation.
const ( ProviderActionInvite ProviderOperationAction = "identity.invite" ProviderActionStartRecovery ProviderOperationAction = "identity.recovery.start" ProviderActionSuspend ProviderOperationAction = "account.suspend" ProviderActionActivate ProviderOperationAction = "account.activate" ProviderActionGetAccountState ProviderOperationAction = "account.state.get" ProviderActionListFactors ProviderOperationAction = "factor.list" ProviderActionRemoveFactor ProviderOperationAction = "factor.remove" ProviderActionAuthorizationDetails ProviderOperationAction = "authorization.details" ProviderActionAuthorizationApprove ProviderOperationAction = "authorization.approve" ProviderActionAuthorizationDeny ProviderOperationAction = "authorization.deny" )
type ProviderOperationAuthorizationRequest ¶ added in v0.45.0
type ProviderOperationAuthorizationRequest struct {
Action ProviderOperationAction
Permission string
Actor ActorRef
Target ProviderOperationTarget
Reason string
Environment string
RequestID string
}
type ProviderOperationAuthorizer ¶ added in v0.45.0
type ProviderOperationAuthorizer interface {
AuthorizeProviderOperation(context.Context, ProviderOperationAuthorizationRequest) (AuthorizedOperationContext, error)
}
ProviderOperationAuthorizer is host-owned. Provider adapters consume the resulting proof but never decide business permissions themselves.
type ProviderOperationExecutor ¶ added in v0.45.0
type ProviderOperationExecutor interface {
ExecuteProviderOperation(context.Context, AuthorizedOperationContext) (ProviderOperationOutcome, error)
}
type ProviderOperationExecutorFunc ¶ added in v0.45.0
type ProviderOperationExecutorFunc func(context.Context, AuthorizedOperationContext) (ProviderOperationOutcome, error)
func (ProviderOperationExecutorFunc) ExecuteProviderOperation ¶ added in v0.45.0
func (f ProviderOperationExecutorFunc) ExecuteProviderOperation( ctx context.Context, operation AuthorizedOperationContext, ) (ProviderOperationOutcome, error)
type ProviderOperationFingerprintContributor ¶ added in v0.45.0
type ProviderOperationFingerprintContributor interface {
ProviderOperationFingerprintFields() []ProviderOperationFingerprintField
}
ProviderOperationFingerprintContributor is implemented by concrete executors whose request contains action inputs outside AuthorizedOperationContext.
type ProviderOperationFingerprintField ¶ added in v0.45.0
ProviderOperationFingerprintField binds an action-specific executor input to the durable operation fingerprint without storing the raw input.
type ProviderOperationOutcome ¶ added in v0.45.0
type ProviderOperationOutcome struct {
Status ProviderOperationStatus
Retryable bool
ProviderRequestID string
ProviderSessionEffect ProviderSessionEffect
ResidualAccessExpires time.Time
}
func (ProviderOperationOutcome) Validate ¶ added in v0.45.0
func (o ProviderOperationOutcome) Validate() error
type ProviderOperationStatus ¶ added in v0.45.0
type ProviderOperationStatus string
const ( ProviderOperationSucceeded ProviderOperationStatus = "succeeded" ProviderOperationAlreadyComplete ProviderOperationStatus = "already_complete" ProviderOperationPending ProviderOperationStatus = "pending" ProviderOperationUnsupported ProviderOperationStatus = "unsupported" ProviderOperationConflict ProviderOperationStatus = "conflict" ProviderOperationFailed ProviderOperationStatus = "failed" )
type ProviderOperationTarget ¶ added in v0.45.0
type ProviderOperationTarget struct {
Provider string
ApplicationSubject string
Subject string
ObjectID string
}
ProviderOperationTarget identifies the provider-side object selected by an already-authorized host operation.
type ProviderProfileSyncRepository ¶ added in v0.45.0
type ProviderProfileSyncRepository interface {
SyncProviderProfileTx(ctx context.Context, tx bun.IDB, profile *User) (*User, error)
}
ProviderProfileSyncRepository is the user-store capability required when a provider-driven sync updates an already-linked local user. Implementations must update provider-owned profile fields only; lifecycle and authorization fields remain under their dedicated state/version writers.
type ProviderRefreshClaim ¶ added in v0.45.0
type ProviderRefreshClaim struct {
Session ProviderSession
Tokens TokenEnvelope
AttemptID string
Acquired bool
}
type ProviderRefreshCommit ¶ added in v0.45.0
type ProviderRefreshReconcileRequest ¶ added in v0.45.0
type ProviderRefreshReconcileRequest struct {
Session ProviderSession
AttemptID string
BaseRevision int64
}
type ProviderRefreshReconcileResult ¶ added in v0.45.0
type ProviderRefreshReconcileResult struct {
Status ProviderRefreshReconcileStatus
Tokens ProviderTokenSet
}
type ProviderRefreshReconcileStatus ¶ added in v0.45.0
type ProviderRefreshReconcileStatus string
const ( ProviderRefreshReconciledTokens ProviderRefreshReconcileStatus = "tokens" ProviderRefreshReconciledRevoked ProviderRefreshReconcileStatus = "revoked" ProviderRefreshReconcileUnknown ProviderRefreshReconcileStatus = "unknown" )
type ProviderRefreshRequest ¶ added in v0.45.0
type ProviderRefreshRequest struct {
Session ProviderSession
AttemptID string
RefreshToken Secret
CurrentTokens ProviderTokenSet
}
type ProviderRefreshResult ¶ added in v0.45.0
type ProviderRefreshResult struct {
Tokens ProviderTokenSet
}
type ProviderRemoteRevocationClaim ¶ added in v0.45.0
type ProviderRemoteRevocationClaim struct {
Session ProviderSession
Tokens TokenEnvelope
RemoteRevision int64
Attempt int
LeaseOwner string
LeaseUntil time.Time
LeaseRemaining time.Duration
}
type ProviderRemoteRevocationClaimPolicy ¶ added in v0.45.0
type ProviderRemoteRevocationCompletion ¶ added in v0.45.0
type ProviderRemoteRevocationCompletion struct {
SessionID string
RemoteRevision int64
LeaseOwner string
LeaseUntil time.Time
Outcome ProviderRemoteRevocationOutcome
// Deprecated: repositories derive the next attempt from their database
// clock and RetryDelay.
NextAttemptAt time.Time
RetryDelay time.Duration
SafeErrorCode string
Terminal bool
}
type ProviderRemoteRevocationOutcome ¶ added in v0.45.0
type ProviderRemoteRevocationOutcome struct {
Status ProviderRemoteRevocationStatus
Retryable bool
ResidualAccessExpires time.Time
}
func (ProviderRemoteRevocationOutcome) Validate ¶ added in v0.45.0
func (o ProviderRemoteRevocationOutcome) Validate() error
type ProviderRemoteRevocationRepository ¶ added in v0.45.0
type ProviderRemoteRevocationRepository interface {
ClaimRemoteRevocations(
context.Context,
ProviderRemoteRevocationClaimPolicy,
) ([]ProviderRemoteRevocationClaim, error)
CompleteRemoteRevocation(context.Context, ProviderRemoteRevocationCompletion) error
}
type ProviderRemoteRevocationRetryResult ¶ added in v0.45.0
type ProviderRemoteRevocationStatus ¶ added in v0.45.0
type ProviderRemoteRevocationStatus string
const ( ProviderRemoteRevocationSucceeded ProviderRemoteRevocationStatus = "succeeded" ProviderRemoteRevocationPending ProviderRemoteRevocationStatus = "pending" ProviderRemoteRevocationUnsupported ProviderRemoteRevocationStatus = "unsupported" ProviderRemoteRevocationFailed ProviderRemoteRevocationStatus = "failed" )
type ProviderRevocationHook ¶ added in v0.45.0
type ProviderRevocationHook interface {
RevokeProviderSession(ctx context.Context, request ProviderRevocationRequest) (ProviderRemoteRevocationOutcome, error)
}
type ProviderRevocationRequest ¶ added in v0.45.0
type ProviderRevocationRequest struct {
Session ProviderSession
Reason string
ReasonCode ProviderSessionReasonCode
ReasonFingerprint ProviderAuditFingerprint
Tokens ProviderTokenSet
}
type ProviderSession ¶ added in v0.45.0
type ProviderSession struct {
ID string
LocalSessionID string
Principal PrincipalSnapshot
Binding ProviderSessionBinding
Status ProviderSessionStatus
TokenRevision int64
CreatedAt time.Time
LastSeenAt time.Time
IdleExpiresAt time.Time
MaxExpiresAt time.Time
RefreshAttemptID string
RefreshBaseRevision int64
RefreshLeaseUntil time.Time
RevokedAt time.Time
// Deprecated: contains only the typed reason code after remediation.
RevocationReason string
RevocationReasonCode ProviderSessionReasonCode
RevocationReasonFingerprint ProviderAuditFingerprint
RemoteRevocation ProviderRemoteRevocationOutcome
RemoteAttemptCount int
RemoteNextAttemptAt time.Time
RemoteLeaseOwner string
RemoteLeaseUntil time.Time
RemoteRevision int64
RemoteSafeErrorCode string
RemoteWorkExpiresAt time.Time
RemoteTerminalAt time.Time
}
ProviderSession never includes the browser handle, lookup hash, or provider tokens. ID is internal; LocalSessionID is safe for audit and CSRF keys.
func (ProviderSession) LogValue ¶ added in v0.45.0
func (s ProviderSession) LogValue() slog.Value
func (ProviderSession) String ¶ added in v0.45.0
func (s ProviderSession) String() string
type ProviderSessionActivityMetadata ¶ added in v0.45.0
type ProviderSessionActivityMetadata struct {
Result string
Reason ProviderSessionReason
RemoteStatus ProviderRemoteRevocationStatus
RemoteRetryable bool
LocalOnly bool
Target string
LifecycleGeneration int64
}
type ProviderSessionBinding ¶ added in v0.45.0
type ProviderSessionBinding struct {
Host string
ApplicationID string
Environment string
TenantID string
Provider string
Issuer string
ClientID string
}
ProviderSessionBinding prevents an opaque browser handle from being copied between applications, environments, issuers, or OAuth clients.
func (ProviderSessionBinding) Equal ¶ added in v0.45.0
func (b ProviderSessionBinding) Equal(other ProviderSessionBinding) bool
func (ProviderSessionBinding) Validate ¶ added in v0.45.0
func (b ProviderSessionBinding) Validate() error
type ProviderSessionCleanupPolicy ¶ added in v0.45.0
type ProviderSessionCleanupResult ¶ added in v0.45.0
type ProviderSessionContext ¶ added in v0.45.0
type ProviderSessionContext struct {
Session ProviderSession
Principal AuthenticatedPrincipal
}
func ProviderSessionFromContext ¶ added in v0.45.0
func ProviderSessionFromContext(ctx context.Context) (*ProviderSessionContext, bool)
type ProviderSessionCreate ¶ added in v0.45.0
type ProviderSessionCreate struct {
Session ProviderSession
LookupHash []byte
Tokens TokenEnvelope
}
type ProviderSessionCreation ¶ added in v0.45.0
type ProviderSessionCreation struct {
Handle Secret
Session ProviderSession
Principal AuthenticatedPrincipal
}
type ProviderSessionCreator ¶ added in v0.45.0
type ProviderSessionCreator interface {
CreateProviderSession(ctx context.Context, principal AuthenticatedPrincipal, tokens ProviderTokenSet) (ProviderSessionCreation, error)
}
type ProviderSessionDeployment ¶ added in v0.45.0
type ProviderSessionDeployment string
const ( ProviderSessionDeploymentDevelopment ProviderSessionDeployment = "development" ProviderSessionDeploymentTest ProviderSessionDeployment = "test" ProviderSessionDeploymentProduction ProviderSessionDeployment = "production" ProviderSessionDeploymentHardened ProviderSessionDeployment = "hardened" )
func (ProviderSessionDeployment) RequiresOperations ¶ added in v0.45.0
func (d ProviderSessionDeployment) RequiresOperations() bool
func (ProviderSessionDeployment) Validate ¶ added in v0.45.0
func (d ProviderSessionDeployment) Validate() error
type ProviderSessionEffect ¶ added in v0.45.0
type ProviderSessionEffect string
const ( ProviderSessionEffectNone ProviderSessionEffect = "none" ProviderSessionEffectCurrent ProviderSessionEffect = "current" ProviderSessionEffectNamed ProviderSessionEffect = "named" ProviderSessionEffectAllForUser ProviderSessionEffect = "all_for_user" )
type ProviderSessionHTTP ¶ added in v0.45.0
type ProviderSessionHTTP struct {
// contains filtered or unexported fields
}
func NewProviderSessionHTTP ¶ added in v0.45.0
func NewProviderSessionHTTP(cfg ProviderSessionHTTPConfig) (*ProviderSessionHTTP, error)
func (*ProviderSessionHTTP) ClearCookie ¶ added in v0.45.0
func (h *ProviderSessionHTTP) ClearCookie(c router.Context)
func (*ProviderSessionHTTP) Middleware ¶ added in v0.45.0
func (h *ProviderSessionHTTP) Middleware() router.MiddlewareFunc
func (*ProviderSessionHTTP) RotateCookie ¶ added in v0.45.0
func (h *ProviderSessionHTTP) RotateCookie(c router.Context, manager *ProviderSessionManager) error
type ProviderSessionHTTPConfig ¶ added in v0.45.0
type ProviderSessionHTTPConfig struct {
Resolver ProviderSessionResolver
Binding ProviderSessionBinding
Cookie router.Cookie
CookieDuration time.Duration
AllowDomain bool
LocalJWTCookie string
ContextKey string
CSRF csrf.Config
Origin router.OriginProtectionConfig
ErrorHandler func(router.Context, error) error
}
type ProviderSessionInvalidationScope ¶ added in v0.45.0
type ProviderSessionInvalidationScope struct {
ApplicationSubject string
TenantID string
SessionID string
// PermissionVersion installs a durable authorization fence for the
// subject and tenant. New sessions whose principal snapshot does not
// carry this exact version are rejected after the fence is committed.
PermissionVersion string
// PermissionVersionObservedAt orders duplicate/out-of-order events so an
// older delivery cannot roll the durable fence backward.
PermissionVersionObservedAt time.Time
}
type ProviderSessionLifecycleFence ¶ added in v0.45.0
type ProviderSessionLifecycleFence struct {
ApplicationSubject string
TenantID string
BlockedState ProviderSessionLifecycleState
CredentialsNotBefore time.Time
EventObservedAt time.Time
Generation int64
}
ProviderSessionLifecycleFence is the observable non-secret lifecycle state.
type ProviderSessionLifecycleInvalidator ¶ added in v0.45.0
type ProviderSessionLifecycleInvalidator interface {
ApplyProviderSessionLifecycle(
ctx context.Context,
transition ProviderSessionLifecycleTransition,
) (fence ProviderSessionLifecycleFence, revoked []ProviderSession, err error)
}
type ProviderSessionLifecycleOrdering ¶ added in v0.45.0
type ProviderSessionLifecycleOrdering string
const ( // ProviderSessionLifecycleObservedOrder preserves externally observed event // ordering. Older or duplicate timestamps are no-ops. ProviderSessionLifecycleObservedOrder ProviderSessionLifecycleOrdering = "observed" // ProviderSessionLifecycleRepositoryOrder serializes a locally initiated // transition under the durable fence lock and advances generation // regardless of replica wall-clock skew. ProviderSessionLifecycleRepositoryOrder ProviderSessionLifecycleOrdering = "repository" )
type ProviderSessionLifecycleRepository ¶ added in v0.45.0
type ProviderSessionLifecycleRepository interface {
AdvanceProviderSessionLifecycle(
ctx context.Context,
transition ProviderSessionLifecycleTransition,
) (fence ProviderSessionLifecycleFence, revoked []ProviderSession, err error)
}
ProviderSessionLifecycleRepository is the additive durable capability used by hardened lifecycle coordination and provider-session admission.
type ProviderSessionLifecycleState ¶ added in v0.45.0
type ProviderSessionLifecycleState string
ProviderSessionLifecycleState is the durable session-admission state for one application subject and optional tenant. The empty value means "unchanged" on a transition; persisted fences always use one of the named values.
const ( ProviderSessionLifecycleActive ProviderSessionLifecycleState = "active" ProviderSessionLifecycleSuspended ProviderSessionLifecycleState = "suspended" ProviderSessionLifecycleDisabled ProviderSessionLifecycleState = "disabled" ProviderSessionLifecycleArchived ProviderSessionLifecycleState = "archived" )
type ProviderSessionLifecycleTransition ¶ added in v0.45.0
type ProviderSessionLifecycleTransition struct {
ApplicationSubject string
TenantID string
BlockedState ProviderSessionLifecycleState
CredentialsNotBefore time.Time
AdvanceCredentials bool
EventObservedAt time.Time
Reason string
Ordering ProviderSessionLifecycleOrdering
QueueRemoteRevocation bool
}
ProviderSessionLifecycleTransition advances a durable lifecycle fence. BlockedState may be empty to leave the account state unchanged. An explicit active state is the only transition that clears a prior block.
func (ProviderSessionLifecycleTransition) Validate ¶ added in v0.45.0
func (t ProviderSessionLifecycleTransition) Validate() error
type ProviderSessionLocalInvalidator ¶ added in v0.45.0
type ProviderSessionLocalInvalidator interface {
InvalidateProviderSession(ctx context.Context, sessionID, reason string) error
InvalidateUserProviderSessions(ctx context.Context, applicationSubject, reason string) error
}
ProviderSessionLocalInvalidator makes sessions unusable without invoking a remote provider hook. Lifecycle coordinators use this boundary before their one provider-specific mutation.
type ProviderSessionManager ¶ added in v0.45.0
type ProviderSessionManager struct {
// contains filtered or unexported fields
}
func NewProviderSessionManager ¶ added in v0.45.0
func NewProviderSessionManager(cfg ProviderSessionManagerConfig) (*ProviderSessionManager, error)
func (*ProviderSessionManager) AccessToken ¶ added in v0.45.0
func (m *ProviderSessionManager) AccessToken(ctx context.Context, request UserTokenRequest) (Secret, error)
func (*ProviderSessionManager) ApplyProviderSessionLifecycle ¶ added in v0.45.0
func (m *ProviderSessionManager) ApplyProviderSessionLifecycle( ctx context.Context, transition ProviderSessionLifecycleTransition, ) (ProviderSessionLifecycleFence, []ProviderSession, error)
func (*ProviderSessionManager) CreateProviderSession ¶ added in v0.45.0
func (m *ProviderSessionManager) CreateProviderSession(ctx context.Context, principal AuthenticatedPrincipal, tokens ProviderTokenSet) (ProviderSessionCreation, error)
func (*ProviderSessionManager) InvalidateProviderSession ¶ added in v0.45.0
func (m *ProviderSessionManager) InvalidateProviderSession(ctx context.Context, sessionID, reason string) error
func (*ProviderSessionManager) InvalidateProviderSessions ¶ added in v0.45.0
func (m *ProviderSessionManager) InvalidateProviderSessions( ctx context.Context, scope ProviderSessionInvalidationScope, limit int, reason string, ) (int, bool, error)
func (*ProviderSessionManager) InvalidateUserProviderSessions ¶ added in v0.45.0
func (m *ProviderSessionManager) InvalidateUserProviderSessions(ctx context.Context, applicationSubject, reason string) error
func (*ProviderSessionManager) ReencryptProviderSession ¶ added in v0.45.0
func (m *ProviderSessionManager) ReencryptProviderSession(ctx context.Context, handle Secret, binding ProviderSessionBinding) (ProviderSession, error)
func (*ProviderSessionManager) RefreshProviderSession ¶ added in v0.45.0
func (m *ProviderSessionManager) RefreshProviderSession(ctx context.Context, handle Secret, binding ProviderSessionBinding) (ProviderSession, error)
func (*ProviderSessionManager) ResolveProviderSession ¶ added in v0.45.0
func (m *ProviderSessionManager) ResolveProviderSession(ctx context.Context, handle Secret, binding ProviderSessionBinding) (ProviderSession, AuthenticatedPrincipal, error)
func (*ProviderSessionManager) RetryRemoteRevocations ¶ added in v0.45.0
func (m *ProviderSessionManager) RetryRemoteRevocations( ctx context.Context, policy ProviderRemoteRevocationClaimPolicy, ) (ProviderRemoteRevocationRetryResult, error)
RetryRemoteRevocations executes already-locally-revoked remote work claimed through a bounded durable lease. It never changes local session usability.
func (*ProviderSessionManager) RevokeCurrentProviderSession ¶ added in v0.45.0
func (m *ProviderSessionManager) RevokeCurrentProviderSession(ctx context.Context, handle Secret, binding ProviderSessionBinding, reason string) error
func (*ProviderSessionManager) RevokeProviderSession ¶ added in v0.45.0
func (m *ProviderSessionManager) RevokeProviderSession(ctx context.Context, sessionID, reason string) error
func (*ProviderSessionManager) RevokeUserProviderSessions ¶ added in v0.45.0
func (m *ProviderSessionManager) RevokeUserProviderSessions(ctx context.Context, applicationSubject, reason string) error
func (*ProviderSessionManager) RotateProviderSessionHandle ¶ added in v0.45.0
func (m *ProviderSessionManager) RotateProviderSessionHandle(ctx context.Context, handle Secret, binding ProviderSessionBinding) (Secret, ProviderSession, error)
type ProviderSessionManagerConfig ¶ added in v0.45.0
type ProviderSessionManagerConfig struct {
Repository ProviderSessionRepository
Cipher TokenCipher
Binding ProviderSessionBinding
IdleLifetime time.Duration
MaxLifetime time.Duration
TouchInterval time.Duration
RefreshLease time.Duration
Refresher ProviderTokenRefresher
Reconciler ProviderTokenReconciler
RevocationHook ProviderRevocationHook
TargetRegistry *TokenTargetRegistry
AccessPolicy TokenAccessPolicy
ActivitySink ActivitySink
Deployment ProviderSessionDeployment
Operations *ProviderSessionOperationsConfig
}
type ProviderSessionOperationsConfig ¶ added in v0.45.0
type ProviderSessionOperationsConfig struct {
Environment string
PostgresOwner string
EncryptionKeySource string
KeyRotationOwner string
ActiveKeyPolicy string
RetiredKeyPolicy string
CookiePolicyOwner string
IdleLifetime time.Duration
MaxLifetime time.Duration
StateRetention time.Duration
SessionRetention time.Duration
TokenRetention time.Duration
CleanupSchedule string
CleanupOwner string
MonitoringOwner string
OutagePolicy string
EmergencyRevocationOwner string
EmergencyProcedure string
}
ProviderSessionOperationsConfig is the production enablement gate. Values are intentionally supplied by the host/deployment rather than guessed by this library.
func (ProviderSessionOperationsConfig) Validate ¶ added in v0.45.0
func (c ProviderSessionOperationsConfig) Validate(binding ProviderSessionBinding, idle, maximum time.Duration) error
type ProviderSessionReason ¶ added in v0.45.0
type ProviderSessionReason struct {
Code ProviderSessionReasonCode
DetailFingerprint ProviderAuditFingerprint
}
func NewProviderSessionReason ¶ added in v0.45.0
func NewProviderSessionReason( code ProviderSessionReasonCode, detail string, ) (ProviderSessionReason, error)
func ParseProviderSessionReason ¶ added in v0.45.0
func ParseProviderSessionReason(value string) ProviderSessionReason
func ProviderSessionReasonFromLegacy ¶ added in v0.45.0
func ProviderSessionReasonFromLegacy(detail string) ProviderSessionReason
type ProviderSessionReasonCode ¶ added in v0.45.0
type ProviderSessionReasonCode string
const ( ProviderSessionReasonLogout ProviderSessionReasonCode = "logout" ProviderSessionReasonAccountSuspended ProviderSessionReasonCode = "account_suspended" ProviderSessionReasonFactorChanged ProviderSessionReasonCode = "factor_changed" ProviderSessionReasonAuthorizationChange ProviderSessionReasonCode = "authorization_changed" ProviderSessionReasonAdministrativeRevoke ProviderSessionReasonCode = "administrative_revoke" ProviderSessionReasonExpired ProviderSessionReasonCode = "expired" ProviderSessionReasonRefreshUncertain ProviderSessionReasonCode = "refresh_uncertain" ProviderSessionReasonLegacyExternal ProviderSessionReasonCode = "legacy_external" )
func (ProviderSessionReasonCode) Valid ¶ added in v0.45.0
func (c ProviderSessionReasonCode) Valid() bool
type ProviderSessionRepository ¶ added in v0.45.0
type ProviderSessionRepository interface {
Create(ctx context.Context, input ProviderSessionCreate) (ProviderSession, error)
Resolve(ctx context.Context, lookupHash []byte, binding ProviderSessionBinding, touchInterval time.Duration) (ProviderSessionResolution, error)
Load(ctx context.Context, sessionID string) (ProviderSessionResolution, error)
RotateHandle(ctx context.Context, sessionID string, expectedRevision int64, oldLookupHash, newLookupHash []byte) (ProviderSession, error)
ClaimRefresh(ctx context.Context, sessionID string, expectedRevision int64, attemptID string, lease time.Duration) (ProviderRefreshClaim, error)
CommitRefresh(ctx context.Context, input ProviderRefreshCommit) (ProviderSession, error)
MarkRefreshUncertain(ctx context.Context, sessionID, attemptID string, baseRevision int64, reason string) error
ReplaceCiphertext(ctx context.Context, sessionID string, expectedRevision int64, tokens TokenEnvelope) (ProviderSession, error)
Revoke(ctx context.Context, sessionID, reason string) (ProviderSession, bool, error)
RevokeUser(ctx context.Context, applicationSubject, reason string) ([]ProviderSession, error)
UpdateRemoteRevocation(ctx context.Context, sessionID string, outcome ProviderRemoteRevocationOutcome) error
Cleanup(ctx context.Context, policy ProviderSessionCleanupPolicy) (ProviderSessionCleanupResult, error)
}
ProviderSessionRepository is the composite atomic persistence boundary. Implementations must use database-authoritative time for transitions.
type ProviderSessionResolution ¶ added in v0.45.0
type ProviderSessionResolution struct {
Session ProviderSession
Tokens TokenEnvelope
}
type ProviderSessionResolver ¶ added in v0.45.0
type ProviderSessionResolver interface {
ResolveProviderSession(ctx context.Context, handle Secret, binding ProviderSessionBinding) (ProviderSession, AuthenticatedPrincipal, error)
}
type ProviderSessionRevoker ¶ added in v0.45.0
type ProviderSessionRevoker interface {
RevokeCurrentProviderSession(ctx context.Context, handle Secret, binding ProviderSessionBinding, reason string) error
RevokeProviderSession(ctx context.Context, sessionID, reason string) error
RevokeUserProviderSessions(ctx context.Context, applicationSubject, reason string) error
}
type ProviderSessionScopeInvalidator ¶ added in v0.45.0
type ProviderSessionScopeRepository ¶ added in v0.45.0
type ProviderSessionScopeRepository interface {
RevokeScope(
ctx context.Context,
scope ProviderSessionInvalidationScope,
limit int,
reason string,
) (sessions []ProviderSession, more bool, err error)
}
type ProviderSessionStatus ¶ added in v0.45.0
type ProviderSessionStatus string
const ( ProviderSessionAvailable ProviderSessionStatus = "available" ProviderSessionRefreshing ProviderSessionStatus = "refreshing" ProviderSessionUncertain ProviderSessionStatus = "uncertain" ProviderSessionRevoked ProviderSessionStatus = "revoked" ProviderSessionExpired ProviderSessionStatus = "expired" )
func (ProviderSessionStatus) Usable ¶ added in v0.45.0
func (s ProviderSessionStatus) Usable() bool
type ProviderSessionStore ¶ added in v0.45.0
type ProviderSessionStore interface {
Resolve(ctx context.Context, lookupHash []byte, binding ProviderSessionBinding, touchInterval time.Duration) (ProviderSessionResolution, error)
}
Logical views deliberately omit create/commit operations. They are useful for narrow consumers while the manager retains the composite repository.
type ProviderTokenReconciler ¶ added in v0.45.0
type ProviderTokenReconciler interface {
ReconcileProviderRefresh(ctx context.Context, request ProviderRefreshReconcileRequest) (ProviderRefreshReconcileResult, error)
}
type ProviderTokenRefresher ¶ added in v0.45.0
type ProviderTokenRefresher interface {
RefreshProviderTokens(ctx context.Context, request ProviderRefreshRequest) (ProviderRefreshResult, error)
}
type ProviderTokenSet ¶ added in v0.45.0
type ProviderTokenSet struct {
// contains filtered or unexported fields
}
ProviderTokenSet keeps provider credentials opaque and non-serializable.
func NewProviderTokenSet ¶ added in v0.45.0
func NewProviderTokenSet(input ProviderTokenSetInput) (ProviderTokenSet, error)
func (ProviderTokenSet) AccessContext ¶ added in v0.45.0
func (s ProviderTokenSet) AccessContext() (ValidatedTokenContext, bool)
func (ProviderTokenSet) AccessExpiresAt ¶ added in v0.45.0
func (s ProviderTokenSet) AccessExpiresAt() time.Time
func (ProviderTokenSet) AccessToken ¶ added in v0.45.0
func (s ProviderTokenSet) AccessToken() Secret
func (ProviderTokenSet) AcquiredAt ¶ added in v0.45.0
func (s ProviderTokenSet) AcquiredAt() time.Time
func (ProviderTokenSet) Format ¶ added in v0.45.0
func (s ProviderTokenSet) Format(state fmt.State, _ rune)
func (ProviderTokenSet) GoString ¶ added in v0.45.0
func (s ProviderTokenSet) GoString() string
func (ProviderTokenSet) IDContext ¶ added in v0.45.0
func (s ProviderTokenSet) IDContext() (ValidatedTokenContext, bool)
func (ProviderTokenSet) IDExpiresAt ¶ added in v0.45.0
func (s ProviderTokenSet) IDExpiresAt() time.Time
func (ProviderTokenSet) IDToken ¶ added in v0.45.0
func (s ProviderTokenSet) IDToken() Secret
func (ProviderTokenSet) LogValue ¶ added in v0.45.0
func (s ProviderTokenSet) LogValue() slog.Value
func (ProviderTokenSet) MarshalJSON ¶ added in v0.45.0
func (s ProviderTokenSet) MarshalJSON() ([]byte, error)
func (ProviderTokenSet) MarshalText ¶ added in v0.45.0
func (s ProviderTokenSet) MarshalText() ([]byte, error)
func (ProviderTokenSet) Metadata ¶ added in v0.45.0
func (s ProviderTokenSet) Metadata() map[string]string
func (ProviderTokenSet) RefreshExpiresAt ¶ added in v0.45.0
func (s ProviderTokenSet) RefreshExpiresAt() time.Time
func (ProviderTokenSet) RefreshToken ¶ added in v0.45.0
func (s ProviderTokenSet) RefreshToken() Secret
func (ProviderTokenSet) Scopes ¶ added in v0.45.0
func (s ProviderTokenSet) Scopes() []string
func (ProviderTokenSet) String ¶ added in v0.45.0
func (s ProviderTokenSet) String() string
func (ProviderTokenSet) TokenType ¶ added in v0.45.0
func (s ProviderTokenSet) TokenType() string
type ProviderTokenSetInput ¶ added in v0.45.0
type ProviderTokenSetInput struct {
AccessToken Secret
RefreshToken Secret
IDToken Secret
TokenType string
Scopes []string
AcquiredAt time.Time
AccessExpiresAt time.Time
RefreshExpiresAt time.Time
IDExpiresAt time.Time
IDContext *ValidatedTokenContext
AccessContext *ValidatedTokenContext
Metadata map[string]string
}
ProviderTokenSetInput is the construction boundary for a provider token set.
type ProviderTokenVault ¶ added in v0.45.0
type ProviderTokenVault interface {
ClaimRefresh(ctx context.Context, sessionID string, expectedRevision int64, attemptID string, lease time.Duration) (ProviderRefreshClaim, error)
CommitRefresh(ctx context.Context, input ProviderRefreshCommit) (ProviderSession, error)
MarkRefreshUncertain(ctx context.Context, sessionID, attemptID string, baseRevision int64, reason string) error
ReplaceCiphertext(ctx context.Context, sessionID string, expectedRevision int64, tokens TokenEnvelope) (ProviderSession, error)
}
type ProviderUserSession ¶ added in v0.45.0
type ProviderUserSession struct {
SessionHandle Secret
Binding ProviderSessionBinding
Principal AuthenticatedPrincipal
TokenTarget string
Capability TokenTargetCapability
}
ProviderUserSession identifies the validated central provider session whose user token may be resolved internally. It cannot carry a raw token.
type PurgeablePermissionCacheStore ¶ added in v0.33.0
type PurgeablePermissionCacheStore interface {
PurgeExpired(ctx context.Context) (purged int, err error)
}
PurgeablePermissionCacheStore optionally supports active cleanup of expired keys. Implementations backed by Redis can ignore this capability.
type RecoveryRequest ¶ added in v0.45.0
type RecoveryRequest struct {
Operation AuthorizedOperationContext
Email string
ReturnURL string
}
type RegisterUserHandler ¶
type RegisterUserHandler struct {
// contains filtered or unexported fields
}
Test handlers
func NewRegisterUserHandler ¶ added in v0.26.0
func NewRegisterUserHandler(repo RepositoryManager) *RegisterUserHandler
func (*RegisterUserHandler) Execute ¶
func (h *RegisterUserHandler) Execute(ctx context.Context, event RegisterUserMessage) error
func (*RegisterUserHandler) WithFeatureGate ¶ added in v0.26.0
func (h *RegisterUserHandler) WithFeatureGate(featureGate gate.FeatureGate) *RegisterUserHandler
type RegisterUserMessage ¶
type RegisterUserMessage struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Username string `json:"username"`
Email string `json:"email"`
Phone string `json:"phone"`
Role string `json:"role"`
Password string `json:"password"`
UseHashid bool
}
func (RegisterUserMessage) Type ¶
func (e RegisterUserMessage) Type() string
type RegistrationCreatePayload ¶
type RegistrationCreatePayload struct {
FirstName string `form:"first_name" json:"first_name"`
LastName string `form:"last_name" json:"last_name"`
Email string `form:"email" json:"email"`
Phone string `form:"phone_number" json:"phone_number"`
Password string `form:"password" json:"password"`
ConfirmPassword string `form:"confirm_password" json:"confirm_password"`
}
RegistrationCreatePayload is the form paylaod
func (RegistrationCreatePayload) Validate ¶
func (r RegistrationCreatePayload) Validate() *errors.Error
Validate will validate the payload
type RepositoryManager ¶
type RepositoryManager interface {
repository.Validator
repository.TransactionManager
Users() Users
PasswordResets() repository.Repository[*PasswordReset]
}
RepositoryManager exposes all repositories
func NewRepositoryManager ¶
func NewRepositoryManager(db *bun.DB) RepositoryManager
type ResourceRoleProvider ¶ added in v0.7.0
type ResourceRoleProvider interface {
FindResourceRoles(ctx context.Context, identity Identity) (map[string]string, error)
}
ResourceRoleProvider is an optional interface for fetching resource-specific roles. If provided to an Auther, it will be used to embed fine-grained permissions into the JWT, upgrading it to a structured claims format.
type RoleCapableSession ¶ added in v0.7.0
type RoleCapableSession interface {
Session // Embed the existing Session interface
// CanRead checks if the role can read a specific resource
CanRead(resource string) bool
// CanEdit checks if the role can edit a specific resource
CanEdit(resource string) bool
// CanCreate checks if the role can create a specific resource
CanCreate(resource string) bool
// CanDelete checks if the role can delete a specific resource
CanDelete(resource string) bool
// HasRole checks if the user has a specific role
HasRole(role string) bool
// IsAtLeast checks if the user's role is at least the minimum required role
IsAtLeast(minRole UserRole) bool
}
RoleCapableSession extends Session with role-based access control capabilities
type RoleFreshnessPolicy ¶ added in v0.45.0
type RoleFreshnessPolicy struct {
Role string
Policy FreshnessOperationPolicy
}
type RoleValidator ¶ added in v0.7.0
type RoleValidator interface {
// CanRead checks if the role can read a specific resource
CanRead(resource string) bool
// CanEdit checks if the role can edit a specific resource
CanEdit(resource string) bool
// CanCreate checks if the role can create a specific resource
CanCreate(resource string) bool
// CanDelete checks if the role can delete a specific resource
CanDelete(resource string) bool
// HasRole checks if the user has a specific role
HasRole(role string) bool
// IsAtLeast checks if the user's role is at least the minimum required role
IsAtLeast(minRole UserRole) bool
}
RoleValidator defines the interface for role-based access control validation
type RouteAuthenticationMode ¶ added in v0.45.0
type RouteAuthenticationMode string
const ( RouteAuthenticationProviderSession RouteAuthenticationMode = "provider_session" RouteAuthenticationLocalJWT RouteAuthenticationMode = "local_jwt" RouteAuthenticationBearer RouteAuthenticationMode = "bearer" )
type RouteAuthenticator ¶
type RouteAuthenticator struct {
AuthErrorHandler func(c router.Context, err error) error // TODO: make functions
ErrorHandler func(c router.Context, err error) error // TODO: make functions
// contains filtered or unexported fields
}
func NewHTTPAuthenticator ¶
func NewHTTPAuthenticator(auther Authenticator, cfg Config, opts ...HTTPAuthenticatorOption) (*RouteAuthenticator, error)
func (*RouteAuthenticator) AuthCookieName ¶ added in v0.40.0
func (a *RouteAuthenticator) AuthCookieName() string
func (RouteAuthenticator) GetCookieDuration ¶
func (a RouteAuthenticator) GetCookieDuration() time.Duration
func (RouteAuthenticator) GetExtendedCookieDuration ¶
func (a RouteAuthenticator) GetExtendedCookieDuration() time.Duration
func (*RouteAuthenticator) GetRedirect ¶
func (a *RouteAuthenticator) GetRedirect(ctx router.Context, def ...string) string
func (*RouteAuthenticator) GetRedirectOrDefault ¶
func (a *RouteAuthenticator) GetRedirectOrDefault(ctx router.Context) string
func (*RouteAuthenticator) Impersonate ¶
func (a *RouteAuthenticator) Impersonate(c router.Context, identifier string) error
func (*RouteAuthenticator) Login ¶
func (a *RouteAuthenticator) Login(ctx router.Context, payload LoginPayload) error
func (*RouteAuthenticator) Logout ¶
func (a *RouteAuthenticator) Logout(ctx router.Context)
func (*RouteAuthenticator) MakeClientRouteAuthErrorHandler ¶
func (*RouteAuthenticator) ProtectedBrowserRoute ¶ added in v0.37.0
func (a *RouteAuthenticator) ProtectedBrowserRoute(cfg Config, errorHandler func(router.Context, error) error, config ...BrowserProtectionConfig) router.MiddlewareFunc
func (*RouteAuthenticator) ProtectedRoute ¶
func (a *RouteAuthenticator) ProtectedRoute(cfg Config, errorHandler func(router.Context, error) error) router.MiddlewareFunc
func (*RouteAuthenticator) SetAuthCookie ¶ added in v0.44.0
func (a *RouteAuthenticator) SetAuthCookie(ctx router.Context, token string, opts ...AuthCookieOption) error
SetAuthCookie writes the normal go-auth browser session cookie for a token minted outside the password-login handler, such as an OIDC SSO callback.
func (*RouteAuthenticator) SetRedirect ¶
func (a *RouteAuthenticator) SetRedirect(ctx router.Context)
func (*RouteAuthenticator) WithLogger ¶ added in v0.4.0
func (a *RouteAuthenticator) WithLogger(l Logger) *RouteAuthenticator
func (*RouteAuthenticator) WithLoggerProvider ¶ added in v0.31.0
func (a *RouteAuthenticator) WithLoggerProvider(provider LoggerProvider) *RouteAuthenticator
WithLoggerProvider overrides the logger provider used by the HTTP authenticator.
func (*RouteAuthenticator) WithValidationListeners ¶ added in v0.15.0
func (a *RouteAuthenticator) WithValidationListeners(listeners ...ValidationListener) *RouteAuthenticator
WithValidationListeners registers callbacks invoked immediately after token validation.
type RouteCredentialConfig ¶ added in v0.45.0
type ScopedTokenOptions ¶ added in v0.29.0
type ScopedTokenOptions struct {
// TTL overrides the default token expiration. Zero uses TokenService defaults.
TTL time.Duration
// Issuer overrides the default issuer if provided.
Issuer string
// Audience overrides the default audience if provided.
Audience []string
// IssuedAt overrides the issuance time. Zero uses time.Now().
IssuedAt time.Time
// Scopes sets the optional scopes claim on the minted token.
Scopes []string
}
ScopedTokenOptions controls how MintScopedToken issues short-lived tokens.
type Secret ¶ added in v0.45.0
type Secret struct {
// contains filtered or unexported fields
}
Secret is an opaque secret value. It must be explicitly revealed by trusted server-side code and fails closed when passed to common serializers.
func (Secret) MarshalJSON ¶ added in v0.45.0
func (Secret) MarshalText ¶ added in v0.45.0
func (*Secret) UnmarshalText ¶ added in v0.45.0
type Session ¶
type Session interface {
GetUserID() string
GetUserUUID() (uuid.UUID, error)
GetAudience() []string
GetIssuer() string
GetIssuedAt() *time.Time
GetData() map[string]any
}
Session holds attributes that are part of an auth session
type SessionObject ¶
type SessionObject struct {
UserID string `json:"user_id,omitempty"`
Audience []string `json:"audience,omitempty"`
Issuer string `json:"issuer,omitempty"`
IssuedAt *time.Time `json:"issued_at,omitempty"`
ExpirationDate *time.Time `json:"expiration_date,omitempty"`
Data map[string]any `json:"data,omitempty"`
}
func GetRouterSession ¶
func GetRouterSession(c router.Context, key string) (*SessionObject, error)
func (*SessionObject) CanCreate ¶ added in v0.7.0
func (s *SessionObject) CanCreate(resource string) bool
CanCreate checks if the role can create a specific resource
func (*SessionObject) CanDelete ¶ added in v0.7.0
func (s *SessionObject) CanDelete(resource string) bool
CanDelete checks if the role can delete a specific resource
func (*SessionObject) CanEdit ¶ added in v0.7.0
func (s *SessionObject) CanEdit(resource string) bool
CanEdit checks if the role can edit a specific resource
func (*SessionObject) CanRead ¶ added in v0.7.0
func (s *SessionObject) CanRead(resource string) bool
CanRead checks if the role can read a specific resource
func (*SessionObject) GetAudience ¶
func (s *SessionObject) GetAudience() []string
func (*SessionObject) GetData ¶
func (s *SessionObject) GetData() map[string]any
func (*SessionObject) GetIssuedAt ¶
func (s *SessionObject) GetIssuedAt() *time.Time
func (*SessionObject) GetIssuer ¶
func (s *SessionObject) GetIssuer() string
func (*SessionObject) GetUserID ¶
func (s *SessionObject) GetUserID() string
func (*SessionObject) GetUserUUID ¶
func (s *SessionObject) GetUserUUID() (uuid.UUID, error)
func (*SessionObject) HasRole ¶ added in v0.7.0
func (s *SessionObject) HasRole(role string) bool
HasRole checks if the user has a specific role
func (*SessionObject) IsAtLeast ¶ added in v0.7.0
func (s *SessionObject) IsAtLeast(minRole UserRole) bool
IsAtLeast checks if the user's role is at least the minimum required role
func (SessionObject) String ¶
func (s SessionObject) String() string
type StateMachineOption ¶ added in v0.14.0
type StateMachineOption func(*userStateMachine)
StateMachineOption customizes state machine construction.
func WithStateMachineActivitySink ¶ added in v0.14.0
func WithStateMachineActivitySink(sink ActivitySink) StateMachineOption
WithStateMachineActivitySink sets the ActivitySink used to publish lifecycle events.
func WithStateMachineClock ¶ added in v0.14.0
func WithStateMachineClock(clock func() time.Time) StateMachineOption
WithStateMachineClock injects a custom clock (useful for tests).
func WithStateMachineHookErrorHandler ¶ added in v0.15.0
func WithStateMachineHookErrorHandler(handler HookErrorHandler) StateMachineOption
WithStateMachineHookErrorHandler overrides how hook failures are propagated. Provide a handler to convert hook errors into domain-specific responses, otherwise the default handler panics with guidance for developers.
func WithStateMachineLogger ¶ added in v0.14.0
func WithStateMachineLogger(logger Logger) StateMachineOption
WithStateMachineLogger overrides the logger used for sink failures.
func WithStateMachineLoggerProvider ¶ added in v0.31.0
func WithStateMachineLoggerProvider(provider LoggerProvider) StateMachineOption
WithStateMachineLoggerProvider overrides the logger provider used by the state machine.
type StateStoreMaintenance ¶ added in v0.45.0
type StaticTokenKeyProvider ¶ added in v0.45.0
type StaticTokenKeyProvider struct {
// contains filtered or unexported fields
}
func NewStaticTokenKeyProvider ¶ added in v0.45.0
func NewStaticTokenKeyProvider(activeID string, keys ...TokenEncryptionKey) (*StaticTokenKeyProvider, error)
func (*StaticTokenKeyProvider) ActiveKey ¶ added in v0.45.0
func (p *StaticTokenKeyProvider) ActiveKey(context.Context) (TokenEncryptionKey, error)
func (*StaticTokenKeyProvider) Key ¶ added in v0.45.0
func (p *StaticTokenKeyProvider) Key(_ context.Context, keyID string) (TokenEncryptionKey, error)
func (*StaticTokenKeyProvider) Retire ¶ added in v0.45.0
func (p *StaticTokenKeyProvider) Retire(keyID string) error
func (*StaticTokenKeyProvider) Rotate ¶ added in v0.45.0
func (p *StaticTokenKeyProvider) Rotate(active TokenEncryptionKey) error
type StatusAwareIdentity ¶ added in v0.45.0
type StatusAwareIdentity interface {
Status() UserStatus
}
StatusAwareIdentity is implemented by identities that expose an account lifecycle status. Identity implementations that predate lifecycle support remain compatible and are treated as active.
type StatusUpdateOption ¶ added in v0.14.0
type StatusUpdateOption func(*User)
StatusUpdateOption allows callers to mutate the user record before persisting status changes.
func WithSuspendedAt ¶ added in v0.14.0
func WithSuspendedAt(at *time.Time) StatusUpdateOption
WithSuspendedAt sets the SuspendedAt timestamp during a status transition.
type StorePermissionVersionResolver ¶ added in v0.45.0
type StorePermissionVersionResolver struct {
Store AuthorizationVersionStore
}
StorePermissionVersionResolver reads the current host-owned version.
func (StorePermissionVersionResolver) ResolvePermissionVersion ¶ added in v0.45.0
func (r StorePermissionVersionResolver) ResolvePermissionVersion( ctx context.Context, principal AuthenticatedPrincipal, ) (PermissionVersionResult, error)
type TemporaryPasswordResetRepository ¶ added in v0.42.0
type TemporaryPasswordResetRepository interface {
ResetPasswordAndClearTemporaryPassword(ctx context.Context, id uuid.UUID, passwordHash string) error
ResetPasswordAndClearTemporaryPasswordTx(ctx context.Context, tx bun.IDB, id uuid.UUID, passwordHash string) error
}
TemporaryPasswordResetRepository is an optional user repository capability for replacing a password hash and clearing temporary-password metadata together.
type TemporaryPasswordState ¶ added in v0.41.0
type TemporaryPasswordState struct {
Temporary bool
ChangeRequired bool
IssuedAt time.Time
ExpiresAt time.Time
}
TemporaryPasswordState is the normalized state carried in user metadata.
func TemporaryPasswordStateFromMetadata ¶ added in v0.41.0
func TemporaryPasswordStateFromMetadata(metadata map[string]any) TemporaryPasswordState
TemporaryPasswordStateFromMetadata extracts temporary-password state from user metadata.
type TokenAccessPolicy ¶ added in v0.45.0
type TokenAccessPolicy interface {
AuthorizeProviderToken(ctx context.Context, request TokenAccessPolicyRequest) error
}
type TokenAccessPolicyRequest ¶ added in v0.45.0
type TokenAccessPolicyRequest struct {
Session ProviderSession
Target TokenTarget
}
type TokenCipher ¶ added in v0.45.0
type TokenEncryptionKey ¶ added in v0.45.0
type TokenEncryptionKey struct {
// contains filtered or unexported fields
}
func NewTokenEncryptionKey ¶ added in v0.45.0
func NewTokenEncryptionKey(id string, material []byte, retired bool) (TokenEncryptionKey, error)
func (TokenEncryptionKey) Format ¶ added in v0.45.0
func (k TokenEncryptionKey) Format(state fmt.State, _ rune)
func (TokenEncryptionKey) GoString ¶ added in v0.45.0
func (k TokenEncryptionKey) GoString() string
func (TokenEncryptionKey) ID ¶ added in v0.45.0
func (k TokenEncryptionKey) ID() string
func (TokenEncryptionKey) LogValue ¶ added in v0.45.0
func (k TokenEncryptionKey) LogValue() slog.Value
func (TokenEncryptionKey) MarshalJSON ¶ added in v0.45.0
func (k TokenEncryptionKey) MarshalJSON() ([]byte, error)
func (TokenEncryptionKey) Material ¶ added in v0.45.0
func (k TokenEncryptionKey) Material() []byte
func (TokenEncryptionKey) Retired ¶ added in v0.45.0
func (k TokenEncryptionKey) Retired() bool
func (TokenEncryptionKey) String ¶ added in v0.45.0
func (k TokenEncryptionKey) String() string
type TokenEnvelope ¶ added in v0.45.0
type TokenEnvelope struct {
Version uint8
Algorithm string
KeyID string
Nonce []byte
Ciphertext []byte
}
func (TokenEnvelope) Format ¶ added in v0.45.0
func (e TokenEnvelope) Format(state fmt.State, _ rune)
func (TokenEnvelope) GoString ¶ added in v0.45.0
func (e TokenEnvelope) GoString() string
func (TokenEnvelope) LogValue ¶ added in v0.45.0
func (e TokenEnvelope) LogValue() slog.Value
func (TokenEnvelope) MarshalJSON ¶ added in v0.45.0
func (e TokenEnvelope) MarshalJSON() ([]byte, error)
func (TokenEnvelope) String ¶ added in v0.45.0
func (e TokenEnvelope) String() string
type TokenIDer ¶ added in v0.29.0
type TokenIDer interface {
TokenID() string
}
TokenIDer is an optional interface for claims that expose a token ID (jti).
type TokenKeyProvider ¶ added in v0.45.0
type TokenKeyProvider interface {
ActiveKey(ctx context.Context) (TokenEncryptionKey, error)
Key(ctx context.Context, keyID string) (TokenEncryptionKey, error)
}
type TokenService ¶ added in v0.7.0
type TokenService interface {
// Generate creates a new JWT token for the given identity with resource-specific roles
Generate(identity Identity, resourceRoles map[string]string) (string, error)
// SignClaims validates required claims, assigns jti/token_use when needed,
// and signs the provided custom claims.
SignClaims(claims *JWTClaims) (string, error)
// Validate parses and validates a token string, returning structured claims
Validate(tokenString string) (AuthClaims, error)
}
TokenService provides transport-agnostic JWT operations
func NewTokenService ¶ added in v0.7.0
func NewTokenService(signingKey []byte, tokenExpiration int, issuer string, audience jwt.ClaimStrings, logger Logger, opts ...TokenServiceOption) TokenService
NewTokenService is the compatibility constructor. Invalid configuration produces a fail-closed service whose signing and validation methods return the configuration error. New code should use NewValidatedTokenService.
type TokenServiceAdapter ¶ added in v0.7.0
type TokenServiceAdapter struct {
// contains filtered or unexported fields
}
TokenServiceAdapter adapts TokenValidator to jwtware.TokenValidator interface
func NewTokenServiceAdapter ¶ added in v0.11.0
func NewTokenServiceAdapter(tokenValidator TokenValidator) *TokenServiceAdapter
NewTokenServiceAdapter creates a new TokenServiceAdapter
func (*TokenServiceAdapter) Validate ¶ added in v0.7.0
func (tsa *TokenServiceAdapter) Validate(tokenString string) (jwtware.AuthClaims, error)
Validate implements the jwtware.TokenValidator interface
type TokenServiceImpl ¶ added in v0.7.0
type TokenServiceImpl struct {
// contains filtered or unexported fields
}
TokenServiceImpl implements the TokenService interface
func NewValidatedTokenService ¶ added in v0.45.0
func NewValidatedTokenService(signingKey []byte, tokenExpiration int, issuer string, audience jwt.ClaimStrings, logger Logger, opts ...TokenServiceOption) (*TokenServiceImpl, error)
NewValidatedTokenService creates a token service only when all signing and registered-claim trust-boundary requirements are configured.
func (*TokenServiceImpl) Generate ¶ added in v0.7.0
func (ts *TokenServiceImpl) Generate(identity Identity, resourceRoles map[string]string) (string, error)
Generate creates a JWT token with resource specific roles
func (*TokenServiceImpl) SignClaims ¶ added in v0.14.0
func (ts *TokenServiceImpl) SignClaims(claims *JWTClaims) (string, error)
SignClaims signs arbitrary JWT claims using the configured signing key.
func (*TokenServiceImpl) SignClaimsWithType ¶ added in v0.34.0
func (ts *TokenServiceImpl) SignClaimsWithType(claims *JWTClaims, tokenType string) (string, error)
SignClaimsWithType signs claims and annotates guardrail logs/errors with the provided token type.
func (*TokenServiceImpl) Stats ¶ added in v0.34.0
func (ts *TokenServiceImpl) Stats() TokenServiceStats
Stats returns runtime counters for token signing guardrails.
func (*TokenServiceImpl) Validate ¶ added in v0.7.0
func (ts *TokenServiceImpl) Validate(tokenString string) (AuthClaims, error)
Validate parses and validates a token string, returning structured claims
func (*TokenServiceImpl) ValidateSession ¶ added in v0.45.0
func (ts *TokenServiceImpl) ValidateSession(tokenString string) (AuthClaims, error)
ValidateSession validates a token and additionally requires session use.
type TokenServiceOption ¶ added in v0.34.0
type TokenServiceOption func(*TokenServiceImpl)
TokenServiceOption customizes TokenService behavior without changing the TokenService interface.
func WithClaimsMetadataStripKeys ¶ added in v0.34.0
func WithClaimsMetadataStripKeys(keys ...string) TokenServiceOption
WithClaimsMetadataStripKeys overrides the metadata keys that are removed by default minimization. Matching is case-insensitive and normalizes "-" to "_".
func WithTokenSizeGuardrails ¶ added in v0.34.0
func WithTokenSizeGuardrails(warnThresholdBytes, hardLimitBytes int) TokenServiceOption
WithTokenSizeGuardrails overrides warning and hard-limit thresholds for signed JWT size. Values <= 0 disable the respective threshold.
type TokenServiceStats ¶ added in v0.34.0
TokenServiceStats exposes runtime counters for token signing operations.
type TokenTarget ¶ added in v0.45.0
type TokenTargetCapability ¶ added in v0.45.0
type TokenTargetCapability struct {
// contains filtered or unexported fields
}
func NewTokenTargetCapability ¶ added in v0.45.0
func NewTokenTargetCapability() (TokenTargetCapability, error)
func (TokenTargetCapability) Format ¶ added in v0.45.0
func (c TokenTargetCapability) Format(state fmt.State, _ rune)
func (TokenTargetCapability) GoString ¶ added in v0.45.0
func (c TokenTargetCapability) GoString() string
func (TokenTargetCapability) MarshalJSON ¶ added in v0.45.0
func (c TokenTargetCapability) MarshalJSON() ([]byte, error)
func (TokenTargetCapability) String ¶ added in v0.45.0
func (c TokenTargetCapability) String() string
type TokenTargetRegistry ¶ added in v0.45.0
type TokenTargetRegistry struct {
// contains filtered or unexported fields
}
func NewTokenTargetRegistry ¶ added in v0.45.0
func NewTokenTargetRegistry(targets ...TokenTarget) (*TokenTargetRegistry, error)
func (*TokenTargetRegistry) Resolve ¶ added in v0.45.0
func (r *TokenTargetRegistry) Resolve(name string, capability TokenTargetCapability) (TokenTarget, error)
type TokenUseClaimer ¶ added in v0.45.0
type TokenUseClaimer interface {
TokenUse() string
}
TokenUseClaimer is implemented by claims that identify the trust boundary in which the token may be used.
type TokenValidator ¶ added in v0.24.0
type TokenValidator interface {
Validate(tokenString string) (AuthClaims, error)
}
TokenValidator validates tokens and extracts claims without tying callers to a specific signing implementation.
type TokenValidatorFunc ¶ added in v0.24.0
type TokenValidatorFunc func(tokenString string) (AuthClaims, error)
TokenValidatorFunc adapts a function into a TokenValidator.
func (TokenValidatorFunc) Validate ¶ added in v0.24.0
func (f TokenValidatorFunc) Validate(tokenString string) (AuthClaims, error)
Validate satisfies the TokenValidator interface.
type TransactionalIdentifierStore ¶ added in v0.45.0
type TransactionalIdentifierStore interface {
ImmutableIdentifierStore
CreateUserAndBind(ctx context.Context, users Users, user *User, provider, identifier string) (*User, error)
}
TransactionalIdentifierStore can create a user and bind its external identifier in one database transaction.
type TransactionalIdentifierSyncStore ¶ added in v0.45.0
type TransactionalIdentifierSyncStore interface {
ImmutableIdentifierStore
UpsertUserAndBind(ctx context.Context, users Users, user *User, provider, identifier string) (*User, error)
}
TransactionalIdentifierSyncStore can upsert provider-owned local profile data and preserve its immutable external binding in one transaction. Provider-driven sync must require this capability because compensating an update cannot safely reconstruct the previous user record.
type TransitionContext ¶ added in v0.14.0
type TransitionContext struct {
Actor ActorRef
User *User
From UserStatus
To UserStatus
Meta TransitionMetadata
}
TransitionContext is passed into hooks for additional processing.
type TransitionHook ¶ added in v0.14.0
type TransitionHook func(ctx context.Context, tc TransitionContext) error
TransitionHook is executed before or after a transition.
type TransitionHookPhase ¶ added in v0.15.0
type TransitionHookPhase string
TransitionHookPhase identifies whether a hook ran before or after persistence.
const ( HookPhaseBefore TransitionHookPhase = "before_transition" HookPhaseAfter TransitionHookPhase = "after_transition" )
type TransitionMetadata ¶ added in v0.14.0
TransitionMetadata captures extra context for a transition.
type TransitionOption ¶ added in v0.14.0
type TransitionOption func(*transitionOptions)
TransitionOption customizes state machine behavior.
func WithAfterTransitionHook ¶ added in v0.14.0
func WithAfterTransitionHook(h TransitionHook) TransitionOption
WithAfterTransitionHook adds a hook executed after the status update succeeds.
func WithBeforeTransitionHook ¶ added in v0.14.0
func WithBeforeTransitionHook(h TransitionHook) TransitionOption
WithBeforeTransitionHook adds a hook executed before the status update.
func WithForceTransition ¶ added in v0.14.0
func WithForceTransition() TransitionOption
WithForceTransition bypasses validation rules (use sparingly).
func WithSuspensionTime ¶ added in v0.14.0
func WithSuspensionTime(t time.Time) TransitionOption
WithSuspensionTime overrides the timestamp recorded when entering the suspended state.
func WithTransitionMetadata ¶ added in v0.14.0
func WithTransitionMetadata(metadata map[string]any) TransitionOption
WithTransitionMetadata merges metadata into the transition context.
func WithTransitionReason ¶ added in v0.14.0
func WithTransitionReason(reason string) TransitionOption
WithTransitionReason sets the human-readable reason for the transition.
type User ¶
type User struct {
bun.BaseModel `bun:"table:users,alias:usr"`
ID uuid.UUID `bun:"id,pk,nullzero,type:uuid" json:"id,omitempty"`
Role UserRole `bun:"user_role,notnull" json:"user_role,omitempty"`
Status UserStatus `bun:"status,notnull,default:'active'" json:"status,omitempty"`
FirstName string `bun:"first_name,notnull" json:"first_name,omitempty"`
LastName string `bun:"last_name,notnull" json:"last_name,omitempty"`
Username string `bun:"username,notnull,unique" json:"username,omitempty"`
ProfilePicture string `bun:"profile_picture" json:"profile_picture,omitempty"`
Email string `bun:"email,notnull,unique" json:"email,omitempty"`
ExternalID string `bun:"external_id,nullzero" json:"external_id,omitempty"`
ExternalIDProvider string `bun:"external_id_provider,nullzero" json:"external_id_provider,omitempty"`
Phone string `bun:"phone_number" json:"phone_number,omitempty"`
PasswordHash string `bun:"password_hash" json:"password_hash,omitempty"`
EmailValidated bool `bun:"is_email_verified" json:"is_email_verified,omitempty"`
LoginAttempts int `bun:"login_attempts" json:"login_attempts,omitempty"`
LoginAttemptAt *time.Time `bun:"login_attempt_at" json:"login_attempt_at,omitempty"`
LoggedInAt *time.Time `bun:"loggedin_at" json:"loggedin_at,omitempty"`
SuspendedAt *time.Time `bun:"suspended_at,nullzero" json:"suspended_at,omitempty"`
Metadata map[string]any `bun:"metadata" json:"metadata,omitempty"`
ResetedAt *time.Time `bun:"reseted_at,nullzero" json:"reseted_at,omitempty"`
CreatedAt *time.Time `bun:"created_at,nullzero,default:current_timestamp" json:"created_at,omitempty"`
UpdatedAt *time.Time `bun:"updated_at,nullzero,default:current_timestamp" json:"updated_at,omitempty"`
DeletedAt *time.Time `bun:"deleted_at,soft_delete,nullzero" json:"deleted_at,omitempty"`
}
User is the user model
func FromContext ¶ added in v0.4.0
FromContext finds the user from the context.
func (*User) AddMetadata ¶
AddMetadata will append information to a metadata attribute TODO: make a trigger to merge metadata in database! https://stackoverflow.com/a/42954907/125083
func (*User) EnsureStatus ¶ added in v0.14.0
EnsureStatus sets a default status when empty to keep DB constraints satisfied.
func (*User) HasStatus ¶ added in v0.14.0
func (u *User) HasStatus(status UserStatus) bool
HasStatus reports whether the user is currently in the provided status.
func (*User) IsArchived ¶ added in v0.14.0
IsArchived returns true when the user is archived.
func (*User) IsDisabled ¶ added in v0.14.0
IsDisabled returns true when the user is disabled.
func (*User) IsPending ¶ added in v0.14.0
IsPending returns true when the user is pending activation.
func (*User) IsSuspended ¶ added in v0.14.0
IsSuspended returns true when the user is suspended.
type UserIdentity ¶ added in v0.24.0
type UserIdentity struct {
// contains filtered or unexported fields
}
UserIdentity adapts a User into the Identity interface for token generation.
func (UserIdentity) Email ¶ added in v0.24.0
func (u UserIdentity) Email() string
Email returns the user's email address.
func (UserIdentity) ID ¶ added in v0.24.0
func (u UserIdentity) ID() string
ID returns the user's ID as a string.
func (UserIdentity) Metadata ¶ added in v0.41.0
func (u UserIdentity) Metadata() map[string]any
Metadata returns a copy of user metadata that is safe for auth decorators.
func (UserIdentity) Role ¶ added in v0.24.0
func (u UserIdentity) Role() string
Role returns the user's role as a string.
func (UserIdentity) Status ¶ added in v0.24.0
func (u UserIdentity) Status() UserStatus
Status returns the user's lifecycle status.
func (UserIdentity) Username ¶ added in v0.24.0
func (u UserIdentity) Username() string
Username returns the user's username.
type UserProvider ¶
UserProvider handles users
func NewUserProvider ¶
func NewUserProvider(store UserTracker) *UserProvider
NewUserProvider will create a new UserProvider
func (UserProvider) FindIdentityByIdentifier ¶
func (UserProvider) VerifyIdentity ¶
func (u UserProvider) VerifyIdentity(ctx context.Context, identifier, password string) (Identity, error)
VerifyIdentity will find the user, compare to the password, and return identity
func (*UserProvider) WithLogger ¶ added in v0.4.0
func (u *UserProvider) WithLogger(l Logger) *UserProvider
func (*UserProvider) WithLoggerProvider ¶ added in v0.31.0
func (u *UserProvider) WithLoggerProvider(provider LoggerProvider) *UserProvider
WithLoggerProvider overrides the logger provider used by the user provider.
func (*UserProvider) WithLoginAttemptPolicy ¶ added in v0.45.0
func (u *UserProvider) WithLoginAttemptPolicy(policy LoginAttemptPolicy) *UserProvider
type UserRole ¶
type UserRole string
UserRole is the user's role
const ( // RoleGuest is an guest role (ie. view) RoleGuest UserRole = "guest" // RoleMember us a member (i.e. view, edit) RoleMember UserRole = "member" // RoleAdmin is an admin role (i.e. view, edit, create) RoleAdmin UserRole = "admin" // RoleOwner is an admin role (i.e. view, edit, create, delete) RoleOwner UserRole = "owner" )
func GetAllRoles ¶ added in v0.7.0
func GetAllRoles() []UserRole
GetAllRoles returns all predefined roles in hierarchical order
type UserStateMachine ¶ added in v0.14.0
type UserStateMachine interface {
Transition(ctx context.Context, actor ActorRef, user *User, target UserStatus, opts ...TransitionOption) (*User, error)
CurrentStatus(user *User) UserStatus
}
UserStateMachine defines lifecycle operations for users.
func NewUserStateMachine ¶ added in v0.14.0
func NewUserStateMachine(users Users, opts ...StateMachineOption) UserStateMachine
NewUserStateMachine returns the default implementation backed by the provided repository.
type UserStatus ¶ added in v0.14.0
type UserStatus string
UserStatus represents lifecycle states for a user account
const ( // UserStatusPending indicates the account exists but is not yet active UserStatusPending UserStatus = "pending" // UserStatusActive represents a fully active account UserStatusActive UserStatus = "active" // UserStatusSuspended indicates temporary suspension UserStatusSuspended UserStatus = "suspended" // UserStatusDisabled indicates manual disablement with no path back to active except admin intervention UserStatusDisabled UserStatus = "disabled" // UserStatusArchived signals the record should be treated as deleted/read-only UserStatusArchived UserStatus = "archived" )
func EnsureIdentityActive ¶ added in v0.45.0
func EnsureIdentityActive(identity Identity) (UserStatus, error)
EnsureIdentityActive applies the provider-neutral account lifecycle gate used by every authentication flow before issuing or handing off a session.
type UserTokenProvider ¶ added in v0.45.0
type UserTokenProvider interface {
AccessToken(ctx context.Context, request UserTokenRequest) (Secret, error)
}
type UserTokenRequest ¶ added in v0.45.0
type UserTokenRequest struct {
SessionHandle Secret
Binding ProviderSessionBinding
Target string
Capability TokenTargetCapability
}
type UserTracker ¶
type UserTracker interface {
GetByIdentifier(ctx context.Context, identifier string) (*User, error)
TrackAttemptedLogin(ctx context.Context, user *User) error
TrackSucccessfulLogin(ctx context.Context, user *User) error
}
UserTracker is a store we can use to retrieve users
type Users ¶
type Users interface {
repository.Repository[*User]
TrackAttemptedLogin(ctx context.Context, user *User) error
TrackAttemptedLoginTx(ctx context.Context, tx bun.IDB, user *User) error
TrackSucccessfulLogin(ctx context.Context, user *User) error
TrackSucccessfulLoginTx(ctx context.Context, tx bun.IDB, user *User) error
Register(ctx context.Context, user *User) (*User, error)
RegisterTx(ctx context.Context, tx bun.IDB, user *User) (*User, error)
GetOrRegisterTx(ctx context.Context, tx bun.IDB, record *User) (*User, error)
GetOrCreate(ctx context.Context, record *User) (*User, error)
GetOrCreateTx(ctx context.Context, tx bun.IDB, record *User) (*User, error)
Create(ctx context.Context, record *User, criteria ...repository.InsertCriteria) (*User, error)
CreateTx(ctx context.Context, tx bun.IDB, record *User, criteria ...repository.InsertCriteria) (*User, error)
Upsert(ctx context.Context, record *User, criteria ...repository.UpdateCriteria) (*User, error)
UpsertTx(ctx context.Context, tx bun.IDB, record *User, criteria ...repository.UpdateCriteria) (*User, error)
UpdateStatus(ctx context.Context, id uuid.UUID, status UserStatus, opts ...StatusUpdateOption) (*User, error)
UpdateStatusTx(ctx context.Context, tx bun.IDB, id uuid.UUID, status UserStatus, opts ...StatusUpdateOption) (*User, error)
Suspend(ctx context.Context, actor ActorRef, user *User, opts ...TransitionOption) (*User, error)
Reinstate(ctx context.Context, actor ActorRef, user *User, opts ...TransitionOption) (*User, error)
ResetPassword(ctx context.Context, id uuid.UUID, passwordHash string) error
ResetPasswordTx(ctx context.Context, tx bun.IDB, id uuid.UUID, passwordHash string) error
}
func NewUsersRepository ¶
func NewUsersRepository(db *bun.DB, opts ...UsersOption) Users
type UsersOption ¶ added in v0.14.0
type UsersOption func(*users)
func WithUsersStateMachine ¶ added in v0.14.0
func WithUsersStateMachine(sm UserStateMachine) UsersOption
func WithUsersStateMachineOptions ¶ added in v0.14.0
func WithUsersStateMachineOptions(options ...StateMachineOption) UsersOption
type ValidatedTokenContext ¶ added in v0.45.0
type ValidatedTokenContext struct {
Issuer string
Subject string
Audiences []string
SessionID string
ClientID string
AssuranceLevel string
AssuranceMethods []string
AuthenticationAt time.Time
IssuedAt time.Time
ExpiresAt time.Time
TokenID string
TenantID string
OrganizationID string
PermissionVersion string
}
ValidatedTokenContext contains only independently validated, typed claims. It deliberately excludes arbitrary raw provider claim maps.
func (ValidatedTokenContext) Clone ¶ added in v0.45.0
func (c ValidatedTokenContext) Clone() ValidatedTokenContext
type ValidationListener ¶ added in v0.23.0
type ValidationListener = jwtware.ValidationListener
ValidationListener aliases the jwtware listener so consumers can use auth helpers directly.
type WSAuthClaimsAdapter ¶ added in v0.9.0
type WSAuthClaimsAdapter struct {
// contains filtered or unexported fields
}
WSAuthClaimsAdapter adapts go-auth AuthClaims to go-router's WSAuthClaims interface
func (*WSAuthClaimsAdapter) CanCreate ¶ added in v0.9.0
func (w *WSAuthClaimsAdapter) CanCreate(resource string) bool
CanCreate checks if the user can create a specific resource
func (*WSAuthClaimsAdapter) CanDelete ¶ added in v0.9.0
func (w *WSAuthClaimsAdapter) CanDelete(resource string) bool
CanDelete checks if the user can delete a specific resource
func (*WSAuthClaimsAdapter) CanEdit ¶ added in v0.9.0
func (w *WSAuthClaimsAdapter) CanEdit(resource string) bool
CanEdit checks if the user can edit a specific resource
func (*WSAuthClaimsAdapter) CanRead ¶ added in v0.9.0
func (w *WSAuthClaimsAdapter) CanRead(resource string) bool
CanRead checks if the user can read a specific resource
func (*WSAuthClaimsAdapter) HasRole ¶ added in v0.9.0
func (w *WSAuthClaimsAdapter) HasRole(role string) bool
HasRole checks if the user has a specific role
func (*WSAuthClaimsAdapter) IsAtLeast ¶ added in v0.9.0
func (w *WSAuthClaimsAdapter) IsAtLeast(minRole string) bool
IsAtLeast checks if the user's role is at least the minimum required role
func (*WSAuthClaimsAdapter) Role ¶ added in v0.9.0
func (w *WSAuthClaimsAdapter) Role() string
Role returns the user's role
func (*WSAuthClaimsAdapter) Subject ¶ added in v0.9.0
func (w *WSAuthClaimsAdapter) Subject() string
Subject returns the subject claim
func (*WSAuthClaimsAdapter) UserID ¶ added in v0.9.0
func (w *WSAuthClaimsAdapter) UserID() string
UserID returns the user ID
type WSTokenValidator ¶ added in v0.9.0
type WSTokenValidator struct {
// contains filtered or unexported fields
}
WSTokenValidator implements go-router's WSTokenValidator interface using the go-auth TokenValidator for seamless WebSocket authentication
func NewWSTokenValidator ¶ added in v0.9.0
func NewWSTokenValidator(tokenValidator TokenValidator) *WSTokenValidator
NewWSTokenValidator creates a new WebSocket token validator using the provided TokenValidator
func (*WSTokenValidator) Validate ¶ added in v0.9.0
func (w *WSTokenValidator) Validate(tokenString string) (router.WSAuthClaims, error)
Validate validates a token string and returns WebSocket-compatible auth claims
Source Files
¶
- account_state.go
- activity.go
- assurance.go
- authenticator.go
- authorization_freshness.go
- authorization_version.go
- bcrypt.go
- bcrypt_cost_default.go
- claims.go
- claims_decorator.go
- claims_guard.go
- command_account_verification_request.go
- command_password_reset_finalize.go
- command_password_reset_initialize.go
- command_register_user.go
- ctx.go
- doc.go
- emergency_access.go
- errors.go
- feature_gate_helpers.go
- files.go
- freshness_invalidation.go
- freshness_policy.go
- http.go
- http_controller.go
- identifier_store.go
- identity_adapter.go
- identity_status.go
- middleware_helpers.go
- models.go
- permissions_cache_store.go
- permissions_cache_store_memory.go
- permissions_resolver.go
- permissions_resolver_request_cache.go
- permissions_resolver_strict.go
- provider_lifecycle.go
- provider_lifecycle_audit.go
- provider_lifecycle_coordinator.go
- provider_lifecycle_operations.go
- provider_lifecycle_policy.go
- provider_session_audit.go
- provider_session_cipher.go
- provider_session_http.go
- provider_session_manager.go
- provider_session_operations.go
- provider_session_targets.go
- provider_sessions.go
- provider_tokens.go
- repo_manager.go
- repo_users.go
- roles.go
- session.go
- state_machine.go
- template_helpers.go
- template_helpers_v7.go
- template_views.go
- temporary_password.go
- time.go
- token_mint.go
- token_service.go
- token_service_options.go
- token_validator.go
- types.go
- user_provider.go
- uuid_helpers.go
- websocket_adapter.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package activitymap provides helpers to normalize auth activity events into transport-agnostic records for external activity systems.
|
Package activitymap provides helpers to normalize auth activity events into transport-agnostic records for external activity systems. |
|
adapters
|
|
|
featuregate
module
|
|
|
goadmin
module
|
|
|
middleware
|
|
|
provider
|
|
|
auth0
Package auth0 provides Auth0 JWT validation and claims mapping for go-auth.
|
Package auth0 provides Auth0 JWT validation and claims mapping for go-auth. |
|
auth0/sync
Package sync provides optional Auth0 user synchronization helpers.
|
Package sync provides optional Auth0 user synchronization helpers. |
|
oidc
Package oidc implements generic OpenID Connect support for go-auth.
|
Package oidc implements generic OpenID Connect support for go-auth. |
|
oidc/preset
Package preset contains thin provider conventions for generic OIDC.
|
Package preset contains thin provider conventions for generic OIDC. |
|
supabase
Package supabase integrates Supabase Auth with go-auth's hardened OIDC and provider-session boundaries.
|
Package supabase integrates Supabase Auth with go-auth's hardened OIDC and provider-session boundaries. |
|
Package social provides OAuth2 social login primitives for go-auth.
|
Package social provides OAuth2 social login primitives for go-auth. |