Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Authenticate ¶
Authenticate executes all the authentication handlers in the order they were added. If any of the handlers does not return an error, the request proceeds to the next handler. If the last handler returns an error, the request is aborted.
func BootstrapMiddleware ¶
BootstrapMiddleware sets up the authentication handlers. The context object is used to controll the life-cycle of the JWKS cache auto-refresh worker.
func SetHandlers ¶
func SetHandlers(handlers []AuthHandler)
SetHandlers sets the authentication handlers
Types ¶
type APIKeyConfig ¶ added in v1.3.0
type APIKeyConfig struct {
// Header is the header to be used on the VerifyAPIKey handler. Defaults to X-API-Key
Header string `mapstructure:"GOAUTH_API_KEY_HEADER"`
// KeyList is the list of API keys to be used on the VerifyAPIKey handler, separated by comma
KeyList []string `mapstructure:"GOAUTH_API_KEY_LIST"`
}
APIKeyConfig is the config to be used on the VerifyAPIKey handler
type AuthHandler ¶
type AuthHandler interface {
Handle(h *http.Request) (request *http.Request, statusCode int, err error)
}
AuthHandler is the interface that wraps the AuthenticateFunc method and is used to authenticate the request
type AuthMiddlewareError ¶
type AuthMiddlewareError struct {
// Code is the HTTP status code
Code int
// Message is the error message
Message string
}
AuthMiddlewareError is the error type returned by the middleware
func (*AuthMiddlewareError) Error ¶
func (e *AuthMiddlewareError) Error() string
Error implements the error interface
type Config ¶
type Config struct {
// AuthHandlers is the list of authentication handlers to be used
Handlers []string `mapstructure:"GOAUTH_HANDLERS"`
// APIKeyConfig stores the configuration for the VerifyAPIKey handler
APIKeyConfig APIKeyConfig `mapstructure:",squash"`
// JWKSConfig stores the configuration for the VerifyJWKS handler
JWKSConfig JWKSConfig `mapstructure:",squash"`
// JWTConfig stores the configuration for the VerifyJWT handler
JWTConfig JWTConfig `mapstructure:",squash"`
}
Config stores the configuration for the Goauth middleware
type JWKSConfig ¶ added in v1.3.0
type JWKSConfig struct {
// Header is the header to be used on the VerifyJWKS handler. Defaults to Authorization
Header string `mapstructure:"GOAUTH_JWKS_HEADER"`
// TokenType is the token type to be used on the VerifyJWKS handler. Defaults to Bearer
TokenType string `mapstructure:"GOAUTH_JWKS_TOKEN_TYPE"`
// URL is the JWKS endpoint to be used on the VerifyJWKS handler
URL string `mapstructure:"GOAUTH_JWKS_URL"`
// RefreshWindow is the time window before checking if the JWKS cache needs to be refreshed, in seconds. Defaults to 60
RefreshWindow int `mapstructure:"GOAUTH_JWKS_REFRESH_WINDOW"`
// MinRefreshInterval is the minimum interval between JWKS refreshes, in seconds. Defaults to 300
MinRefreshInterval int `mapstructure:"GOAUTH_JWKS_MIN_REFRESH_INTERVAL"`
// PayloadContextKey is the context key to store the JWT payload. Defaults to USER
PayloadContextKey string `mapstructure:"GOAUTH_JWKS_PAYLOAD_CONTEXT_KEY"`
}
JWKSConfig is the config to be used on the VerifyJWKS handler
type JWTConfig ¶ added in v1.3.0
type JWTConfig struct {
// Header is the header to be used on the VerifyJWT handler. Defaults to Authorization
Header string `mapstructure:"GOAUTH_JWT_HEADER"`
// TokenType is the token type to be used on the VerifyJWT handler. Defaults to Bearer
TokenType string `mapstructure:"GOAUTH_JWT_TOKEN_TYPE"`
// SignatureKey is the signature key to be used on the VerifyJWT handler
SignatureKey string `mapstructure:"GOAUTH_JWT_SIGNATURE_KEY"`
// SignatureAlgorithm is the algorithm used to sign the JWT. Defaults to RS256
SignatureAlgorithm string `mapstructure:"GOAUTH_JWT_SIGNATURE_ALGORITHM"`
// PayloadContextKey is the context key to store the JWT payload. Defaults to USER
PayloadContextKey string `mapstructure:"GOAUTH_JWT_PAYLOAD_CONTEXT_KEY"`
}
JWTConfig is the config to be used on the VerifyJWT handler