Documentation
¶
Overview ¶
Purpose: This file implements the GoStack JWT authentication extension. It provides claims structures, a manager to sign and verify tokens statelessly, a compliant contract.Guard wrapper, and standard HTTP middleware for request-scoped context authentication.
Philosophy: Stateless authentication should integrate seamlessly with GoStack's container (Citadel) and request lifecycle context cache. By writing a JWT manager and guard that satisfies the framework's contracts, developers get zero-overhead authentication without breaking downstream roles, permissions, or session checks.
Choice: We use `github.com/golang-jwt/jwt/v5` as a standard, secure base dependency to sign tokens, while presenting a highly simplified, GoStack-native interface containingHS256 defaults.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Middleware ¶
func Middleware(manager *Manager, provider contract.UserProvider) httpFrame.Middleware
Middleware returns a GoStack-compliant http.Middleware interceptor.
Types ¶
type Claims ¶
type Claims struct {
UserID string `json:"user_id"`
Role string `json:"role"`
jwt.RegisteredClaims
}
Claims represents the JWT payload metadata.
type JWTGuard ¶
type JWTGuard struct {
// contains filtered or unexported fields
}
JWTGuard implements contract.Guard statelessly using the JWT manager.
func NewJWTGuard ¶
func NewJWTGuard(manager *Manager, provider contract.UserProvider) *JWTGuard
NewJWTGuard creates a new JWTGuard adapter instance.
func (*JWTGuard) Check ¶
Check validates if the request context contains a valid JWT user signature.
func (*JWTGuard) Login ¶
func (g *JWTGuard) Login(w http.ResponseWriter, r *http.Request, user contract.Authenticatable) error
Login is a stateless no-op for JWTGuard.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager coordinates token generation and verification using configurable keys and algorithms.
func NewManager ¶
NewManager initializes a JWT manager with configuration settings.
type ServiceProvider ¶
type ServiceProvider struct{}
ServiceProvider integrates JWT into the GoStack dependency container framework.
func NewServiceProvider ¶
func NewServiceProvider() *ServiceProvider
func (*ServiceProvider) Boot ¶
func (sp *ServiceProvider) Boot(c *foundation.Container)
Boot is a no-op lifecycle implementation for contract compliance.
func (*ServiceProvider) Register ¶
func (sp *ServiceProvider) Register(c *foundation.Container)
Register binds the JWT Manager singleton into the container.