Documentation ¶
Index ¶
Constants ¶
View Source
const ( // HS256 represents a public cryptography key generated by a 256 bit HMAC algorithm. HS256 = "HS256" // HS384 represents a public cryptography key generated by a 384 bit HMAC algorithm. HS384 = "HS384" // HS512 represents a public cryptography key generated by a 512 bit HMAC algorithm. HS512 = "HS512" // ES256 represents a public cryptography key generated by a 256 bit ECDSA algorithm. ES256 = "ES256" // ES384 represents a public cryptography key generated by a 384 bit ECDSA algorithm. ES384 = "ES384" // ES512 represents a public cryptography key generated by a 512 bit ECDSA algorithm. ES512 = "ES512" // P256 represents a cryptographic elliptical curve type. P256 = "P-256" // P384 represents a cryptographic elliptical curve type. P384 = "P-384" // P521 represents a cryptographic elliptical curve type. P521 = "P-521" // RS256 represents a public cryptography key generated by a 256 bit RSA algorithm. RS256 = "RS256" // RS384 represents a public cryptography key generated by a 384 bit RSA algorithm. RS384 = "RS384" // RS512 represents a public cryptography key generated by a 512 bit RSA algorithm. RS512 = "RS512" // PS256 represents a public cryptography key generated by a 256 bit RSA algorithm. PS256 = "PS256" // PS384 represents a public cryptography key generated by a 384 bit RSA algorithm. PS384 = "PS384" // PS512 represents a public cryptography key generated by a 512 bit RSA algorithm. PS512 = "PS512" )
Variables ¶
View Source
var ( // ErrJWTAlg is returned when the JWT header did not contain the expected algorithm. ErrJWTAlg = errors.New("the JWT header did not contain the expected algorithm") )
View Source
var ( // ErrJWTMissingOrMalformed is returned when the JWT is missing or malformed. ErrJWTMissingOrMalformed = errors.New("missing or malformed JWT") )
Functions ¶
Types ¶
type Config ¶
type Config struct { // Filter defines a function to skip middleware. // Optional. Default: nil Filter func(*fiber.Ctx) bool // SuccessHandler defines a function which is executed for a valid token. // Optional. Default: nil SuccessHandler fiber.Handler // ErrorHandler defines a function which is executed for an invalid token. // It may be used to define a custom JWT error. // Optional. Default: 401 Invalid or expired JWT ErrorHandler fiber.ErrorHandler // Signing key to validate token. Used as fallback if SigningKeys has length 0. // At least one of the following is required: KeyFunc, JWKSetURLs, SigningKeys, or SigningKey. // The order of precedence is: KeyFunc, JWKSetURLs, SigningKeys, SigningKey. SigningKey SigningKey // Map of signing keys to validate token with kid field usage. // At least one of the following is required: KeyFunc, JWKSetURLs, SigningKeys, or SigningKey. // The order of precedence is: KeyFunc, JWKSetURLs, SigningKeys, SigningKey. SigningKeys map[string]SigningKey // Context key to store user information from the token into context. // Optional. Default: "user". ContextKey string // Claims are extendable claims data defining token content. // Optional. Default value jwt.MapClaims Claims jwt.Claims // TokenLookup is a string in the form of "<source>:<name>" that is used // to extract token from the request. // Optional. Default value "header:Authorization". // Possible values: // - "header:<name>" // - "query:<name>" // - "param:<name>" // - "cookie:<name>" TokenLookup string // AuthScheme to be used in the Authorization header. // Optional. Default: "Bearer". AuthScheme string // KeyFunc is a function that supplies the public key for JWT cryptographic verification. // The function shall take care of verifying the signing algorithm and selecting the proper key. // Internally, github.com/MicahParks/keyfunc/v2 package is used project defaults. If you need more customization, // you can provide a jwt.Keyfunc using that package or make your own implementation. // // At least one of the following is required: KeyFunc, JWKSetURLs, SigningKeys, or SigningKey. // The order of precedence is: KeyFunc, JWKSetURLs, SigningKeys, SigningKey. KeyFunc jwt.Keyfunc // JWKSetURLs is a slice of HTTP URLs that contain the JSON Web Key Set (JWKS) used to verify the signatures of // JWTs. Use of HTTPS is recommended. The presence of the "kid" field in the JWT header and JWKs is mandatory for // this feature. // // By default, all JWK Sets in this slice will: // * Refresh every hour. // * Refresh automatically if a new "kid" is seen in a JWT being verified. // * Rate limit refreshes to once every 5 minutes. // * Timeout refreshes after 10 seconds. // // At least one of the following is required: KeyFunc, JWKSetURLs, SigningKeys, or SigningKey. // The order of precedence is: KeyFunc, JWKSetURLs, SigningKeys, SigningKey. JWKSetURLs []string }
Config defines the config for JWT middleware
type SigningKey ¶
type SigningKey struct { // JWTAlg is the algorithm used to sign JWTs. If this value is a non-empty string, this will be checked against the // "alg" value in the JWT header. // // https://www.rfc-editor.org/rfc/rfc7518#section-3.1 JWTAlg string // Key is the cryptographic key used to sign JWTs. For supported types, please see // https://github.com/golang-jwt/jwt. Key interface{} }
SigningKey holds information about the recognized cryptographic keys used to sign JWTs by this program.
Click to show internal directories.
Click to hide internal directories.