Documentation
¶
Index ¶
- Constants
- func CallerIdentityFromRequest(ctx context.Context, r *http.Request, cfg CallerIdentityConfig) (string, error)
- func GetIdentityFromContext(ctx context.Context, identityClaim string) (string, error)
- func GetJWTTokenFromContext(ctx context.Context) *jwt.Token
- func GetUsernameFromContext(ctx context.Context) string
- func SetJWTTokenContext(ctx context.Context, token *jwt.Token) context.Context
- func SetUsernameContext(ctx context.Context, username string) context.Context
- type CallerIdentityConfig
- type CallerIdentityMiddleware
- type JWTHandler
- type JWTHandlerConfig
- type Payload
Constants ¶
const ( ContextUsernameKey contextKey = "username" ContextJWTTokenKey contextKey = "jwt_token" // DefaultJWTIdentityClaim is used when server.jwt.identity_claim is unset. DefaultJWTIdentityClaim = "email" )
Variables ¶
This section is empty.
Functions ¶
func CallerIdentityFromRequest ¶ added in v0.3.0
func CallerIdentityFromRequest(ctx context.Context, r *http.Request, cfg CallerIdentityConfig) (string, error)
CallerIdentityFromRequest resolves the caller identity with header-primary precedence. When the identity header is configured and present, it overrides the JWT claim. Both header and JWT identity values are normalized: trimmed, length-checked, and validated for control characters before being accepted.
func GetIdentityFromContext ¶ added in v0.3.0
GetIdentityFromContext returns the configured JWT claim value used as the request identity.
func GetJWTTokenFromContext ¶ added in v0.3.0
func GetUsernameFromContext ¶
func SetJWTTokenContext ¶ added in v0.3.0
Types ¶
type CallerIdentityConfig ¶ added in v0.3.0
CallerIdentityConfig controls how the caller identity is resolved for audit fields. Identity resolution is enabled by setting the relevant fields:
- HeaderName: when non-empty, the named HTTP header is checked first
- JWTIdentityClaim: when non-empty, the JWT claim is used as fallback (or primary when no header is configured)
type CallerIdentityMiddleware ¶ added in v0.3.0
CallerIdentityMiddleware resolves and attaches the caller identity used for audit fields.
func NewCallerIdentityMiddleware ¶ added in v0.3.0
func NewCallerIdentityMiddleware(cfg CallerIdentityConfig) (CallerIdentityMiddleware, error)
type JWTHandler ¶ added in v0.3.0
type JWTHandler struct {
// contains filtered or unexported fields
}
JWTHandler validates JWT tokens on incoming requests. Call Close() during shutdown to stop the background JWKS refresh goroutine.
func NewJWTHandler ¶ added in v0.3.0
func NewJWTHandler(ctx context.Context, cfg JWTHandlerConfig) (*JWTHandler, error)
func (*JWTHandler) Close ¶ added in v0.3.0
func (h *JWTHandler) Close()
func (*JWTHandler) ServeHTTP ¶ added in v0.3.0
func (h *JWTHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)