@@ -9,10 +9,7 @@ import (
99// Claims must just have a Valid method that determines
1010// if the token is invalid for any supported reason
1111type 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
1613}
1714
1815// RegisteredClaims are a structured version of the JWT Claims Set,
@@ -51,13 +48,13 @@ type RegisteredClaims struct {
5148// There is no accounting for clock skew.
5249// As well, if any of the above claims are not in the token, it will still
5350// be considered a valid claim.
54- func (c RegisteredClaims ) Valid (opts ... validationOption ) error {
51+ func (c RegisteredClaims ) Valid () error {
5552 vErr := new (ValidationError )
5653 now := TimeFunc ()
5754
5855 // The claims below are optional, by default, so if they are set to the
5956 // 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 ) {
6158 delta := now .Sub (c .ExpiresAt .Time )
6259 vErr .Inner = fmt .Errorf ("%s by %s" , ErrTokenExpired , delta )
6360 vErr .Errors |= ValidationErrorExpired
@@ -68,7 +65,7 @@ func (c RegisteredClaims) Valid(opts ...validationOption) error {
6865 vErr .Errors |= ValidationErrorIssuedAt
6966 }
7067
71- if ! c .VerifyNotBefore (now , false , opts ... ) {
68+ if ! c .VerifyNotBefore (now , false ) {
7269 vErr .Inner = ErrTokenNotValidYet
7370 vErr .Errors |= ValidationErrorNotValidYet
7471 }
@@ -88,16 +85,12 @@ func (c *RegisteredClaims) VerifyAudience(cmp string, req bool) bool {
8885
8986// VerifyExpiresAt compares the exp claim against cmp (cmp < exp).
9087// 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 {
9689 if c .ExpiresAt == nil {
97- return verifyExp (nil , cmp , req , validator . leeway )
90+ return verifyExp (nil , cmp , req )
9891 }
9992
100- return verifyExp (& c .ExpiresAt .Time , cmp , req , validator . leeway )
93+ return verifyExp (& c .ExpiresAt .Time , cmp , req )
10194}
10295
10396// VerifyIssuedAt compares the iat claim against cmp (cmp >= iat).
@@ -112,16 +105,12 @@ func (c *RegisteredClaims) VerifyIssuedAt(cmp time.Time, req bool) bool {
112105
113106// VerifyNotBefore compares the nbf claim against cmp (cmp >= nbf).
114107// 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 {
120109 if c .NotBefore == nil {
121- return verifyNbf (nil , cmp , req , validator . leeway )
110+ return verifyNbf (nil , cmp , req )
122111 }
123112
124- return verifyNbf (& c .NotBefore .Time , cmp , req , validator . leeway )
113+ return verifyNbf (& c .NotBefore .Time , cmp , req )
125114}
126115
127116// VerifyIssuer compares the iss claim against cmp.
@@ -152,13 +141,13 @@ type StandardClaims struct {
152141// Valid validates time based claims "exp, iat, nbf". There is no accounting for clock skew.
153142// As well, if any of the above claims are not in the token, it will still
154143// be considered a valid claim.
155- func (c StandardClaims ) Valid (opts ... validationOption ) error {
144+ func (c StandardClaims ) Valid () error {
156145 vErr := new (ValidationError )
157146 now := TimeFunc ().Unix ()
158147
159148 // The claims below are optional, by default, so if they are set to the
160149 // 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 ) {
162151 delta := time .Unix (now , 0 ).Sub (time .Unix (c .ExpiresAt , 0 ))
163152 vErr .Inner = fmt .Errorf ("%s by %s" , ErrTokenExpired , delta )
164153 vErr .Errors |= ValidationErrorExpired
@@ -169,7 +158,7 @@ func (c StandardClaims) Valid(opts ...validationOption) error {
169158 vErr .Errors |= ValidationErrorIssuedAt
170159 }
171160
172- if ! c .VerifyNotBefore (now , false , opts ... ) {
161+ if ! c .VerifyNotBefore (now , false ) {
173162 vErr .Inner = ErrTokenNotValidYet
174163 vErr .Errors |= ValidationErrorNotValidYet
175164 }
@@ -189,17 +178,13 @@ func (c *StandardClaims) VerifyAudience(cmp string, req bool) bool {
189178
190179// VerifyExpiresAt compares the exp claim against cmp (cmp < exp).
191180// 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 {
197182 if c .ExpiresAt == 0 {
198- return verifyExp (nil , time .Unix (cmp , 0 ), req , validator . leeway )
183+ return verifyExp (nil , time .Unix (cmp , 0 ), req )
199184 }
200185
201186 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 )
203188}
204189
205190// VerifyIssuedAt compares the iat claim against cmp (cmp >= iat).
@@ -215,17 +200,13 @@ func (c *StandardClaims) VerifyIssuedAt(cmp int64, req bool) bool {
215200
216201// VerifyNotBefore compares the nbf claim against cmp (cmp >= nbf).
217202// 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 {
223204 if c .NotBefore == 0 {
224- return verifyNbf (nil , time .Unix (cmp , 0 ), req , validator . leeway )
205+ return verifyNbf (nil , time .Unix (cmp , 0 ), req )
225206 }
226207
227208 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 )
229210}
230211
231212// VerifyIssuer compares the iss claim against cmp.
@@ -259,11 +240,11 @@ func verifyAud(aud []string, cmp string, required bool) bool {
259240 return result
260241}
261242
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 {
263244 if exp == nil {
264245 return ! required
265246 }
266- return now .Before (( * exp ). Add ( + skew ) )
247+ return now .Before (* exp )
267248}
268249
269250func 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 {
273254 return now .After (* iat ) || now .Equal (* iat )
274255}
275256
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 {
277258 if nbf == nil {
278259 return ! required
279260 }
280- t := (* nbf ).Add (- skew )
281- return now .After (t ) || now .Equal (t )
261+ return now .After (* nbf ) || now .Equal (* nbf )
282262}
283263
284264func verifyIss (iss string , cmp string , required bool ) bool {
0 commit comments