auth0

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 9 Imported by: 6

README

THIS IS AN ARCHIVE SINCE THE ORIGINAL REPO WAS DELETED.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidContentType = errors.New("should have a JSON content type for JWKS endpoint")
	ErrInvalidAlgorithm   = errors.New("algorithm is invalid")
)
View Source
var (
	ErrNoKeyFound = errors.New("no Keys has been found")
	ErrKeyExpired = errors.New("key exists but is expired")

	// Configuring with MaxKeyAgeNoCheck will skip key expiry check
	MaxKeyAgeNoCheck = time.Duration(-1)
	// Configuring with MaxCacheSizeNoCheck will skip key cache size check
	MaxCacheSizeNoCheck = -1
)
View Source
var (
	// ErrNoJWTHeaders is returned when there are no headers in the JWT.
	ErrNoJWTHeaders = errors.New("No headers in the token")
)
View Source
var (
	// ErrTokenNotFound is returned by the ValidateRequest if the token was not
	// found in the request.
	ErrTokenNotFound = errors.New("Token not found")
)

Functions

func FromHeader

func FromHeader(r *http.Request) (*jwt.JSONWebToken, error)

FromHeader looks for the request in the authentication header or call ParseMultipartForm if not present. TODO: Implement parsing form data.

func FromParams

func FromParams(r *http.Request) (*jwt.JSONWebToken, error)

FromParams returns the JWT when passed as the URL query param "token".

Types

type Configuration

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

Configuration contains all the information about the Auth0 service.

func NewConfiguration

func NewConfiguration(provider SecretProvider, audience []string, issuer string, method jose.SignatureAlgorithm) Configuration

NewConfiguration creates a configuration for server

func NewConfigurationTrustProvider

func NewConfigurationTrustProvider(provider SecretProvider, audience []string, issuer string) Configuration

NewConfigurationTrustProvider creates a configuration for server with no enforcement for token sig alg type, instead trust provider

type JWKClient

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

func NewJWKClient

func NewJWKClient(options JWKClientOptions, extractor RequestTokenExtractor) *JWKClient

NewJWKClient creates a new JWKClient instance from the provided options.

func NewJWKClientWithCache

func NewJWKClientWithCache(options JWKClientOptions, extractor RequestTokenExtractor, keyCacher KeyCacher) *JWKClient

NewJWKClientWithCache creates a new JWKClient instance from the provided options and a custom keycacher interface. Passing nil to keyCacher will create a persistent key cacher

func (*JWKClient) GetKey

func (j *JWKClient) GetKey(ID string) (jose.JSONWebKey, error)

GetKey returns the key associated with the provided ID.

func (*JWKClient) GetSecret

func (j *JWKClient) GetSecret(r *http.Request) (interface{}, error)

GetSecret implements the GetSecret method of the SecretProvider interface.

type JWKClientOptions

type JWKClientOptions struct {
	URI    string
	Client *http.Client
}

type JWKS

type JWKS struct {
	Keys []jose.JSONWebKey `json:"keys"`
}

type JWTValidator

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

JWTValidator helps middleware to validate token

func NewValidator

func NewValidator(config Configuration, extractor RequestTokenExtractor) *JWTValidator

NewValidator creates a new validator with the provided configuration and the default leeway.

func NewValidatorWithLeeway added in v1.1.0

func NewValidatorWithLeeway(config Configuration, extractor RequestTokenExtractor, leeway time.Duration) *JWTValidator

NewValidatorWithLeeway creates a new validator with the provided configuration.

func (*JWTValidator) Claims

func (v *JWTValidator) Claims(r *http.Request, token *jwt.JSONWebToken, values ...interface{}) error

Claims unmarshall the claims of the provided token

func (*JWTValidator) ValidateRequest

func (v *JWTValidator) ValidateRequest(r *http.Request) (*jwt.JSONWebToken, error)

ValidateRequest validates the token within the http request.

type KeyCacher

type KeyCacher interface {
	Get(keyID string) (*jose.JSONWebKey, error)
	Add(keyID string, webKeys []jose.JSONWebKey) (*jose.JSONWebKey, error)
}

func NewMemoryKeyCacher

func NewMemoryKeyCacher(maxKeyAge time.Duration, maxCacheSize int) KeyCacher

NewMemoryKeyCacher creates a new Keycacher interface with option to set max age of cached keys and max size of the cache.

type RequestTokenExtractor

type RequestTokenExtractor interface {
	Extract(r *http.Request) (*jwt.JSONWebToken, error)
}

RequestTokenExtractor can extract a JWT from a request.

func FromMultiple

func FromMultiple(extractors ...RequestTokenExtractor) RequestTokenExtractor

FromMultiple combines multiple extractors by chaining.

type RequestTokenExtractorFunc

type RequestTokenExtractorFunc func(r *http.Request) (*jwt.JSONWebToken, error)

RequestTokenExtractorFunc function conforming to the RequestTokenExtractor interface.

func (RequestTokenExtractorFunc) Extract

Extract calls f(r)

type SecretProvider

type SecretProvider interface {
	GetSecret(r *http.Request) (interface{}, error)
}

SecretProvider will provide everything needed retrieve the secret.

func NewKeyProvider

func NewKeyProvider(key interface{}) SecretProvider

NewKeyProvider provide a simple passphrase key provider.

type SecretProviderFunc

type SecretProviderFunc func(*http.Request) (interface{}, error)

SecretProviderFunc simple wrappers to provide secret with functions.

func (SecretProviderFunc) GetSecret

func (f SecretProviderFunc) GetSecret(r *http.Request) (interface{}, error)

GetSecret implements the SecretProvider interface.

Jump to

Keyboard shortcuts

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