config.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package jwt
  2. import "github.com/golang-jwt/jwt/v4"
  3. const (
  4. // DefaultContextKey jwt
  5. DefaultContextKey = "jwt"
  6. )
  7. // Config is a struct for specifying configuration options for the jwt middleware.
  8. type Config struct {
  9. // The function that will return the Key to validate the JWT.
  10. // It can be either a shared secret or a public key.
  11. // Default value: nil
  12. ValidationKeyGetter jwt.Keyfunc
  13. // The name of the property in the request where the user (&token) information
  14. // from the JWT will be stored.
  15. // Default value: "jwt"
  16. ContextKey string
  17. // The function that will be called when there's an error validating the token
  18. // Default value:
  19. ErrorHandler errorHandler
  20. // A boolean indicating if the credentials are required or not
  21. // Default value: false
  22. CredentialsOptional bool
  23. // A function that extracts the token from the request
  24. // Default: FromAuthHeader (i.e., from Authorization header as bearer token)
  25. Extractor TokenExtractor
  26. // When set, all requests with the OPTIONS method will use authentication
  27. // if you enable this option you should register your route with iris.Options(...) also
  28. // Default: false
  29. EnableAuthOnOptions bool
  30. // When set, the middelware verifies that tokens are signed with the specific signing algorithm
  31. // If the signing method is not constant the ValidationKeyGetter callback can be used to implement additional checks
  32. // Important to avoid security issues described here: https://auth0.com/blog/2015/03/31/critical-vulnerabilities-in-json-web-token-libraries/
  33. // Default: nil
  34. SigningMethod jwt.SigningMethod
  35. // When set, the expiration time of token will be check every time
  36. // if the token was expired, expiration error will be returned
  37. // Default: false
  38. Expiration bool
  39. }