jwt

package
v0.0.0-...-e0cb8a0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnrecognizedPublicKey = errors.New("unrecognized public key")

Functions

This section is empty.

Types

type Auth0Tokener

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

Auth0Tokener implements anonymizer by requesting new tokens through an Auth0 machine-to-machine client

func NewTokener

func NewTokener(url, clientID, clientSecret, audience string, doer Doer) Auth0Tokener

NewTokener builds an Auth0Tokener from the specified auth0 API url, client id, and secret.

func (Auth0Tokener) GetToken

func (a Auth0Tokener) GetToken(ctx context.Context) (string, error)

GetToken returns an token from the auth0 client

type Authorization

type Authorization struct {
	jwt.StandardClaims
	Session string `json:"https://jwt.smartatransit.com/session"`
	Role    string `json:"https://jwt.smartatransit.com/role"`
}

Authorization is used to interact with the `jwt` package

func (Authorization) SetAuthHeaders

func (a Authorization) SetAuthHeaders(w http.ResponseWriter)

SetAuthHeaders converts the authorization claims into X-Smarta-Auth headers.

func (Authorization) Valid

func (a Authorization) Valid() error

Valid implements jwt.Authorization

type CachedToken

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

CachedToken represents a cached token

type Doer

type Doer interface {
	Do(*http.Request) (*http.Response, error)
}

type Key

type Key struct {
	ID string `json:"kid"`

	Algorithm string `json:"alg"`
	KeyType   string `json:"kty"`

	RSAModulus         string `json:"n"`
	RSAExponent        string `json:"e"`
	RSAPrivateExponent string `json:"d"`
}

type KeyServer

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

func NewKeyServer

func NewKeyServer(uri string, doer Doer) *KeyServer

func (*KeyServer) Fetch

func (ks *KeyServer) Fetch(kid string) (jose.JSONWebKey, error)

type Keys

type Keys interface {
	Fetch(kid string) (jose.JSONWebKey, error)
}

type ParseFunc

type ParseFunc func(tokenString string, claims jwt.Claims, keyFunc jwt.Keyfunc) (*jwt.Token, error)

type Parser

type Parser interface {
	ParseToken(ctx context.Context, tokenStr string) (Authorization, error)
}

Parser parses a JWT into an Authorization struct

type ParserAgent

type ParserAgent struct {
	ParseWithClaims ParseFunc
	// contains filtered or unexported fields
}

ParserAgent implements Parser

func NewParser

func NewParser(keys Keys) ParserAgent

NewParser creates a new JWT parser

func (ParserAgent) ParseToken

func (a ParserAgent) ParseToken(ctx context.Context, tokenStr string) (Authorization, error)

ParseToken fails if the token is invalid, has an invalid signature, or fails standard claims validations. Otherwise, returns the claims covered by the Authorization struct. It uses the underlying Keys implementation to look up the `kid` in the key for verification.

type TokenAgent

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

TokenAgent implements TokenCache

func NewTokenCache

func NewTokenCache() *TokenAgent

NewTokenCache creates a new TokenCache

func (*TokenAgent) AddToken

func (a *TokenAgent) AddToken(ctx context.Context, key string, token string, expy time.Time)

AddToken adds a token to cache

func (*TokenAgent) Clean

func (a *TokenAgent) Clean(ctx context.Context)

Clean clears out any expired tokens

func (*TokenAgent) FetchToken

func (a *TokenAgent) FetchToken(ctx context.Context, key string) (string, bool)

FetchToken gets a token for the key if there is an unexpired one

type TokenCache

type TokenCache interface {
	FetchToken(ctx context.Context, key string) (string, bool)
	Clean(ctx context.Context)
	AddToken(ctx context.Context, key string, token string, expy time.Time)
}

TokenCache parses a JWT into an Authorization struct

type Tokener

type Tokener interface {
	GetToken(ctx context.Context) (string, error)
}

Tokener is an interface for obtaining tokens

type TokenerFactory

type TokenerFactory func(clientID, clientSecret string) Tokener

TokenerFactory builds a tokener for a specific Auth0 client identity

func NewTokenerFactory

func NewTokenerFactory(url, audience string, doer Doer) TokenerFactory

NewTokenerFactory returns a new tokener factory

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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