Documentation
¶
Overview ¶
Package authn provides a generic Kratos middleware for JWT-based authentication. It is engine-agnostic: any Authenticator implementation can be injected.
Example usage:
import (
"github.com/Servora-Kit/servora/security/authn"
"github.com/Servora-Kit/servora/security/authn/jwt"
)
mw = append(mw, authn.Server(
jwt.NewAuthenticator(jwt.WithVerifier(km.Verifier())),
))
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractBearerToken ¶
ExtractBearerToken parses the Bearer token from an Authorization header value. Returns empty string if the header is absent or malformed.
func Server ¶
func Server(authenticator Authenticator, opts ...Option) middleware.Middleware
Server returns a Kratos middleware that authenticates requests using the provided Authenticator. It extracts the Bearer token from the Authorization header, stores it in context via svrmw.NewTokenContext, then delegates to the Authenticator to produce an actor.Actor.
Behavior:
- No transport in context → anonymous actor injected, handler called
- No Authorization header → anonymous actor injected (authenticator may override)
- Authenticator error + no error handler → error returned
- Authenticator error + error handler → handler's return value used
Types ¶
type Authenticator ¶
Authenticator is the interface for authenticating incoming requests. Implementations receive the full request context (which may include the raw token stored by Server) and return an actor.Actor.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package jwt provides a JWT-based Authenticator implementation for pkg/authn.
|
Package jwt provides a JWT-based Authenticator implementation for pkg/authn. |
|
Package noop provides a no-op Authenticator that always returns an anonymous actor.
|
Package noop provides a no-op Authenticator that always returns an anonymous actor. |