@@ -9,10 +9,7 @@ import (
9
9
// Claims must just have a Valid method that determines
10
10
// if the token is invalid for any supported reason
11
11
type Claims interface {
12
- // Valid implements claim validation. The opts are function style options that can
13
- // be used to fine-tune the validation. The type used for the options is intentionally
14
- // un-exported, since its API and its naming is subject to change.
15
- Valid (opts ... validationOption ) error
12
+ Valid () error
16
13
}
17
14
18
15
// RegisteredClaims are a structured version of the JWT Claims Set,
@@ -51,13 +48,13 @@ type RegisteredClaims struct {
51
48
// There is no accounting for clock skew.
52
49
// As well, if any of the above claims are not in the token, it will still
53
50
// be considered a valid claim.
54
- func (c RegisteredClaims ) Valid (opts ... validationOption ) error {
51
+ func (c RegisteredClaims ) Valid () error {
55
52
vErr := new (ValidationError )
56
53
now := TimeFunc ()
57
54
58
55
// The claims below are optional, by default, so if they are set to the
59
56
// default value in Go, let's not fail the verification for them.
60
- if ! c .VerifyExpiresAt (now , false , opts ... ) {
57
+ if ! c .VerifyExpiresAt (now , false ) {
61
58
delta := now .Sub (c .ExpiresAt .Time )
62
59
vErr .Inner = fmt .Errorf ("%s by %s" , ErrTokenExpired , delta )
63
60
vErr .Errors |= ValidationErrorExpired
@@ -68,7 +65,7 @@ func (c RegisteredClaims) Valid(opts ...validationOption) error {
68
65
vErr .Errors |= ValidationErrorIssuedAt
69
66
}
70
67
71
- if ! c .VerifyNotBefore (now , false , opts ... ) {
68
+ if ! c .VerifyNotBefore (now , false ) {
72
69
vErr .Inner = ErrTokenNotValidYet
73
70
vErr .Errors |= ValidationErrorNotValidYet
74
71
}
@@ -88,16 +85,12 @@ func (c *RegisteredClaims) VerifyAudience(cmp string, req bool) bool {
88
85
89
86
// VerifyExpiresAt compares the exp claim against cmp (cmp < exp).
90
87
// If req is false, it will return true, if exp is unset.
91
- func (c * RegisteredClaims ) VerifyExpiresAt (cmp time.Time , req bool , opts ... validationOption ) bool {
92
- validator := validator {}
93
- for _ , o := range opts {
94
- o (& validator )
95
- }
88
+ func (c * RegisteredClaims ) VerifyExpiresAt (cmp time.Time , req bool ) bool {
96
89
if c .ExpiresAt == nil {
97
- return verifyExp (nil , cmp , req , validator . leeway )
90
+ return verifyExp (nil , cmp , req )
98
91
}
99
92
100
- return verifyExp (& c .ExpiresAt .Time , cmp , req , validator . leeway )
93
+ return verifyExp (& c .ExpiresAt .Time , cmp , req )
101
94
}
102
95
103
96
// VerifyIssuedAt compares the iat claim against cmp (cmp >= iat).
@@ -112,16 +105,12 @@ func (c *RegisteredClaims) VerifyIssuedAt(cmp time.Time, req bool) bool {
112
105
113
106
// VerifyNotBefore compares the nbf claim against cmp (cmp >= nbf).
114
107
// If req is false, it will return true, if nbf is unset.
115
- func (c * RegisteredClaims ) VerifyNotBefore (cmp time.Time , req bool , opts ... validationOption ) bool {
116
- validator := validator {}
117
- for _ , o := range opts {
118
- o (& validator )
119
- }
108
+ func (c * RegisteredClaims ) VerifyNotBefore (cmp time.Time , req bool ) bool {
120
109
if c .NotBefore == nil {
121
- return verifyNbf (nil , cmp , req , validator . leeway )
110
+ return verifyNbf (nil , cmp , req )
122
111
}
123
112
124
- return verifyNbf (& c .NotBefore .Time , cmp , req , validator . leeway )
113
+ return verifyNbf (& c .NotBefore .Time , cmp , req )
125
114
}
126
115
127
116
// VerifyIssuer compares the iss claim against cmp.
@@ -152,13 +141,13 @@ type StandardClaims struct {
152
141
// Valid validates time based claims "exp, iat, nbf". There is no accounting for clock skew.
153
142
// As well, if any of the above claims are not in the token, it will still
154
143
// be considered a valid claim.
155
- func (c StandardClaims ) Valid (opts ... validationOption ) error {
144
+ func (c StandardClaims ) Valid () error {
156
145
vErr := new (ValidationError )
157
146
now := TimeFunc ().Unix ()
158
147
159
148
// The claims below are optional, by default, so if they are set to the
160
149
// default value in Go, let's not fail the verification for them.
161
- if ! c .VerifyExpiresAt (now , false , opts ... ) {
150
+ if ! c .VerifyExpiresAt (now , false ) {
162
151
delta := time .Unix (now , 0 ).Sub (time .Unix (c .ExpiresAt , 0 ))
163
152
vErr .Inner = fmt .Errorf ("%s by %s" , ErrTokenExpired , delta )
164
153
vErr .Errors |= ValidationErrorExpired
@@ -169,7 +158,7 @@ func (c StandardClaims) Valid(opts ...validationOption) error {
169
158
vErr .Errors |= ValidationErrorIssuedAt
170
159
}
171
160
172
- if ! c .VerifyNotBefore (now , false , opts ... ) {
161
+ if ! c .VerifyNotBefore (now , false ) {
173
162
vErr .Inner = ErrTokenNotValidYet
174
163
vErr .Errors |= ValidationErrorNotValidYet
175
164
}
@@ -189,17 +178,13 @@ func (c *StandardClaims) VerifyAudience(cmp string, req bool) bool {
189
178
190
179
// VerifyExpiresAt compares the exp claim against cmp (cmp < exp).
191
180
// If req is false, it will return true, if exp is unset.
192
- func (c * StandardClaims ) VerifyExpiresAt (cmp int64 , req bool , opts ... validationOption ) bool {
193
- validator := validator {}
194
- for _ , o := range opts {
195
- o (& validator )
196
- }
181
+ func (c * StandardClaims ) VerifyExpiresAt (cmp int64 , req bool ) bool {
197
182
if c .ExpiresAt == 0 {
198
- return verifyExp (nil , time .Unix (cmp , 0 ), req , validator . leeway )
183
+ return verifyExp (nil , time .Unix (cmp , 0 ), req )
199
184
}
200
185
201
186
t := time .Unix (c .ExpiresAt , 0 )
202
- return verifyExp (& t , time .Unix (cmp , 0 ), req , validator . leeway )
187
+ return verifyExp (& t , time .Unix (cmp , 0 ), req )
203
188
}
204
189
205
190
// VerifyIssuedAt compares the iat claim against cmp (cmp >= iat).
@@ -215,17 +200,13 @@ func (c *StandardClaims) VerifyIssuedAt(cmp int64, req bool) bool {
215
200
216
201
// VerifyNotBefore compares the nbf claim against cmp (cmp >= nbf).
217
202
// If req is false, it will return true, if nbf is unset.
218
- func (c * StandardClaims ) VerifyNotBefore (cmp int64 , req bool , opts ... validationOption ) bool {
219
- validator := validator {}
220
- for _ , o := range opts {
221
- o (& validator )
222
- }
203
+ func (c * StandardClaims ) VerifyNotBefore (cmp int64 , req bool ) bool {
223
204
if c .NotBefore == 0 {
224
- return verifyNbf (nil , time .Unix (cmp , 0 ), req , validator . leeway )
205
+ return verifyNbf (nil , time .Unix (cmp , 0 ), req )
225
206
}
226
207
227
208
t := time .Unix (c .NotBefore , 0 )
228
- return verifyNbf (& t , time .Unix (cmp , 0 ), req , validator . leeway )
209
+ return verifyNbf (& t , time .Unix (cmp , 0 ), req )
229
210
}
230
211
231
212
// VerifyIssuer compares the iss claim against cmp.
@@ -259,11 +240,11 @@ func verifyAud(aud []string, cmp string, required bool) bool {
259
240
return result
260
241
}
261
242
262
- func verifyExp (exp * time.Time , now time.Time , required bool , skew time. Duration ) bool {
243
+ func verifyExp (exp * time.Time , now time.Time , required bool ) bool {
263
244
if exp == nil {
264
245
return ! required
265
246
}
266
- return now .Before (( * exp ). Add ( + skew ) )
247
+ return now .Before (* exp )
267
248
}
268
249
269
250
func verifyIat (iat * time.Time , now time.Time , required bool ) bool {
@@ -273,12 +254,11 @@ func verifyIat(iat *time.Time, now time.Time, required bool) bool {
273
254
return now .After (* iat ) || now .Equal (* iat )
274
255
}
275
256
276
- func verifyNbf (nbf * time.Time , now time.Time , required bool , skew time. Duration ) bool {
257
+ func verifyNbf (nbf * time.Time , now time.Time , required bool ) bool {
277
258
if nbf == nil {
278
259
return ! required
279
260
}
280
- t := (* nbf ).Add (- skew )
281
- return now .After (t ) || now .Equal (t )
261
+ return now .After (* nbf ) || now .Equal (* nbf )
282
262
}
283
263
284
264
func verifyIss (iss string , cmp string , required bool ) bool {
0 commit comments