Documentation
¶
Index ¶
- Variables
- func NewBearer(authenticators []TokenAuthenticator, opts ...BearerOption) api.AuthStrategy
- func NewNone() api.AuthStrategy
- func NewRegistry(strategies ...api.AuthStrategy) api.AuthStrategyRegistry
- func NewSignature(authManager security.AuthManager) api.AuthStrategy
- type AccessTokenAuthenticator
- type BearerOption
- type BearerStrategy
- type NoneStrategy
- type Registry
- type SignatureStrategy
- type TokenAuthenticator
Constants ¶
This section is empty.
Variables ¶
var ( ErrMissingToken = errors.New("missing token") ErrInvalidToken = errors.New("invalid token") )
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(authManager security.AuthManager) api.AuthStrategy
NewSignature creates a new signature authentication strategy. The authManager is used to delegate the actual authentication to SignatureAuthenticator.
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 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 SignatureStrategy ¶
type SignatureStrategy struct {
// contains filtered or unexported fields
}
SignatureStrategy implements api.AuthStrategy for HMAC signature authentication. It extracts credentials from HTTP headers and delegates authentication to the security.AuthManager, following the Spring Security pattern.
Required headers:
- X-App-ID: Application identifier (used as Principal)
- X-Timestamp: Unix timestamp in seconds
- X-Nonce: Random string for replay attack prevention
- X-Signature: HMAC signature in hex encoding
func (*SignatureStrategy) Authenticate ¶
func (s *SignatureStrategy) Authenticate(ctx fiber.Ctx, _ map[string]any) (*security.Principal, error)
Authenticate extracts credentials from request headers and delegates authentication to the AuthManager. Headers are extracted and formatted as: Principal=AppID, Credentials="timestamp:nonce:signature".
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