middleware

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// RequireLogin check JWT token.
	RequireLogin echo.MiddlewareFunc

	// RequireToken checks email confirmation token.
	RequireToken echo.MiddlewareFunc
)

Functions

func Init

func Init(e *echo.Echo)

Init middlewares

func JWTWithConfig

func JWTWithConfig(config JWTConfig) echo.MiddlewareFunc

JWTWithConfig returns a JWT auth middleware with config. See: `JWT()`.

func RequireJSON

func RequireJSON(next echo.HandlerFunc) echo.HandlerFunc

RequireJSON requires an application/json content type.

Types

type CustomClaims

type CustomClaims struct {
	Username string `json:"username"`
	Purpose  string `json:"purpose"`
	jwt.StandardClaims
}

CustomClaims are custom claims extending default ones. Used for email confirmation and pwd reset.

type JWTConfig

type JWTConfig struct {
	// Skipper defines a function to skip middleware.
	Skipper m.Skipper

	// BeforeFunc defines a function which is executed just before the middleware.
	BeforeFunc m.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

	// ErrorHandlerWithContext is almost identical to ErrorHandler, but it's passed the current context.
	ErrorHandlerWithContext JWTErrorHandlerWithContext

	// Signing key to validate token. Used as fallback if SigningKeys has length 0.
	// Required. This or SigningKeys.
	SigningKey interface{}

	// Map of signing keys to validate token with kid field usage.
	// Required. This or SigningKey.
	SigningKeys map[string]interface{}

	// Signing method, used to check token signing method.
	// Optional. Default value HS256.
	SigningMethod string

	// Context key to store user information from the token into context.
	// Optional. Default value "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>"
	// - "form:<name>"
	TokenLookup string

	// AuthScheme to be used in the Authorization header.
	// Optional. Default value "Bearer".
	AuthScheme string
	// contains filtered or unexported fields
}

JWTConfig defines the config for JWT middleware.

type JWTErrorHandler

type JWTErrorHandler func(error) error

JWTErrorHandler defines a function which is executed for an invalid token.

type JWTErrorHandlerWithContext

type JWTErrorHandlerWithContext func(error, echo.Context) error

JWTErrorHandlerWithContext is almost identical to JWTErrorHandler, but it's passed the current context.

type JWTSuccessHandler

type JWTSuccessHandler func(echo.Context)

JWTSuccessHandler defines a function which is executed for a valid token.

type LoginCustomClaims

type LoginCustomClaims struct {
	Name  string `json:"name"`
	Admin bool   `json:"admin"`
	jwt.StandardClaims
}

LoginCustomClaims are custom claims extending default ones

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL