@@ -119,102 +119,6 @@ func (c *RegisteredClaims) VerifyIssuer(cmp string, req bool) bool {
119
119
return verifyIss (c .Issuer , cmp , req )
120
120
}
121
121
122
- // StandardClaims are a structured version of the JWT Claims Set, as referenced at
123
- // https://datatracker.ietf.org/doc/html/rfc7519#section-4. They do not follow the
124
- // specification exactly, since they were based on an earlier draft of the
125
- // specification and not updated. The main difference is that they only
126
- // support integer-based date fields and singular audiences. This might lead to
127
- // incompatibilities with other JWT implementations. The use of this is discouraged, instead
128
- // the newer RegisteredClaims struct should be used.
129
- //
130
- // Deprecated: Use RegisteredClaims instead for a forward-compatible way to access registered claims in a struct.
131
- type StandardClaims struct {
132
- Audience string `json:"aud,omitempty"`
133
- ExpiresAt int64 `json:"exp,omitempty"`
134
- Id string `json:"jti,omitempty"`
135
- IssuedAt int64 `json:"iat,omitempty"`
136
- Issuer string `json:"iss,omitempty"`
137
- NotBefore int64 `json:"nbf,omitempty"`
138
- Subject string `json:"sub,omitempty"`
139
- }
140
-
141
- // Valid validates time based claims "exp, iat, nbf". There is no accounting for clock skew.
142
- // As well, if any of the above claims are not in the token, it will still
143
- // be considered a valid claim.
144
- func (c StandardClaims ) Valid () error {
145
- vErr := new (ValidationError )
146
- now := TimeFunc ().Unix ()
147
-
148
- // The claims below are optional, by default, so if they are set to the
149
- // default value in Go, let's not fail the verification for them.
150
- if ! c .VerifyExpiresAt (now , false ) {
151
- delta := time .Unix (now , 0 ).Sub (time .Unix (c .ExpiresAt , 0 ))
152
- vErr .Inner = fmt .Errorf ("%s by %s" , ErrTokenExpired , delta )
153
- vErr .Errors |= ValidationErrorExpired
154
- }
155
-
156
- if ! c .VerifyIssuedAt (now , false ) {
157
- vErr .Inner = ErrTokenUsedBeforeIssued
158
- vErr .Errors |= ValidationErrorIssuedAt
159
- }
160
-
161
- if ! c .VerifyNotBefore (now , false ) {
162
- vErr .Inner = ErrTokenNotValidYet
163
- vErr .Errors |= ValidationErrorNotValidYet
164
- }
165
-
166
- if vErr .valid () {
167
- return nil
168
- }
169
-
170
- return vErr
171
- }
172
-
173
- // VerifyAudience compares the aud claim against cmp.
174
- // If required is false, this method will return true if the value matches or is unset
175
- func (c * StandardClaims ) VerifyAudience (cmp string , req bool ) bool {
176
- return verifyAud ([]string {c .Audience }, cmp , req )
177
- }
178
-
179
- // VerifyExpiresAt compares the exp claim against cmp (cmp < exp).
180
- // If req is false, it will return true, if exp is unset.
181
- func (c * StandardClaims ) VerifyExpiresAt (cmp int64 , req bool ) bool {
182
- if c .ExpiresAt == 0 {
183
- return verifyExp (nil , time .Unix (cmp , 0 ), req )
184
- }
185
-
186
- t := time .Unix (c .ExpiresAt , 0 )
187
- return verifyExp (& t , time .Unix (cmp , 0 ), req )
188
- }
189
-
190
- // VerifyIssuedAt compares the iat claim against cmp (cmp >= iat).
191
- // If req is false, it will return true, if iat is unset.
192
- func (c * StandardClaims ) VerifyIssuedAt (cmp int64 , req bool ) bool {
193
- if c .IssuedAt == 0 {
194
- return verifyIat (nil , time .Unix (cmp , 0 ), req )
195
- }
196
-
197
- t := time .Unix (c .IssuedAt , 0 )
198
- return verifyIat (& t , time .Unix (cmp , 0 ), req )
199
- }
200
-
201
- // VerifyNotBefore compares the nbf claim against cmp (cmp >= nbf).
202
- // If req is false, it will return true, if nbf is unset.
203
- func (c * StandardClaims ) VerifyNotBefore (cmp int64 , req bool ) bool {
204
- if c .NotBefore == 0 {
205
- return verifyNbf (nil , time .Unix (cmp , 0 ), req )
206
- }
207
-
208
- t := time .Unix (c .NotBefore , 0 )
209
- return verifyNbf (& t , time .Unix (cmp , 0 ), req )
210
- }
211
-
212
- // VerifyIssuer compares the iss claim against cmp.
213
- // If required is false, this method will return true if the value matches or is unset
214
- func (c * StandardClaims ) VerifyIssuer (cmp string , req bool ) bool {
215
- return verifyIss (c .Issuer , cmp , req )
216
- }
217
-
218
122
// ----- helpers
219
123
220
124
func verifyAud (aud []string , cmp string , required bool ) bool {
0 commit comments