Documentation
¶
Index ¶
- Constants
- func CheckOAuthScope(jwksUrl, scope string) func(tokenString string) bool
- func CheckOAuthScopeFromEnv(scope string) func(tokenString string) bool
- func FromAuthHeader(r libhttp.Request) (string, error)
- func OnError(r libhttp.Request, errMsg string) libhttp.Response
- func OnScopeInsufficient(r libhttp.Request, errMsg string) libhttp.Response
- func ValidationKeyGetterFromEnv() jwt.Keyfunc
- func ValidationKeyGetterFromMetaData(aud, iss, jwksUrl string) jwt.Keyfunc
- type CustomClaims
- type EmptyTokenHandler
- type ErrorHandler
- type JSONWebKeys
- type Jwks
- type Option
- func WithCredentialsOptional(o bool) Option
- func WithDebug() Option
- func WithEmptyTokenHandler(e EmptyTokenHandler) Option
- func WithEnvScopeChecker(scope string) Option
- func WithEnvValidationKeyGetter() Option
- func WithScopeCheckErrorHandler(e ErrorHandler) Option
- func WithScopeChecker(s ScopeChecker) Option
- func WithSigningMethod(s jwt.SigningMethod) Option
- func WithTokenExtractor(extractor TokenExtractor) Option
- func WithTokenExtractors(extractors ...TokenExtractor) Option
- func WithUserProperty(u string) Option
- func WithValidationKeyGetter(getter jwt.Keyfunc) Option
- type ScopeChecker
- type TokenExtractor
- type Validator
Constants ¶
View Source
const ( OAuthAudienceEnvKey = "OAUTH_AUDIENCE" OAuthIssuerEnvKey = "OAUTH_ISSUER" OAuthJWKSUrlEnvKey = "OAUTH_JWKS_URL" DefaultUserProperty = "user" )
Variables ¶
This section is empty.
Functions ¶
func CheckOAuthScope ¶
func CheckOAuthScopeFromEnv ¶
func OnScopeInsufficient ¶
Types ¶
type CustomClaims ¶
type CustomClaims struct {
Scope string `json:"scope"`
jwt.StandardClaims
}
type EmptyTokenHandler ¶
type JSONWebKeys ¶
type Jwks ¶
type Jwks struct {
Keys []JSONWebKeys `json:"keys"`
}
type Option ¶
type Option func(j *Validator)
func WithCredentialsOptional ¶
func WithEmptyTokenHandler ¶
func WithEmptyTokenHandler(e EmptyTokenHandler) Option
func WithEnvScopeChecker ¶
func WithEnvValidationKeyGetter ¶
func WithEnvValidationKeyGetter() Option
func WithScopeCheckErrorHandler ¶
func WithScopeCheckErrorHandler(e ErrorHandler) Option
func WithScopeChecker ¶
func WithScopeChecker(s ScopeChecker) Option
func WithSigningMethod ¶
func WithSigningMethod(s jwt.SigningMethod) Option
func WithTokenExtractor ¶
func WithTokenExtractor(extractor TokenExtractor) Option
func WithTokenExtractors ¶
func WithTokenExtractors(extractors ...TokenExtractor) Option
func WithUserProperty ¶
func WithValidationKeyGetter ¶
type ScopeChecker ¶
type TokenExtractor ¶
func FromFirst ¶
func FromFirst(extractors ...TokenExtractor) TokenExtractor
FromFirst returns a function that runs multiple token extractors and takes the first token it finds
func TokenExtractorFromParameter ¶
func TokenExtractorFromParameter(param string) TokenExtractor
TokenExtractorFromParameter returns a TokenExtractor that extracts the token from the specified query string parameter
type Validator ¶
type Validator struct {
// If you are too lazy to scope check in your request handlers, you can do it here
ScopeChecker ScopeChecker
// Callback for an unsuccessful Errorcheck
// Default value: OnScopeInsufficient
ScopeCheckErrorHandler ErrorHandler
// The function that will return the Key to validate the JWT.
// It can be either a shared secret or a public key.
// Default value: ValidationKeyGetterFromEnv()
ValidationKeyGetter jwt.Keyfunc
// The name of the property in the request where the user information
// from the JWT will be stored.
// Default value: "user"
UserProperty string
// The function that will be called when there's an error validating the token
// Default value: OnError
ErrorHandler ErrorHandler
// The function that will be called when there is no token set
// Default value: OnEmptyToken
EmptyTokenHandler EmptyTokenHandler
// A boolean indicating if the credentials are required or not
// Default value: false
CredentialsOptional bool
// A function that extracts the token from the request
// Default: FromAuthHeader (i.e., from Authorization header as bearer token)
Extractor TokenExtractor
// Debug flag turns on debugging output
// Default: false
Debug bool
// When set, all requests with the OPTIONS method will use authentication
// Default: false
EnableAuthOnOptions bool
// When set, the middleware verifies that tokens are signed with the specific signing algorithm
// If the signing method is not constant the ValidationKeyGetter callback can be used to implement additional checks
// Important to avoid security issues described here: https://auth0.com/blog/2015/03/31/critical-vulnerabilities-in-json-web-token-libraries/
// Default: jwt.SigningMethodRS256
SigningMethod jwt.SigningMethod
}
Click to show internal directories.
Click to hide internal directories.