Documentation
¶
Overview ¶
Package strategy defines the authentication strategy system. Strategies implement different authentication mechanisms (password, social OAuth, magic link, passkey, etc.) and are registered with priorities for ordered evaluation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrStrategyNotApplicable
deprecated
type ErrStrategyNotApplicable = NotApplicableError //nolint:errname // backward-compatible alias
ErrStrategyNotApplicable is an alias kept for backward compatibility.
Deprecated: Use NotApplicableError instead.
type NotApplicableError ¶
type NotApplicableError struct{}
NotApplicableError is returned when a strategy does not apply to the request.
func (NotApplicableError) Error ¶
func (e NotApplicableError) Error() string
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds registered auth strategies ordered by priority. Strategies are evaluated in registration order during authentication.
func NewRegistry ¶
NewRegistry creates a strategy registry with the given logger.
func (*Registry) Authenticate ¶
Authenticate evaluates all registered strategies in priority order. Returns the result from the first applicable strategy that succeeds.
func (*Registry) Register ¶
Register adds a strategy with a given priority. Lower priority values are evaluated first.
func (*Registry) Strategies ¶
Strategies returns the names of all registered strategies in priority order.
type Result ¶
type Result struct {
User *user.User `json:"user"`
Session *session.Session `json:"session"`
New bool `json:"new"` // True if user was created (signup)
}
Result represents the outcome of a successful authentication.
type Strategy ¶
type Strategy interface {
// Name returns the unique identifier for this strategy (e.g., "password", "google", "magic-link").
Name() string
// Authenticate attempts to authenticate a request using this strategy.
// Returns the authenticated user and a new session, or an error if authentication fails.
// If this strategy does not apply to the request, return NotApplicableError.
Authenticate(ctx context.Context, r *http.Request) (*Result, error)
}
Strategy is the interface that authentication strategies must implement.