token

package
v0.2.1-0...-9c16218 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2020 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package token defines middleware that parses and validates a bearer token and passes it via the request context.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

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

NewContext returns a new Context that carries value t.

Types

type Claims

type Claims struct {
	jwt.StandardClaims
	UserID string `json:"uid,omitempty"`
}

Claims type.

func (Claims) VerifyAudience

func (c Claims) VerifyAudience(s string) bool

VerifyAudience compares the "aud" claim (if present) against cmp.

func (Claims) VerifyIssuer

func (c Claims) VerifyIssuer(s string) bool

VerifyIssuer compares the "iss" claim (if present) against cmp.

type Middleware

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

Middleware is a token middleware. Use the Handler method to obtain a http.Handler.

func NewMiddleware

func NewMiddleware(o MiddlewareOptions) *Middleware

NewMiddleware returns a new token middleware.

func (*Middleware) Handler

func (m *Middleware) Handler(h http.Handler) http.Handler

Handler returns a new token handler.

type MiddlewareOptions

type MiddlewareOptions struct {
	// The value to verify in the "aud" claim (if claim present).
	Audience string
	// The value to verify in the "iss" claim (if claim present).
	Issuer string
	// This callback function is used to supply the key for verification. The function receives the
	// parsed, but unverified Token. This allows you to use properties in the Header of the token
	// (such as `kid`) to identify which key to use. The algorithm specified in the token should be
	// verified to match the key.
	KeyFunc jwt.Keyfunc
}

MiddlewareOptions control the behaviour of the token middleware.

type Token

type Token struct {
	*jwt.Token
}

Token represents a JWT Token.

func FromContext

func FromContext(ctx context.Context) (*Token, bool)

FromContext returns the Token stored in ctx, if any.

func (*Token) Claims

func (t *Token) Claims() *Claims

Claims returns the claims contained in the token.

Jump to

Keyboard shortcuts

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