decoder

package
v0.0.0-...-a67e843 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

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

Server is a http handler that will use a decoder to decode the authHeaderKey JWT-Token and put the resulting claims in headers

func NewServer

func NewServer(decoder TokenDecoder, authHeaderKey, tokenValidatedHeaderKey string) *Server

NewServer returns a new server that will decode the header with key authHeaderKey with the given TokenDecoder decoder.

func (*Server) DecodeToken

func (s *Server) DecodeToken(rw http.ResponseWriter, r *http.Request)

DecodeToken http handler

type Token

type Token struct {
	Claims     map[string]string
	Expiration time.Time
}

Token contains the expiration time and a remapped map of claims from the JWT Token

func (*Token) Validate

func (t *Token) Validate() error

Validate the token (currently only checks the expirationTime but could potentially do more checks)

type TokenDecoder

type TokenDecoder interface {
	Decode(ctx context.Context, raw string) (*Token, error)
}

TokenDecoder can decode and validate raw JTW tokens

func NewCachedJwtDecoder

func NewCachedJwtDecoder(cache *ristretto.Cache, delegate TokenDecoder) TokenDecoder

NewCachedJwtDecoder returns a new JwtDecoder that will cache Tokens decoded by the delegate

func NewJwsDecoder

func NewJwsDecoder(jwksURL string, claimMapping map[string]string) (TokenDecoder, error)

NewJwsDecoder returns a root Decoder that can decode and validate JWS Tokens It will also map the claims via the claim mapping `claimMapping = map[string][string]{ "key123", "headerKey123" }` will cause the claim `key123` in the JWS token to be mapped to `headerKey123` in the decoded token

type TokenExpiredError

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

TokenExpiredError means the token is invalid because it has expired

func (TokenExpiredError) Error

func (e TokenExpiredError) Error() string

type UnexpectedClaimTypeError

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

UnexpectedClaimTypeError is thrown if a mapped claim in the token has an unexpected type the token should always have type string

func (UnexpectedClaimTypeError) Error

func (e UnexpectedClaimTypeError) Error() string

Jump to

Keyboard shortcuts

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