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