authn

package
v1.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIKeyOnly

func APIKeyOnly(app apikey.Manager, modes ...ErrorMode) fiber.Handler

func Any

func Any(authenticators ...Authenticator) fiber.Handler

func AnyWithMode

func AnyWithMode(mode ErrorMode, authenticators ...Authenticator) fiber.Handler

func SetPrincipalLocals

func SetPrincipalLocals(c fiber.Ctx, p *Principal)

func SetPrincipalsLocals

func SetPrincipalsLocals(c fiber.Ctx, principals []*Principal)

func UserAndAPIKey

func UserAndAPIKey(user token.Manager, app apikey.Manager, modes ...ErrorMode) fiber.Handler

func UserOnly

func UserOnly(user token.Manager, modes ...ErrorMode) fiber.Handler

func WithPrincipal

func WithPrincipal(ctx context.Context, p *Principal) context.Context

func WithPrincipals

func WithPrincipals(ctx context.Context, principals []*Principal) context.Context

Types

type Authenticator

type Authenticator interface {
	// Authenticate returns:
	// - principal when auth succeeds
	// - matched=true when credential source was present and processed
	// - err when processing/validation failed
	Authenticate(c fiber.Ctx) (*Principal, bool, error)
}

func APIKeyAuthenticator

func APIKeyAuthenticator(app apikey.Manager) Authenticator

func UserTokenAuthenticator

func UserTokenAuthenticator(user token.Manager) Authenticator

type AuthenticatorFunc

type AuthenticatorFunc func(c fiber.Ctx) (*Principal, bool, error)

func (AuthenticatorFunc) Authenticate

func (f AuthenticatorFunc) Authenticate(c fiber.Ctx) (*Principal, bool, error)

type ErrorMode

type ErrorMode string
const (
	ErrorModeFailFast   ErrorMode = "fail_fast"
	ErrorModeBestEffort ErrorMode = "best_effort"
)

type Principal

type Principal struct {
	Type    PrincipalType `json:"type"`
	Subject string        `json:"subject,omitempty"`
	AppID   string        `json:"app_id,omitempty"`
	KeyID   string        `json:"key_id,omitempty"`
	Scopes  []string      `json:"scopes,omitempty"`
	Roles   []string      `json:"roles,omitempty"`
}

func PrincipalFromContext

func PrincipalFromContext(ctx context.Context) (*Principal, bool)

func PrincipalFromLocals

func PrincipalFromLocals(c fiber.Ctx) (*Principal, bool)

func PrincipalsFromContext

func PrincipalsFromContext(ctx context.Context) ([]*Principal, bool)

func PrincipalsFromLocals

func PrincipalsFromLocals(c fiber.Ctx) ([]*Principal, bool)

type PrincipalType

type PrincipalType string
const (
	PrincipalUser PrincipalType = "user"
	PrincipalApp  PrincipalType = "app"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL