jose

package
v0.12.6 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHTTPMiddleware added in v0.12.0

func GetHTTPMiddleware(jh JOSEHandler, authRequired bool) func(*writer.StatusRecorder, *http.Request) (func(), *http.Request)

GetHTTPMiddleware returns an HTTP middleware function which extracts the Authorization header, if present, on all incoming HTTP requests. If an Authorization header is found, this middleware attempts to parse and validate that value as a JWT with the configured Credential types for the given JOSE provider.

Types

type Claim added in v0.12.0

type Claim interface {
	// NewContext accepts an input context and embeds the claim within the context, returning it
	// for further use
	NewContext(c context.Context) context.Context
}

Claim defines an interface for common JWT claim functionality, such as registering claims to contexts.

type ClaimGenerator added in v0.12.0

type ClaimGenerator interface {
	// New creates and returns a new Claim of the given underlying type
	New() Claim
}

ClaimGenerator defines an interface which creates a JWT Claim

type CognitoClaim

type CognitoClaim struct {
	TokenUse string `json:"token_use"`
	Scope    string `json:"scope"`
	ClientID string `json:"client_id"`
	Version  int    `json:"version"`
}

CognitoClaim defines a JWT Claim for tokens issued by the AWS Cognito Service

func (CognitoClaim) NewContext added in v0.12.0

func (cc CognitoClaim) NewContext(ctx context.Context) context.Context

NewContext registers a claim to a given context and returns that new context

type CognitoCtxKey added in v0.12.0

type CognitoCtxKey int

CognitoCtxKey is the type used to uniquely place the cognito claim in the context

const CognitoClaimKey CognitoCtxKey = iota

CognitoClaimKey is the value used to uniquely place the cognito claim within the context

type CognitoGenerator added in v0.12.0

type CognitoGenerator struct{}

CognitoGenerator satisfies the ClaimGenerator interface, allowing middleware to create intermediate Claim objects without specific knowledge of the underlying implementing types.

func (CognitoGenerator) New added in v0.12.0

func (cg CognitoGenerator) New() Claim

New satisfies the ClaimGenerator interface, returning an empty claim for use with JOSE parsing and validation.

type Config

type Config struct {
	JSONWebKeySetURL string // JSON Web Key Set (JWKS) URL for JSON Web Token (JWT) Verification
	ValidIssuer      string // URL of the JWT Issuer for this environment
	// List of one or more claims to be captured from JWTs. If using http middleware,
	// these generators will determine which claims appear on the context.
	ClaimGenerators []ClaimGenerator
	AuthRequired    bool // If true, missing/invalid `Authorization` headers will result in a 4xx error
}

Config contains configuration for the JOSE package

func (Config) NewJOSE

func (c Config) NewJOSE() (JOSE, error)

NewJOSE creates and returns a JOSE client for use.

func (*Config) RegisterFlags

func (c *Config) RegisterFlags(flags *pflag.FlagSet)

RegisterFlags registers JOSE flags with pflags

type JOSE

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

JOSE contains configuration for handling JWTs, JWKS, and other JOSE specifications

func (JOSE) GetClaims added in v0.12.0

func (j JOSE) GetClaims() []Claim

GetClaims returns a set of empty and initialized Claims registered to the JOSE struct

func (JOSE) ParseValidateJWT

func (j JOSE) ParseValidateJWT(input string, claims ...Claim) error

ParseValidateJWT accepts a string containing a JWT token and attempts to parse and validate the token. If you wish to inspect other components of the payload, you may supply one or more claims structs which will be populated if the JWT is valid. Claims must be structs with json fields that match the keys in the payload field, or a map[string]interface{}. Use of map[string]interface{} is strongly discouraged.

type JOSEHandler added in v0.12.0

type JOSEHandler interface {
	// GetClaims returns an array containing empty claims
	GetClaims() []Claim
	// ParseValidateJWT accepts an input JWT string and populates any provided claims with
	// available claim data from the token.
	ParseValidateJWT(input string, claims ...Claim) error
}

JOSEHandler defines an interface for interfacing with JOSE and JWT functionality

type MockClaim added in v0.12.0

type MockClaim struct{}

MockClaim defines a JWT Claim for tokens

func (MockClaim) NewContext added in v0.12.0

func (mc MockClaim) NewContext(ctx context.Context) context.Context

NewContext registers a claim to a given context

type MockCtxKey added in v0.12.0

type MockCtxKey int

MockCtxKey is the type used to uniquely place the mock claim in the context

const MockClaimKey MockCtxKey = iota

MockClaimKey is the value used to uniquely place the mock claim within the context

type MockGenerator added in v0.12.0

type MockGenerator struct{}

MockGenerator satisfies the ClaimGenerator interface

func (MockGenerator) New added in v0.12.0

func (mg MockGenerator) New() Claim

New satisfies the ClaimGenerator interface, returning an empty claim for use with JOSE parsing and validation.

type MockHandler added in v0.12.0

type MockHandler struct {
	mock.Mock
	// contains filtered or unexported fields
}

MockHandler defines an interface for mocking JOSE and JWT functionality

func (*MockHandler) GetClaims added in v0.12.0

func (mh *MockHandler) GetClaims() []Claim

GetClaims mocks retrieval of claim instances

func (*MockHandler) ParseValidateJWT added in v0.12.0

func (mh *MockHandler) ParseValidateJWT(input string, claims ...Claim) error

ParseValidateJWT mocks the ParseValidateJWT function

Jump to

Keyboard shortcuts

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