Documentation
¶
Overview ¶
Package jwt provides HTTP middleware for authenticating requests with a bearer JWT and authorizing them against a claim predicate.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewContextWithScopes ¶
NewContextWithScopes returns a new context carrying scopes, retrievable via ScopesFromContext.
func ScopeMatch ¶
ScopeMatch reports whether subject grants target, treating "*" in any field of subject as a wildcard for that field.
func ScopesMatch ¶
ScopesMatch reports whether any of subjects grants target (see ScopeMatch).
Types ¶
type ClaimsAuthoriser ¶
type ClaimsAuthoriser struct {
Predicate jwt.ClaimPredicate
}
ClaimsAuthoriser checks if the request satisfies a claim predicate.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler handles JWT authentication and sets the authenticated principal in the context.
func NewHandler ¶
func NewHandler(validator jwt.TokenValidator, cookieName string, opts ...jwtmiddleware.Option) *Handler
NewHandler creates a JWT authentication handler. All log output uses the request-scoped zerolog context logger so entries automatically carry request_id, principal, and other fields injected by upstream middleware.
func (*Handler) WithRequireToken ¶ added in v0.8.0
WithRequireToken configures whether Wrap rejects a request with 401 when no bearer token or cookie is presented at all, instead of passing it through unauthenticated. Defaults to false, preserving this handler's pass-through behavior for chained/optional use (e.g. as one of several providers). Callers that use this handler as a server's sole auth gate should opt in.
type ResourceAuthoriser ¶
ResourceAuthoriser handles resource-level permissions (scopes).
func (*ResourceAuthoriser) RequireScope ¶
RequireScope returns middleware that rejects requests whose context scopes (see ScopesFromContext) don't grant resource/action on a's Service.
type Scope ¶
Scope identifies a service/resource/action permission grant or requirement.
func ScopesFromContext ¶
ScopesFromContext returns the scopes previously attached to ctx via NewContextWithScopes, and whether any were found.