package jwt

import "github.com/go-kit/kit/auth/jwt"

Index

Constants

const (
	// JWTTokenContextKey holds the key used to store a JWT Token in the
	// context.
	JWTTokenContextKey contextKey = "JWTToken"
	// JWTClaimsContxtKey holds the key used to store the JWT Claims in the
	// context.
	JWTClaimsContextKey contextKey = "JWTClaims"
)

Variables

var (
	// ErrTokenContextMissing denotes a token was not passed into the parsing
	// middleware's context.
	ErrTokenContextMissing = errors.New("token up for parsing was not passed through the context")
	// ErrTokenInvalid denotes a token was not able to be validated.
	ErrTokenInvalid = errors.New("JWT Token was invalid")
	// ErrTokenExpired denotes a token's expire header (exp) has since passed.
	ErrTokenExpired = errors.New("JWT Token is expired")
	// ErrTokenMalformed denotes a token was not formatted as a JWT token.
	ErrTokenMalformed = errors.New("JWT Token is malformed")
	// ErrTokenNotActive denotes a token's not before header (nbf) is in the
	// future.
	ErrTokenNotActive = errors.New("token is not valid yet")
	// ErrUncesptedSigningMethod denotes a token was signed with an unexpected
	// signing method.
	ErrUnexpectedSigningMethod = errors.New("unexpected signing method")
)

Functions

func FromGRPCContext

func FromGRPCContext() grpc.RequestFunc

FromGRPCContext moves JWT token from context to grpc metadata. Particularly useful for clients.

func FromHTTPContext

func FromHTTPContext() http.RequestFunc

FromHTTPContext moves JWT token from context to request header. Particularly useful for clients.

func NewParser

func NewParser(keyFunc jwt.Keyfunc, method jwt.SigningMethod) endpoint.Middleware

NewParser creates a new JWT token parsing middleware, specifying a jwt.Keyfunc interface and the signing method. NewParser adds the resulting claims to endpoint context or returns error on invalid token. Particularly useful for servers.

func NewSigner

func NewSigner(kid string, key []byte, method jwt.SigningMethod, claims Claims) endpoint.Middleware

NewSigner creates a new JWT token generating middleware, specifying key ID, signing string, signing method and the claims you would like it to contain. Tokens are signed with a Key ID header (kid) which is useful for determining the key to use for parsing. Particularly useful for clients.

func ToGRPCContext

func ToGRPCContext() grpc.RequestFunc

ToGRPCContext moves JWT token from grpc metadata to context. Particularly userful for servers.

func ToHTTPContext

func ToHTTPContext() http.RequestFunc

ToHTTPContext moves JWT token from request header to context. Particularly useful for servers.

Types

type Claims

type Claims map[string]interface{}

Source Files

middleware.go transport.go

Version
v0.3.0
Published
Nov 15, 2016
Platform
linux/amd64
Imports
10 packages
Last checked
5 minutes ago

Tools for package owners.