middleware

package
v0.0.0-...-c4bde49 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TokenCtxKey = &contextKey{"Token"}
	ErrorCtxKey = &contextKey{"Error"}
)
View Source
var (
	ErrUnauthorized = errors.New("jwtauth: token is unauthorized")
	ErrExpired      = errors.New("jwtauth: token is expired")
	ErrNBFInvalid   = errors.New("jwtauth: token nbf validation failed")
	ErrIATInvalid   = errors.New("jwtauth: token iat validation failed")
	ErrNoTokenFound = errors.New("jwtauth: no token found")
	ErrAlgoInvalid  = errors.New("jwtauth: algorithm mismatch")
)

Functions

func Authenticator

func Authenticator(next http.Handler) http.Handler

func EpochNow

func EpochNow() int64

EpochNow is a helper function that returns the NumericDate time value used by the spec

func ExpireIn

func ExpireIn(tm time.Duration) int64

ExpireIn is a helper function to return calculated time in the future for "exp" claim

func FromContext

func FromContext(ctx context.Context) (*jwt.Token, jwt.MapClaims, error)

func NewContext

func NewContext(ctx context.Context, t *jwt.Token, err error) context.Context

func SetExpiryIn

func SetExpiryIn(claims jwt.MapClaims, tm time.Duration)

Set expiry ("exp") in the claims to some duration from the present time

func SetIssuedNow

func SetIssuedNow(claims jwt.MapClaims)

Set issued at ("iat") to present time in the claims

func TokenFromHeader

func TokenFromHeader(r *http.Request) string

TokenFromHeader tries to retreive the token string from the "Authorization" reqeust header: "Authorization: Token T".

func Verifier

func Verifier(ja *JWTAuth) func(http.Handler) http.Handler

func Verify

func Verify(ja *JWTAuth, findTokenFns ...func(r *http.Request) string) func(http.Handler) http.Handler

func VerifyRequest

func VerifyRequest(ja *JWTAuth, r *http.Request, findTokenFns ...func(r *http.Request) string) (*jwt.Token, error)

Types

type JWTAuth

type JWTAuth struct {
	// contains filtered or unexported fields
}

func New

func New(alg string, signKey interface{}, verifyKey interface{}) *JWTAuth

New creates a JWTAuth authenticator instance that provides middleware handlers and encoding/decoding functions for JWT signing.

func NewWithParser

func NewWithParser(alg string, parser *jwt.Parser, signKey interface{}, verifyKey interface{}) *JWTAuth

NewWithParser is the same as New, except it supports custom parser settings introduced in jwt-go/v2.4.0.

func (*JWTAuth) Decode

func (ja *JWTAuth) Decode(tokenString string) (t *jwt.Token, err error)

func (*JWTAuth) Encode

func (ja *JWTAuth) Encode(claims jwt.Claims) (t *jwt.Token, tokenString string, err error)

Jump to

Keyboard shortcuts

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