jwt

package
v2.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: Apache-2.0 Imports: 13 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoHeader    = errors.New("no authorization in header")
	ErrInvalidAuth = errors.New("invalid authentication")
)

errors

Functions

func SetExpire

func SetExpire(duration time.Duration)

SetExpire reset the expire time

func Use

func Use(middleware *Auth)

Use put a custom auth logic then register handler to chassis

Types

type Auth

type Auth struct {
	SecretFunc token.SecretFunc //required
	Expire     time.Duration
	Realm      string //required

	//optional. Authorize check whether this request could access some resource or API based on json claims.
	//Typically, this method should communicate with a RBAC, ABAC system
	Authorize func(payload map[string]interface{}, req *http.Request) error

	//optional.
	// this function control whether a request should be validate or not
	// if this func is nil, validate all requests.
	MustAuth func(req *http.Request) bool
}

Auth should implement auth logic it is singleton

type Handler

type Handler struct {
}

Handler is is a jwt interceptor

func (*Handler) Handle

Handle intercept unauthorized request

func (*Handler) Name

func (h *Handler) Name() string

Name returns the router string

Jump to

Keyboard shortcuts

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