You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

registered_claims.go 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package jwt
  2. // RegisteredClaims are a structured version of the JWT Claims Set,
  3. // restricted to Registered Claim Names, as referenced at
  4. // https://datatracker.ietf.org/doc/html/rfc7519#section-4.1
  5. //
  6. // This type can be used on its own, but then additional private and
  7. // public claims embedded in the JWT will not be parsed. The typical use-case
  8. // therefore is to embedded this in a user-defined claim type.
  9. //
  10. // See examples for how to use this with your own claim types.
  11. type RegisteredClaims struct {
  12. // the `iss` (Issuer) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.1
  13. Issuer string `json:"iss,omitempty"`
  14. // the `sub` (Subject) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.2
  15. Subject string `json:"sub,omitempty"`
  16. // the `aud` (Audience) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.3
  17. Audience ClaimStrings `json:"aud,omitempty"`
  18. // the `exp` (Expiration Time) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.4
  19. ExpiresAt *NumericDate `json:"exp,omitempty"`
  20. // the `nbf` (Not Before) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.5
  21. NotBefore *NumericDate `json:"nbf,omitempty"`
  22. // the `iat` (Issued At) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.6
  23. IssuedAt *NumericDate `json:"iat,omitempty"`
  24. // the `jti` (JWT ID) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.7
  25. ID string `json:"jti,omitempty"`
  26. }
  27. // GetExpirationTime implements the Claims interface.
  28. func (c RegisteredClaims) GetExpirationTime() (*NumericDate, error) {
  29. return c.ExpiresAt, nil
  30. }
  31. // GetNotBefore implements the Claims interface.
  32. func (c RegisteredClaims) GetNotBefore() (*NumericDate, error) {
  33. return c.NotBefore, nil
  34. }
  35. // GetIssuedAt implements the Claims interface.
  36. func (c RegisteredClaims) GetIssuedAt() (*NumericDate, error) {
  37. return c.IssuedAt, nil
  38. }
  39. // GetAudience implements the Claims interface.
  40. func (c RegisteredClaims) GetAudience() (ClaimStrings, error) {
  41. return c.Audience, nil
  42. }
  43. // GetIssuer implements the Claims interface.
  44. func (c RegisteredClaims) GetIssuer() (string, error) {
  45. return c.Issuer, nil
  46. }
  47. // GetSubject implements the Claims interface.
  48. func (c RegisteredClaims) GetSubject() (string, error) {
  49. return c.Subject, nil
  50. }