jwt

package
v0.0.0-...-e08ecba Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Name token name, default: Authorization
	Name string
	// Signing key to validate token
	SigningKey string
	// ErrorHandler validate error handler, default: defaultOnError
	ErrorHandler errorHandler
	// Extractor extract jwt token, default extract from header: defaultExtractorFromHeader
	Extractor tokenExtractor
	// EnableAuthOnOptions http option method validate switch
	EnableAuthOnOptions bool
	// SigningMethod sign method, default: HS256
	SigningMethod gojwt.SigningMethod
	// ExcludeURL exclude url will skip jwt validator
	ExcludeURL []string
	// ExcludePrefix exclude url prefix will skip jwt validator
	ExcludePrefix []string
	// ContextKey Context key to store user information from the token into context.
	// Optional. Default value "".
	ContextKey string

	// HeaderKey Header key to store user information from the token into Header.
	// Optional. Default value "".
	HeaderKey string

	// CustomValidator custom validator suggestion flow:
	// 1. check exlude url, and exclude url prefix
	// 2. extract token string
	// 3. check token sign
	// 4. check token ttl
	// 5. save custom value to conext after check passed
	// 6. handle addon validator
	CustomValidator customValidator
	// contains filtered or unexported fields
}

Config JWT Middleware config

type Provider

type Provider struct {
	Config *Config
}

Provider JWT validator handler

func New

func New(config *Config) *Provider

New create a JWT provider

func (*Provider) Auth

func (t *Provider) Auth(req *restful.Request, resp *restful.Response,
	chain *restful.FilterChain)

func (*Provider) GeneratorToken

func (t *Provider) GeneratorToken(customValue string, ttl time.Duration) (string, error)

GeneratorToken generate token by custom value and token ttl

func (*Provider) GetCustomValue

func (t *Provider) GetCustomValue(req *restful.Request) (string, error)

GetCustomValue return custom value in token, or returns error

Jump to

Keyboard shortcuts

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