@@ -38,6 +38,11 @@ def decode_id_token(id_token, client_id=None, issuer=None, nonce=None, now=None)
3838 """
3939 decoded = json .loads (decode_part (id_token .split ('.' )[1 ]))
4040 err = None # https://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation
41+ _now = now or time .time ()
42+ if _now < decoded .get ("nbf" , _now - 1 ): # nbf is optional per JWT specs
43+ # This is not an ID token validation, but a JWT validation
44+ # https://tools.ietf.org/html/rfc7519#section-4.1.5
45+ err = "0. The ID token is not yet valid"
4146 if issuer and issuer != decoded ["iss" ]:
4247 # https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfigurationResponse
4348 err = ('2. The Issuer Identifier for the OpenID Provider, "%s", '
@@ -53,7 +58,7 @@ def decode_id_token(id_token, client_id=None, issuer=None, nonce=None, now=None)
5358 # the Client and the Token Endpoint (which it is in this flow),
5459 # the TLS server validation MAY be used to validate the issuer
5560 # in place of checking the token signature.
56- if ( now or time . time ()) > decoded ["exp" ]:
61+ if _now > decoded ["exp" ]:
5762 err = "9. The current time MUST be before the time represented by the exp Claim."
5863 if nonce and nonce != decoded .get ("nonce" ):
5964 err = ("11. Nonce must be the same value "
0 commit comments