@@ -100,6 +100,9 @@ type Config struct {
100
100
101
101
// Time function to check Token expiry. Defaults to time.Now
102
102
Now func () time.Time
103
+
104
+ // Duration for clock skew. Defaults to 5 minutes.
105
+ ClockSkew time.Duration
103
106
}
104
107
105
108
// Verifier returns an IDTokenVerifier that uses the provider's key set to verify JWTs.
@@ -267,18 +270,22 @@ func (v *IDTokenVerifier) Verify(ctx context.Context, rawIDToken string) (*IDTok
267
270
}
268
271
nowTime := now ()
269
272
270
- if t .Expiry .Before (nowTime ) {
273
+ // Set to 5 minutes by default since this is what other OpenID Connect providers do to deal with clock skew.
274
+ // https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/blob/6.12.2/src/Microsoft.IdentityModel.Tokens/TokenValidationParameters.cs#L149-L153
275
+ clockSkew := 5 * time .Minute
276
+ if v .config .ClockSkew > 0 {
277
+ clockSkew = v .config .ClockSkew
278
+ }
279
+
280
+ if t .Expiry .Before (nowTime .Add (- clockSkew )) {
271
281
return nil , fmt .Errorf ("oidc: token is expired (Token Expiry: %v)" , t .Expiry )
272
282
}
273
283
274
284
// If nbf claim is provided in token, ensure that it is indeed in the past.
275
285
if token .NotBefore != nil {
276
286
nbfTime := time .Time (* token .NotBefore )
277
- // Set to 5 minutes since this is what other OpenID Connect providers do to deal with clock skew.
278
- // https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/blob/6.12.2/src/Microsoft.IdentityModel.Tokens/TokenValidationParameters.cs#L149-L153
279
- leeway := 5 * time .Minute
280
287
281
- if nowTime .Add (leeway ).Before (nbfTime ) {
288
+ if nowTime .Add (clockSkew ).Before (nbfTime ) {
282
289
return nil , fmt .Errorf ("oidc: current time %v before the nbf (not before) time: %v" , nowTime , nbfTime )
283
290
}
284
291
}
0 commit comments