Back to godoc.org
github.com/reedom/echo-middleware-firebasejwt

Package firebasejwt

v0.0.0-...-88f3098
Latest Go to latest

The latest major version is .

Published: Mar 31, 2020 | License: MIT | Module: github.com/reedom/echo-middleware-firebasejwt

Index

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

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()`.

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

type JWTContextSpecifier func(*auth.Token) (string, interface{})

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

type JWTErrorHandler func(error) error

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

type JWTSuccessHandler

type JWTSuccessHandler func(echo.Context)

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

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier