Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetHTTPMiddleware ¶ added in v0.12.0
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) RegisterFlags ¶
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
GetClaims returns a set of empty and initialized Claims registered to the JOSE struct
func (JOSE) ParseValidateJWT ¶
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 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
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