Documentation
¶
Index ¶
- func GetClaimsFromContext(ctx context.Context) (*token.TSClaims, error)
- func GetRawClaimsFromContext(ctx context.Context) (*token.TSClaims, error)deprecated
- func JWTMiddleware(key interface{}, opts *MiddlewareOptions) func(http.Handler) http.Handler
- func RequireScope(requiredScope string) func(http.Handler) http.Handler
- func RequireScopes(requiredScopes []string) func(http.Handler) http.Handler
- func RequireServiceToken(requiredService string) func(http.Handler) http.Handler
- type ContextKey
- type MiddlewareOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetClaimsFromContext ¶
GetClaimsFromContext retrieves the JWT claims from the request context
func GetRawClaimsFromContext
deprecated
func JWTMiddleware ¶
func JWTMiddleware(key interface{}, opts *MiddlewareOptions) func(http.Handler) http.Handler
JWTMiddleware creates a new JWT middleware using golang-jwt/jwt/v5
func RequireScope ¶
RequireScope creates a middleware that checks if the token has the required scope
func RequireScopes ¶
RequireScopes creates a middleware that checks if the token has all the required scopes
Types ¶
type ContextKey ¶
type ContextKey string
ContextKey is the key used to store the claims in the context
const ( // ClaimsContextKey is the key used to store the claims in the context ClaimsContextKey ContextKey = "jwt_claims" // RawClaimsContextKey is the key used to store raw claims in the context RawClaimsContextKey ContextKey = "jwt_raw_claims" )
type MiddlewareOptions ¶
type MiddlewareOptions struct {
// AllowEmptyToken allows requests without a token
AllowEmptyToken bool
// ValidateExpiration enables expiration validation
ValidateExpiration bool
// ValidateIssuer enables issuer validation
ValidateIssuer bool
// ValidateAudience enables audience validation
ValidateAudience bool
// RequiredClaims is a list of claims that are required to be present in the token
RequiredClaims []string
// JWKSURL is the URL to fetch the JSON Web Key Set from
JWKSURL string
// JWKSRefreshInterval is how often to refresh the JWKS cache
JWKSRefreshInterval time.Duration
// NonEnforcing allows the middleware to skip validation checks. It still logs errors.
NonEnforcing bool
// PolicyModelFile sets the path to an access model file used by Casbin
PolicyModelFile string
// PolicyPermissionsFile sets the path to an user permission file used by Casbin
PolicyPermissionsFile string
}
MiddlewareOptions contains options for the JWT middleware
func DefaultMiddlewareOptions ¶
func DefaultMiddlewareOptions() *MiddlewareOptions
DefaultMiddlewareOptions returns the default middleware options
Click to show internal directories.
Click to hide internal directories.