Documentation
¶
Overview ¶
Package plugin defines the foundational contracts and shared execution context for authentication plugins.
Index ¶
- Constants
- Variables
- type AfterCreateSessionFunc
- type AfterCreateSessionInterceptor
- type AfterSignInFunc
- type AfterSignInInterceptor
- type AfterSignUpFunc
- type AfterSignUpInterceptor
- type AfterValidateSessionFunc
- type AfterValidateSessionInterceptor
- type BeforeCreateSessionFunc
- type BeforeCreateSessionInterceptor
- type BeforeSignInFunc
- type BeforeSignInInterceptor
- type BeforeSignUpFunc
- type BeforeSignUpInterceptor
- type BeforeValidateSessionFunc
- type BeforeValidateSessionInterceptor
- type Context
- func (c *Context) Crypto() CryptoUtils
- func (c *Context) Get(key string) (any, bool)
- func (c *Context) Hooks() *Hooks
- func (c *Context) MFAProvider() MFAProvider
- func (c *Context) Pipeline() *Pipeline
- func (c *Context) Session() SessionManager
- func (c *Context) SessionManager() SessionManager
- func (c *Context) Set(key string, value any)
- func (c *Context) SetHooks(h *Hooks)
- func (c *Context) SetMFAProvider(p MFAProvider)
- func (c *Context) SetPipeline(p *Pipeline)
- func (c *Context) SetSessionManager(sm SessionManager)
- type ContextOption
- type CryptoUtils
- type EmailVerificationReqHookFn
- type EmailVerifiedHookFn
- type ExtraContainer
- type Hooks
- func (h *Hooks) Dispatch(ctx context.Context, topic string, payload any)
- func (h *Hooks) DispatchAsync(ctx context.Context, topic string, payload any)
- func (h *Hooks) DispatchEmailVerificationRequested(ctx context.Context, email string, token *entity.VerificationToken)
- func (h *Hooks) DispatchEmailVerified(ctx context.Context, user *entity.User)
- func (h *Hooks) DispatchPasswordChanged(ctx context.Context, user *entity.User)
- func (h *Hooks) DispatchPasswordResetCompleted(ctx context.Context, userID string)
- func (h *Hooks) DispatchPasswordResetRequested(ctx context.Context, email string, token *entity.VerificationToken)
- func (h *Hooks) DispatchSessionCreated(ctx context.Context, session *entity.Session)
- func (h *Hooks) DispatchSessionRevoked(ctx context.Context, token string, session *entity.Session)
- func (h *Hooks) DispatchSessionValidated(ctx context.Context, data *dto.SessionData)
- func (h *Hooks) DispatchUserSignedIn(ctx context.Context, data *dto.SessionData)
- func (h *Hooks) DispatchUserSignedUp(ctx context.Context, user *entity.User)
- func (h *Hooks) OnEmailVerificationRequested(fn func(ctx context.Context, email string, token *entity.VerificationToken)) *Hooks
- func (h *Hooks) OnEmailVerified(fn func(ctx context.Context, user *entity.User)) *Hooks
- func (h *Hooks) OnPasswordChanged(fn func(ctx context.Context, user *entity.User)) *Hooks
- func (h *Hooks) OnPasswordResetCompleted(fn func(ctx context.Context, userID string)) *Hooks
- func (h *Hooks) OnPasswordResetRequested(fn func(ctx context.Context, email string, token *entity.VerificationToken)) *Hooks
- func (h *Hooks) OnSessionCreated(fn func(ctx context.Context, session *entity.Session)) *Hooks
- func (h *Hooks) OnSessionRevoked(fn func(ctx context.Context, token string, session *entity.Session)) *Hooks
- func (h *Hooks) OnSessionValidated(fn func(ctx context.Context, data *dto.SessionData)) *Hooks
- func (h *Hooks) OnUserSignedIn(fn func(ctx context.Context, data *dto.SessionData)) *Hooks
- func (h *Hooks) OnUserSignedUp(fn func(ctx context.Context, user *entity.User)) *Hooks
- func (h *Hooks) Publish(topic string, args ...any)
- func (h *Hooks) SetAsync(async bool)
- func (h *Hooks) Subscribe(topic string, handler any) *Hooks
- type MFAProvider
- type PasswordChangedHookFn
- type PasswordResetCompHookFn
- type PasswordResetReqHookFn
- type Pipeline
- func (p *Pipeline) AddInterceptor(interceptors ...any) *Pipeline
- func (p *Pipeline) AfterCreateSession(fns ...AfterCreateSessionFunc) *Pipeline
- func (p *Pipeline) AfterSignIn(fns ...AfterSignInFunc) *Pipeline
- func (p *Pipeline) AfterSignUp(fns ...AfterSignUpFunc) *Pipeline
- func (p *Pipeline) BeforeCreateSession(fns ...BeforeCreateSessionFunc) *Pipeline
- func (p *Pipeline) BeforeSignIn(fns ...BeforeSignInFunc) *Pipeline
- func (p *Pipeline) BeforeSignUp(fns ...BeforeSignUpFunc) *Pipeline
- func (p *Pipeline) ExecuteAfterCreateSession(ctx context.Context, session *entity.Session, extraInterceptors ...any) error
- func (p *Pipeline) ExecuteAfterSignIn(ctx context.Context, data *dto.SessionData, extraInterceptors ...any) error
- func (p *Pipeline) ExecuteAfterSignUp(ctx context.Context, user *entity.User, extraInterceptors ...any) error
- func (p *Pipeline) ExecuteAfterValidateSession(ctx context.Context, data *dto.SessionData, extraInterceptors ...any) error
- func (p *Pipeline) ExecuteBeforeCreateSession(ctx context.Context, params *dto.CreateSessionParams, extraInterceptors ...any) error
- func (p *Pipeline) ExecuteBeforeSignIn(ctx context.Context, input *dto.SignInParams, extraInterceptors ...any) error
- func (p *Pipeline) ExecuteBeforeSignUp(ctx context.Context, input *dto.SignUpParams, extraInterceptors ...any) error
- func (p *Pipeline) ExecuteBeforeValidateSession(ctx context.Context, token string, extraInterceptors ...any) error
- func (p *Pipeline) UseSignInMiddleware(mws ...SignInMiddleware) *Pipeline
- func (p *Pipeline) UseSignUpMiddleware(mws ...SignUpMiddleware) *Pipeline
- type Plugin
- type SessionCreatedHookFn
- type SessionInterceptor
- type SessionManager
- type SessionOption
- func WithCallInterceptor(interceptors ...any) SessionOption
- func WithDeviceID(deviceID string) SessionOption
- func WithDuration(d time.Duration) SessionOption
- func WithExtra(key string, val any) SessionOption
- func WithExtraMap(m map[string]any) SessionOption
- func WithIPAddress(ip string) SessionOption
- func WithRememberMe(remember bool) SessionOption
- func WithUserAgent(ua string) SessionOption
- type SessionOptions
- type SessionRevokedHookFn
- type SessionValidatedHookFn
- type SignInHandler
- type SignInInterceptor
- type SignInMiddleware
- type SignUpHandler
- type SignUpInterceptor
- type SignUpMiddleware
- type UserSignedInHookFn
- type UserSignedUpHookFn
- type ValidateSessionInterceptor
Constants ¶
const ( // ContextKeyUser stores the current authenticated user domain entity. ContextKeyUser = "auth:user" // ContextKeySession stores the active session domain entity. ContextKeySession = "auth:session" // ContextKeyAccount stores the active account entity. ContextKeyAccount = "auth:account" // ContextKeyBearerToken stores the bearer or access token string. ContextKeyBearerToken = "auth:bearer_token" )
Standard context key constants stored in the shared thread-safe plugin.Context store.
Variables ¶
var ErrSessionManagerRequired = errors.New("plugin: session manager is required")
ErrSessionManagerRequired is returned when a session operation is attempted but no SessionManager is configured in context.
Functions ¶
This section is empty.
Types ¶
type AfterCreateSessionFunc ¶ added in v1.0.0
Functional adapters allowing plain functions to satisfy interceptor interfaces.
func (AfterCreateSessionFunc) AfterCreateSession ¶ added in v1.0.0
type AfterCreateSessionInterceptor ¶ added in v1.0.0
type AfterCreateSessionInterceptor interface {
AfterCreateSession(ctx context.Context, session *entity.Session) error
}
Single-method interface contracts for maximum flexibility and duck typing.
type AfterSignInFunc ¶ added in v1.0.0
type AfterSignInFunc func(ctx context.Context, data *dto.SessionData) error
Functional adapters allowing plain functions to satisfy interceptor interfaces.
func (AfterSignInFunc) AfterSignIn ¶ added in v1.0.0
func (f AfterSignInFunc) AfterSignIn(ctx context.Context, data *dto.SessionData) error
type AfterSignInInterceptor ¶ added in v1.0.0
type AfterSignInInterceptor interface {
AfterSignIn(ctx context.Context, data *dto.SessionData) error
}
Single-method interface contracts for maximum flexibility and duck typing.
type AfterSignUpFunc ¶ added in v1.0.0
Functional adapters allowing plain functions to satisfy interceptor interfaces.
func (AfterSignUpFunc) AfterSignUp ¶ added in v1.0.0
type AfterSignUpInterceptor ¶ added in v1.0.0
Single-method interface contracts for maximum flexibility and duck typing.
type AfterValidateSessionFunc ¶ added in v1.0.0
type AfterValidateSessionFunc func(ctx context.Context, data *dto.SessionData) error
Functional adapters allowing plain functions to satisfy interceptor interfaces.
func (AfterValidateSessionFunc) AfterValidateSession ¶ added in v1.0.0
func (f AfterValidateSessionFunc) AfterValidateSession(ctx context.Context, data *dto.SessionData) error
type AfterValidateSessionInterceptor ¶ added in v1.0.0
type AfterValidateSessionInterceptor interface {
AfterValidateSession(ctx context.Context, data *dto.SessionData) error
}
Single-method interface contracts for maximum flexibility and duck typing.
type BeforeCreateSessionFunc ¶ added in v1.0.0
type BeforeCreateSessionFunc func(ctx context.Context, params *dto.CreateSessionParams) error
Functional adapters allowing plain functions to satisfy interceptor interfaces.
func (BeforeCreateSessionFunc) BeforeCreateSession ¶ added in v1.0.0
func (f BeforeCreateSessionFunc) BeforeCreateSession(ctx context.Context, params *dto.CreateSessionParams) error
type BeforeCreateSessionInterceptor ¶ added in v1.0.0
type BeforeCreateSessionInterceptor interface {
BeforeCreateSession(ctx context.Context, params *dto.CreateSessionParams) error
}
Single-method interface contracts for maximum flexibility and duck typing.
type BeforeSignInFunc ¶ added in v1.0.0
type BeforeSignInFunc func(ctx context.Context, input *dto.SignInParams) error
Functional adapters allowing plain functions to satisfy interceptor interfaces.
func (BeforeSignInFunc) BeforeSignIn ¶ added in v1.0.0
func (f BeforeSignInFunc) BeforeSignIn(ctx context.Context, input *dto.SignInParams) error
type BeforeSignInInterceptor ¶ added in v1.0.0
type BeforeSignInInterceptor interface {
BeforeSignIn(ctx context.Context, input *dto.SignInParams) error
}
Single-method interface contracts for maximum flexibility and duck typing.
type BeforeSignUpFunc ¶ added in v1.0.0
type BeforeSignUpFunc func(ctx context.Context, input *dto.SignUpParams) error
Functional adapters allowing plain functions to satisfy interceptor interfaces.
func (BeforeSignUpFunc) BeforeSignUp ¶ added in v1.0.0
func (f BeforeSignUpFunc) BeforeSignUp(ctx context.Context, input *dto.SignUpParams) error
type BeforeSignUpInterceptor ¶ added in v1.0.0
type BeforeSignUpInterceptor interface {
BeforeSignUp(ctx context.Context, input *dto.SignUpParams) error
}
Single-method interface contracts for maximum flexibility and duck typing.
type BeforeValidateSessionFunc ¶ added in v1.0.0
Functional adapters allowing plain functions to satisfy interceptor interfaces.
func (BeforeValidateSessionFunc) BeforeValidateSession ¶ added in v1.0.0
func (f BeforeValidateSessionFunc) BeforeValidateSession(ctx context.Context, token string) error
type BeforeValidateSessionInterceptor ¶ added in v1.0.0
type BeforeValidateSessionInterceptor interface {
BeforeValidateSession(ctx context.Context, token string) error
}
Single-method interface contracts for maximum flexibility and duck typing.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context represents the shared environment provided to plugins upon initialization, containing cryptographic tools, synchronous execution pipelines, typed lifecycle hooks, central session management, and a thread-safe key-value store.
func NewContext ¶
func NewContext(crypto CryptoUtils, opts ...ContextOption) *Context
NewContext creates a new Context with the specified cryptographic utilities and optional pipeline/hooks.
func (*Context) Crypto ¶
func (c *Context) Crypto() CryptoUtils
Crypto returns the cryptographic utilities instance.
func (*Context) Hooks ¶ added in v1.0.0
Hooks returns the typed lifecycle hooks and event dispatcher.
func (*Context) MFAProvider ¶ added in v1.0.0
func (c *Context) MFAProvider() MFAProvider
MFAProvider returns the registered multi-factor authentication provider, or nil if none is configured.
func (*Context) Pipeline ¶ added in v1.0.0
Pipeline returns the synchronous interceptor pipeline for authentication operations.
func (*Context) Session ¶ added in v1.0.0
func (c *Context) Session() SessionManager
Session returns the central SessionManager instance available in the execution environment.
func (*Context) SessionManager ¶ added in v1.0.0
func (c *Context) SessionManager() SessionManager
SessionManager returns the central SessionManager instance (alias for Session).
func (*Context) SetHooks ¶ added in v1.0.0
SetHooks updates the lifecycle hooks instance in the shared context.
func (*Context) SetMFAProvider ¶ added in v1.0.0
func (c *Context) SetMFAProvider(p MFAProvider)
SetMFAProvider registers an MFAProvider into the shared plugin context.
func (*Context) SetPipeline ¶ added in v1.0.0
SetPipeline updates the synchronous interceptor pipeline in the shared context.
func (*Context) SetSessionManager ¶ added in v1.0.0
func (c *Context) SetSessionManager(sm SessionManager)
SetSessionManager configures the central SessionManager instance into the shared context.
type ContextOption ¶ added in v1.0.0
type ContextOption func(*Context)
ContextOption allows configuring optional dependencies into the shared plugin Context.
func WithContextSessionManager ¶ added in v1.0.0
func WithContextSessionManager(sm SessionManager) ContextOption
WithContextSessionManager configures a SessionManager into the plugin Context.
func WithHooks ¶ added in v1.0.0
func WithHooks(h *Hooks) ContextOption
WithHooks configures a custom Hooks dispatcher into the plugin Context.
func WithMFAProvider ¶ added in v1.0.0
func WithMFAProvider(p MFAProvider) ContextOption
WithMFAProvider configures an MFAProvider into the plugin Context.
func WithPipeline ¶ added in v1.0.0
func WithPipeline(p *Pipeline) ContextOption
WithPipeline configures a custom Pipeline into the plugin Context.
type CryptoUtils ¶
type CryptoUtils interface {
HashPassword(password string) (string, error)
ComparePassword(hash, password string) bool
GenerateRandomToken(length int) (string, error)
}
CryptoUtils defines cryptographic utility operations provided to plugins (hashing, comparison, random tokens).
type EmailVerificationReqHookFn ¶ added in v1.0.0
type EmailVerificationReqHookFn = func(ctx context.Context, email string, token *entity.VerificationToken)
Typed signatures for core lifecycle callbacks.
type EmailVerifiedHookFn ¶ added in v1.0.0
Typed signatures for core lifecycle callbacks.
type ExtraContainer ¶ added in v0.14.0
type ExtraContainer = entity.ExtraContainer
ExtraContainer provides a reusable map for dynamic metadata with Set and Get methods. Embed plugin.ExtraContainer in DTO parameter structs to eliminate repetitive metadata handling code. TODO: Use entity.ExtraContainer directly instead of aliasing.
type Hooks ¶ added in v1.0.0
type Hooks struct {
// contains filtered or unexported fields
}
Hooks provides strongly typed lifecycle hooks and a native pub/sub event dispatcher with zero external dependencies, complete type safety, and context awareness.
func (*Hooks) Dispatch ¶ added in v1.0.0
Dispatch invokes all registered subscribers for the given topic with the provided payload.
func (*Hooks) DispatchAsync ¶ added in v1.0.0
DispatchAsync explicitly invokes topic subscribers in a background goroutine.
func (*Hooks) DispatchEmailVerificationRequested ¶ added in v1.0.0
func (h *Hooks) DispatchEmailVerificationRequested(ctx context.Context, email string, token *entity.VerificationToken)
DispatchEmailVerificationRequested dispatches email verification token notifications.
func (*Hooks) DispatchEmailVerified ¶ added in v1.0.0
DispatchEmailVerified dispatches email verified notifications.
func (*Hooks) DispatchPasswordChanged ¶ added in v1.0.0
DispatchPasswordChanged dispatches password changed notifications.
func (*Hooks) DispatchPasswordResetCompleted ¶ added in v1.0.0
DispatchPasswordResetCompleted dispatches password reset completed notifications.
func (*Hooks) DispatchPasswordResetRequested ¶ added in v1.0.0
func (h *Hooks) DispatchPasswordResetRequested(ctx context.Context, email string, token *entity.VerificationToken)
DispatchPasswordResetRequested dispatches password reset request notifications.
func (*Hooks) DispatchSessionCreated ¶ added in v1.0.0
DispatchSessionCreated dispatches session creation notifications to all registered listeners.
func (*Hooks) DispatchSessionRevoked ¶ added in v1.0.0
DispatchSessionRevoked dispatches session revocation notifications.
func (*Hooks) DispatchSessionValidated ¶ added in v1.0.0
func (h *Hooks) DispatchSessionValidated(ctx context.Context, data *dto.SessionData)
DispatchSessionValidated dispatches session validation notifications.
func (*Hooks) DispatchUserSignedIn ¶ added in v1.0.0
func (h *Hooks) DispatchUserSignedIn(ctx context.Context, data *dto.SessionData)
DispatchUserSignedIn dispatches user sign-in notifications to all registered listeners.
func (*Hooks) DispatchUserSignedUp ¶ added in v1.0.0
DispatchUserSignedUp dispatches user sign-up notifications to all registered listeners.
func (*Hooks) OnEmailVerificationRequested ¶ added in v1.0.0
func (h *Hooks) OnEmailVerificationRequested(fn func(ctx context.Context, email string, token *entity.VerificationToken)) *Hooks
OnEmailVerificationRequested registers a callback invoked when an email verification token is generated.
func (*Hooks) OnEmailVerified ¶ added in v1.0.0
OnEmailVerified registers a callback invoked after an email address has been verified.
func (*Hooks) OnPasswordChanged ¶ added in v1.0.0
OnPasswordChanged registers a callback invoked after a user password has been updated.
func (*Hooks) OnPasswordResetCompleted ¶ added in v1.0.0
OnPasswordResetCompleted registers a callback invoked after a password has been reset.
func (*Hooks) OnPasswordResetRequested ¶ added in v1.0.0
func (h *Hooks) OnPasswordResetRequested(fn func(ctx context.Context, email string, token *entity.VerificationToken)) *Hooks
OnPasswordResetRequested registers a callback invoked when a password reset token is generated.
func (*Hooks) OnSessionCreated ¶ added in v1.0.0
OnSessionCreated registers a callback invoked whenever an active user session is persisted.
func (*Hooks) OnSessionRevoked ¶ added in v1.0.0
func (h *Hooks) OnSessionRevoked(fn func(ctx context.Context, token string, session *entity.Session)) *Hooks
OnSessionRevoked registers a callback invoked whenever an active session is revoked.
func (*Hooks) OnSessionValidated ¶ added in v1.0.0
OnSessionValidated registers a callback invoked whenever an active session is successfully validated.
func (*Hooks) OnUserSignedIn ¶ added in v1.0.0
OnUserSignedIn registers a callback invoked after a user successfully signs in and session is issued.
func (*Hooks) OnUserSignedUp ¶ added in v1.0.0
OnUserSignedUp registers a callback invoked after a new user registers successfully.
func (*Hooks) Publish ¶ added in v1.0.0
Publish is a convenience wrapper enabling drop-in compatibility for plugins and tests. It accepts either (topic, payload) or (topic, ctx, payload).
func (*Hooks) SetAsync ¶ added in v1.0.0
SetAsync configures whether lifecycle hooks and events run asynchronously.
type MFAProvider ¶ added in v1.0.0
type MFAProvider interface {
// RequiresMFA evaluates whether the user must complete an MFA challenge.
// If the client has supplied an authorized trusted device token,
// RequiresMFA can verify the device trust and return false to bypass the challenge.
RequiresMFA(ctx context.Context, userID string, extra map[string]any) (bool, error)
// CreateMFAChallenge generates a secure, short-lived anti-tampering challenge for the user.
CreateMFAChallenge(ctx context.Context, userID string, factor string) (*dto.AuthChallenge, error)
// VerifyMFAChallenge validates the challenge token and submitted code, atomically revoking the challenge on success.
VerifyMFAChallenge(ctx context.Context, params dto.VerifyChallengeParams) (*dto.ChallengeVerificationResult, error)
}
MFAProvider defines the contract for multi-factor authentication engines (e.g. TwoFactor plugin). It decouples primary credential plugins (emailpassword, username, phonenumber) and the core Auth engine from concrete plugin implementations.
type PasswordChangedHookFn ¶ added in v1.0.0
Typed signatures for core lifecycle callbacks.
type PasswordResetCompHookFn ¶ added in v1.0.0
Typed signatures for core lifecycle callbacks.
type PasswordResetReqHookFn ¶ added in v1.0.0
type PasswordResetReqHookFn = func(ctx context.Context, email string, token *entity.VerificationToken)
Typed signatures for core lifecycle callbacks.
type Pipeline ¶ added in v1.0.0
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline manages sequential interceptors and middlewares for authentication operations.
func NewPipeline ¶ added in v1.0.0
func NewPipeline() *Pipeline
NewPipeline initializes a new empty Pipeline.
func (*Pipeline) AddInterceptor ¶ added in v1.0.0
AddInterceptor inspects and registers any supported interceptor implementation.
func (*Pipeline) AfterCreateSession ¶ added in v1.0.0
func (p *Pipeline) AfterCreateSession(fns ...AfterCreateSessionFunc) *Pipeline
AfterCreateSession registers functional interceptors executed after session persistence.
func (*Pipeline) AfterSignIn ¶ added in v1.0.0
func (p *Pipeline) AfterSignIn(fns ...AfterSignInFunc) *Pipeline
AfterSignIn registers functional interceptors executed after successful user sign-in.
func (*Pipeline) AfterSignUp ¶ added in v1.0.0
func (p *Pipeline) AfterSignUp(fns ...AfterSignUpFunc) *Pipeline
AfterSignUp registers functional interceptors executed after user registration.
func (*Pipeline) BeforeCreateSession ¶ added in v1.0.0
func (p *Pipeline) BeforeCreateSession(fns ...BeforeCreateSessionFunc) *Pipeline
BeforeCreateSession registers functional interceptors executed before session persistence.
func (*Pipeline) BeforeSignIn ¶ added in v1.0.0
func (p *Pipeline) BeforeSignIn(fns ...BeforeSignInFunc) *Pipeline
BeforeSignIn registers functional interceptors executed before user sign-in.
func (*Pipeline) BeforeSignUp ¶ added in v1.0.0
func (p *Pipeline) BeforeSignUp(fns ...BeforeSignUpFunc) *Pipeline
BeforeSignUp registers functional interceptors executed before user registration.
func (*Pipeline) ExecuteAfterCreateSession ¶ added in v1.0.0
func (p *Pipeline) ExecuteAfterCreateSession(ctx context.Context, session *entity.Session, extraInterceptors ...any) error
ExecuteAfterCreateSession runs registered AfterCreateSession interceptors sequentially, aborting immediately on error.
func (*Pipeline) ExecuteAfterSignIn ¶ added in v1.0.0
func (p *Pipeline) ExecuteAfterSignIn(ctx context.Context, data *dto.SessionData, extraInterceptors ...any) error
ExecuteAfterSignIn runs registered AfterSignIn interceptors sequentially, aborting immediately on error.
func (*Pipeline) ExecuteAfterSignUp ¶ added in v1.0.0
func (p *Pipeline) ExecuteAfterSignUp(ctx context.Context, user *entity.User, extraInterceptors ...any) error
ExecuteAfterSignUp runs registered AfterSignUp interceptors sequentially, aborting immediately on error.
func (*Pipeline) ExecuteAfterValidateSession ¶ added in v1.0.0
func (p *Pipeline) ExecuteAfterValidateSession(ctx context.Context, data *dto.SessionData, extraInterceptors ...any) error
ExecuteAfterValidateSession runs registered AfterValidateSession interceptors sequentially.
func (*Pipeline) ExecuteBeforeCreateSession ¶ added in v1.0.0
func (p *Pipeline) ExecuteBeforeCreateSession(ctx context.Context, params *dto.CreateSessionParams, extraInterceptors ...any) error
ExecuteBeforeCreateSession runs registered BeforeCreateSession interceptors sequentially, aborting immediately on error.
func (*Pipeline) ExecuteBeforeSignIn ¶ added in v1.0.0
func (p *Pipeline) ExecuteBeforeSignIn(ctx context.Context, input *dto.SignInParams, extraInterceptors ...any) error
ExecuteBeforeSignIn runs registered BeforeSignIn interceptors sequentially, aborting immediately on error.
func (*Pipeline) ExecuteBeforeSignUp ¶ added in v1.0.0
func (p *Pipeline) ExecuteBeforeSignUp(ctx context.Context, input *dto.SignUpParams, extraInterceptors ...any) error
ExecuteBeforeSignUp runs registered BeforeSignUp interceptors sequentially, aborting immediately on error.
func (*Pipeline) ExecuteBeforeValidateSession ¶ added in v1.0.0
func (p *Pipeline) ExecuteBeforeValidateSession(ctx context.Context, token string, extraInterceptors ...any) error
ExecuteBeforeValidateSession runs registered BeforeValidateSession interceptors sequentially.
func (*Pipeline) UseSignInMiddleware ¶ added in v1.0.0
func (p *Pipeline) UseSignInMiddleware(mws ...SignInMiddleware) *Pipeline
UseSignInMiddleware registers onion middlewares wrapping the complete sign-in execution.
func (*Pipeline) UseSignUpMiddleware ¶ added in v1.0.0
func (p *Pipeline) UseSignUpMiddleware(mws ...SignUpMiddleware) *Pipeline
UseSignUpMiddleware registers onion middlewares wrapping the complete sign-up execution.
type Plugin ¶
type Plugin interface {
// ID returns a unique identifier for the plugin (e.g., "email-password", "two-factor").
ID() string
// Init initializes the plugin with the shared execution context.
Init(ctx *Context) error
}
Plugin defines the interface that all modular authentication plugins must implement.
type SessionCreatedHookFn ¶ added in v1.0.0
Typed signatures for core lifecycle callbacks.
type SessionInterceptor ¶ added in v1.0.0
type SessionInterceptor interface {
BeforeCreateSession(ctx context.Context, params *dto.CreateSessionParams) error
AfterCreateSession(ctx context.Context, session *entity.Session) error
}
SessionInterceptor intercepts session creation and lifecycle operations in SessionManager.
type SessionManager ¶ added in v1.0.0
type SessionManager interface {
// CreateSession creates and persists a new authenticated user session.
CreateSession(ctx context.Context, userID string, opts ...SessionOption) (*entity.Session, error)
// ValidateSession validates a session token, returning combined user and session data.
ValidateSession(ctx context.Context, token string) (*dto.SessionData, error)
// RevokeSession revokes an active session by its unique raw token string.
RevokeSession(ctx context.Context, token string) error
// GetSessionByToken retrieves an active session by its token string without loading the user.
GetSessionByToken(ctx context.Context, token string) (*entity.Session, error)
// RevokeSessionsByUserID revokes all active sessions belonging to the specified user.
RevokeSessionsByUserID(ctx context.Context, userID string) error
}
SessionManager defines the contract for central session management exposed to plugins and the core engine.
type SessionOption ¶ added in v1.0.0
type SessionOption func(*SessionOptions)
SessionOption represents a functional option for configuring session creation.
func WithCallInterceptor ¶ added in v1.0.0
func WithCallInterceptor(interceptors ...any) SessionOption
WithCallInterceptor adds per-call interceptors executed during authentication operations.
func WithDeviceID ¶ added in v1.0.0
func WithDeviceID(deviceID string) SessionOption
WithDeviceID sets the device identifier for the session.
func WithDuration ¶ added in v1.0.0
func WithDuration(d time.Duration) SessionOption
WithDuration sets a custom expiration duration for the session.
func WithExtra ¶ added in v1.0.0
func WithExtra(key string, val any) SessionOption
WithExtra sets a dynamic key-value pair in the session extra metadata.
func WithExtraMap ¶ added in v1.0.0
func WithExtraMap(m map[string]any) SessionOption
WithExtraMap copies a map of key-value pairs into the session extra metadata.
func WithIPAddress ¶ added in v1.0.0
func WithIPAddress(ip string) SessionOption
WithIPAddress sets the client IP address for the session.
func WithRememberMe ¶ added in v1.0.0
func WithRememberMe(remember bool) SessionOption
WithRememberMe toggles extended session lifetime.
func WithUserAgent ¶ added in v1.0.0
func WithUserAgent(ua string) SessionOption
WithUserAgent sets the client User-Agent string for the session.
type SessionOptions ¶ added in v1.0.0
type SessionOptions struct {
// Duration overrides the default validity duration for the session.
Duration time.Duration
// RememberMe indicates whether to apply the extended remember-me session duration.
RememberMe bool
// IPAddress records the client IP address initiating the session.
IPAddress string
// UserAgent records the client user agent string initiating the session.
UserAgent string
// DeviceID optionally identifies the physical device initiating the session.
DeviceID string
// ExtraContainer provides dynamic key-value metadata for the session.
ExtraContainer
// Interceptors contains optional per-call interceptors executed during authentication and session creation.
Interceptors []any
}
SessionOptions holds configurable options when creating or modifying a session.
type SessionRevokedHookFn ¶ added in v1.0.0
Typed signatures for core lifecycle callbacks.
type SessionValidatedHookFn ¶ added in v1.0.0
type SessionValidatedHookFn = func(ctx context.Context, data *dto.SessionData)
Typed signatures for core lifecycle callbacks.
type SignInHandler ¶ added in v1.0.0
type SignInHandler func(ctx context.Context, input *dto.SignInParams) (*dto.SessionData, error)
Onion middleware signatures for developers preferring middleware chaining.
type SignInInterceptor ¶ added in v1.0.0
type SignInInterceptor interface {
BeforeSignIn(ctx context.Context, input *dto.SignInParams) error
AfterSignIn(ctx context.Context, data *dto.SessionData) error
}
SignInInterceptor intercepts the user sign-in authentication flow.
type SignInMiddleware ¶ added in v1.0.0
type SignInMiddleware func(next SignInHandler) SignInHandler
Onion middleware signatures for developers preferring middleware chaining.
type SignUpHandler ¶ added in v1.0.0
Onion middleware signatures for developers preferring middleware chaining.
type SignUpInterceptor ¶ added in v1.0.0
type SignUpInterceptor interface {
BeforeSignUp(ctx context.Context, input *dto.SignUpParams) error
AfterSignUp(ctx context.Context, user *entity.User) error
}
SignUpInterceptor intercepts the user registration sign-up flow.
type SignUpMiddleware ¶ added in v1.0.0
type SignUpMiddleware func(next SignUpHandler) SignUpHandler
Onion middleware signatures for developers preferring middleware chaining.
type UserSignedInHookFn ¶ added in v1.0.0
type UserSignedInHookFn = func(ctx context.Context, data *dto.SessionData)
Typed signatures for core lifecycle callbacks.
type UserSignedUpHookFn ¶ added in v1.0.0
Typed signatures for core lifecycle callbacks.