Documentation
¶
Index ¶
- Variables
- func RecoveryHandler(c *gin.Context, err any)
- type ErrorHandler
- type JWTValidator
- func (v *JWTValidator) AddParserOption(options ...jwt.ParseOption)
- func (v *JWTValidator) Configure(issuer string, jwksUri string, allowFaultyJWKSUri bool) error
- func (v *JWTValidator) DiscoverAndConfigure(issuer string) error
- func (v *JWTValidator) GinHandler(c *gin.Context)
- func (v *JWTValidator) Handler(next http.Handler) http.Handler
- type RequireScope
- type RevokedTokenProvider
Constants ¶
This section is empty.
Variables ¶
var ( ErrDiscoveryFailure = errors.New("oidc discovery failure") ErrIssuerEmpty = errors.New("issuer is empty") ErrIssuerUnsupportedScheme = errors.New("oidc issuer has unsupported scheme") ErrDiscoveryResponseParseFailed = errors.New("oidc discovery response parse failed") ErrJWKSCacheRegisterFailed = errors.New("jwks cache register failed") ErrJWKSCacheRefreshFailed = errors.New("mandatory jwks cache refresh failed") ErrJWKSUriInvalid = errors.New("jwks uri is not a valid uri") )
var ErrorChannelName = internal.ErrorChannelName
Functions ¶
func RecoveryHandler ¶
Types ¶
type ErrorHandler ¶
type ErrorHandler struct{}
func (ErrorHandler) Gin ¶
func (h ErrorHandler) Gin(c *gin.Context)
Gin catches all errors which occurred during the execution of a request and attaches them to the response object. If any errors are set using (gin.Context).Error(err) the handler aborts the context if that didn't already happen
func (ErrorHandler) Handler ¶
func (h ErrorHandler) Handler(next http.Handler) http.Handler
Handler is used to inject a channel into the request's context to enable a deferred handling of errors that may occur during handling of a request. The channel will be inserted using the ErrorChannelName variable which is generated automatically to circumvent possible name clashes. Furthermore, the ErrorHandler also recovers from internal panics and sends an error message about them as well.
In case a types.ServiceError and multiple Errors are supplied to the ErrorHandler the errors are automatically added to the Errors field and sent together with the supplied types.ServiceError instance
Usage Example:
r := chi.NewRouter() r.Use(middleware.ErrorHandler) r.Get("/", func(w http.ResponseWriter, r *http.Request) { errorChannel := r.Context.Value(middleware.ErrorChannelName).(chan interface{}) errorChannel <- errors.New("example error") })
The ErrorHandler accepts objects implementing the Error interface and types.ServiceError objects. Using other types will result in a InvalidTypeProvided error being sent instead using the undocumented HTTP Status Code 999.
type JWTValidator ¶
type JWTValidator struct {
// contains filtered or unexported fields
}
JWTValidator enables the gin router and the stdlib to validate a JWT passed in the request headers. It expects the OAuth 2.0 Bearer Token scheme as Authorization method. To apply the validator, use either the GinHandler or Handler function depending on the router you are using
func (*JWTValidator) AddParserOption ¶ added in v2.2.0
func (v *JWTValidator) AddParserOption(options ...jwt.ParseOption)
func (*JWTValidator) Configure ¶
func (v *JWTValidator) Configure(issuer string, jwksUri string, allowFaultyJWKSUri bool) error
Configure allows the manual configuration of an issuer and a JWKS uri (used to validate JWTs) but allows using incorrect JWKS uris to handle manual or missing JWKS
func (*JWTValidator) DiscoverAndConfigure ¶
func (v *JWTValidator) DiscoverAndConfigure(issuer string) error
DiscoverAndConfigure uses the OpenID Connect discovery mechanism to discover the required variables and uris and configures them accordingly
func (*JWTValidator) GinHandler ¶
func (v *JWTValidator) GinHandler(c *gin.Context)
type RequireScope ¶
type RequireScope struct{}
func (RequireScope) Gin ¶
func (s RequireScope) Gin(scope string, level types.Scope) gin.HandlerFunc