Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultJWTConfig is the default JWT auth middleware config. DefaultFirebaseJWTConfig = JWTConfig{ Skipper: middleware.DefaultSkipper, ContextSpecifier: func(token *auth.Token) (string, interface{}) { return "user", token }, TokenLookup: "header:" + echo.HeaderAuthorization, AuthScheme: "Bearer", } )
var (
ErrJWTMissing = echo.NewHTTPError(http.StatusBadRequest, "missing or malformed jwt")
)
Errors
Functions ¶
func Default ¶
func Default(app *firebase.App) echo.MiddlewareFunc
JWT returns a JSON Web Token (JWT) auth middleware.
For valid token, it sets the user in context and calls next handler. For invalid token, it returns "401 - Unauthorized" error. For missing token, it returns "400 - Bad Request" error.
func With ¶
func With(config JWTConfig) echo.MiddlewareFunc
JWTWithConfig returns a JWT auth middleware with config. See: `JWT()`.
Types ¶
type JWTConfig ¶
type JWTConfig struct {
// Firebase app.
// Required.
App *firebase.App
// Skipper defines a function to skip middleware.
Skipper middleware.Skipper
// BeforeFunc defines a function which is executed just before the middleware.
BeforeFunc middleware.BeforeFunc
// SuccessHandler defines a function which is executed for a valid token.
SuccessHandler JWTSuccessHandler
// ErrorHandler defines a function which is executed for an invalid token.
// It may be used to define a custom JWT error.
ErrorHandler JWTErrorHandler
// JWTContextSpecifier defines a function which returns (context-key, token-value).
// The token-value will be stored into context with context-key.
// Optional. Default values are ("user", *auth.Token)
ContextSpecifier JWTContextSpecifier
// 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>"
// - "cookie:<name>"
TokenLookup string
// AuthScheme to be used in the Authorization header.
// Optional. Default value "Bearer".
AuthScheme string
}
JWTConfig defines the config for JWT middleware.
type JWTContextSpecifier ¶
JWTContextSpecifier defines a function which returns (context-key, token-value). The token-value will be stored into context with context-key. Optional. Default values are ("user", *auth.Token)
type JWTErrorHandler ¶
JWTErrorHandler defines a function which is executed for an invalid token.
type JWTSuccessHandler ¶
JWTSuccessHandler defines a function which is executed for a valid token.