Documentation
¶
Index ¶
- Variables
- func NewBearer(authenticators []TokenAuthenticator, opts ...BearerOption) api.AuthStrategy
- func NewNone() api.AuthStrategy
- func NewRegistry(strategies ...api.AuthStrategy) api.AuthStrategyRegistry
- func NewSignature(loader ExternalAppLoader, opts ...SignatureOption) api.AuthStrategy
- type AccessTokenAuthenticator
- type BearerOption
- type BearerStrategy
- type ExternalApp
- type ExternalAppLoader
- type NoneStrategy
- type Registry
- type SignatureOption
- type SignatureStrategy
- type TokenAuthenticator
Constants ¶
This section is empty.
Variables ¶
var ( ErrMissingToken = errors.New("missing token") ErrInvalidToken = errors.New("invalid token") ErrMissingAuthHeaders = errors.New("missing authentication headers") ErrInvalidTimestamp = errors.New("invalid timestamp") ErrRequestExpired = errors.New("request expired") ErrInvalidSignature = errors.New("invalid signature") )
var Module = fx.Module( "vef:api:auth", fx.Provide( fx.Private, fx.Annotate( NewAccessTokenAuthenticator, fx.ResultTags(`group:"vef:api:bearer_authenticators"`), ), fx.Annotate( NewNone, fx.ResultTags(`group:"vef:api:auth_strategies"`), ), fx.Annotate( NewBearer, fx.ParamTags(`group:"vef:api:bearer_authenticators"`), fx.ResultTags(`group:"vef:api:auth_strategies"`), ), fx.Annotate( NewSignature, fx.ParamTags(`optional:"true"`), fx.ResultTags(`group:"vef:api:auth_strategies"`), ), ), fx.Provide( fx.Annotate( NewRegistry, fx.ParamTags(`group:"vef:api:auth_strategies"`), ), ), )
Functions ¶
func NewBearer ¶
func NewBearer(authenticators []TokenAuthenticator, opts ...BearerOption) api.AuthStrategy
NewBearer creates a new Bearer token authentication strategy.
func NewRegistry ¶
func NewRegistry(strategies ...api.AuthStrategy) api.AuthStrategyRegistry
NewRegistry creates a new authentication strategy registry.
func NewSignature ¶
func NewSignature(loader ExternalAppLoader, opts ...SignatureOption) api.AuthStrategy
NewSignature creates a new signature authentication strategy.
Types ¶
type AccessTokenAuthenticator ¶
type AccessTokenAuthenticator struct {
// contains filtered or unexported fields
}
func (*AccessTokenAuthenticator) Authenticate ¶
type BearerOption ¶
type BearerOption func(*BearerStrategy)
BearerOption configures BearerStrategy.
func WithTokenExtractor ¶
func WithTokenExtractor(e extractors.Extractor) BearerOption
WithTokenExtractor sets a custom token extractor.
type BearerStrategy ¶
type BearerStrategy struct {
// contains filtered or unexported fields
}
BearerStrategy implements api.AuthStrategy for Bearer token authentication.
func (*BearerStrategy) Authenticate ¶
Authenticate validates the bearer token and returns the principal.
type ExternalApp ¶
ExternalApp represents an external application for signature authentication.
type ExternalAppLoader ¶
type ExternalAppLoader interface {
Load(ctx context.Context, appID string) (*ExternalApp, error)
}
ExternalAppLoader loads external app by ID.
type NoneStrategy ¶
type NoneStrategy struct{}
NoneStrategy implements api.AuthStrategy for public endpoints.
func (*NoneStrategy) Authenticate ¶
Authenticate returns anonymous principal.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry implements api.AuthStrategyRegistry using a concurrent map.
func (*Registry) Get ¶
func (r *Registry) Get(name string) (api.AuthStrategy, bool)
Get retrieves a strategy by name.
func (*Registry) Register ¶
func (r *Registry) Register(strategy api.AuthStrategy)
Register adds a strategy to the registry.
type SignatureOption ¶
type SignatureOption func(*SignatureStrategy)
SignatureOption configures SignatureStrategy.
func WithHeaders ¶
func WithHeaders(appID, timestamp, signature string) SignatureOption
WithHeaders sets custom header names.
func WithTimestampTolerance ¶
func WithTimestampTolerance(d time.Duration) SignatureOption
WithTimestampTolerance sets the timestamp tolerance.
type SignatureStrategy ¶
type SignatureStrategy struct {
// contains filtered or unexported fields
}
SignatureStrategy implements api.AuthStrategy for HMAC signature authentication.
func (*SignatureStrategy) Authenticate ¶
func (s *SignatureStrategy) Authenticate(ctx fiber.Ctx, _ map[string]any) (*security.Principal, error)
Authenticate validates the signature and returns the principal.
func (*SignatureStrategy) Name ¶
func (*SignatureStrategy) Name() string
Name returns the strategy name.
type TokenAuthenticator ¶
type TokenAuthenticator interface {
Authenticate(ctx context.Context, token string) (*security.Principal, error)
}
TokenAuthenticator validates a token and returns the principal.
func NewAccessTokenAuthenticator ¶
func NewAccessTokenAuthenticator(manager security.AuthManager) TokenAuthenticator