Skip to content

Commit 4089ce3

Browse files
liudonggalaxyazmeuk
authored andcommitted
fix: Add a 60-second leeway to the JWT validation logic (authlib#689)
* Add a 60-second leeway to the JWT validation logic * Add parameter name * Shorten lines. --------- Co-authored-by: Éloi Rivard <eloi@yaal.coop>
1 parent 2de7e3e commit 4089ce3

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

authlib/oauth2/rfc7523/client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ class JWTBearerClientAssertion:
1919
#: Name of the client authentication method
2020
CLIENT_AUTH_METHOD = "client_assertion_jwt"
2121

22-
def __init__(self, token_url, validate_jti=True):
22+
def __init__(self, token_url, validate_jti=True, leeway=60):
2323
self.token_url = token_url
2424
self._validate_jti = validate_jti
25+
# A small allowance of time, typically no more than a few minutes,
26+
# to account for clock skew. The default is 60 seconds.
27+
self.leeway = leeway
2528

2629
def __call__(self, query_client, request):
2730
data = request.form
@@ -64,7 +67,7 @@ def process_assertion_claims(self, assertion, resolve_key):
6467
claims = jwt.decode(
6568
assertion, resolve_key, claims_options=self.create_claims_options()
6669
)
67-
claims.validate()
70+
claims.validate(leeway=self.leeway)
6871
except JoseError as e:
6972
log.debug("Assertion Error: %r", e)
7073
raise InvalidClientError() from e

authlib/oauth2/rfc7523/jwt_bearer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class JWTBearerGrant(BaseGrant, TokenEndpointMixin):
2626
"exp": {"essential": True},
2727
}
2828

29+
# A small allowance of time, typically no more than a few minutes,
30+
# to account for clock skew. The default is 60 seconds.
31+
LEEWAY = 60
32+
2933
@staticmethod
3034
def sign(
3135
key,
@@ -55,7 +59,7 @@ def process_assertion_claims(self, assertion):
5559
claims = jwt.decode(
5660
assertion, self.resolve_public_key, claims_options=self.CLAIMS_OPTIONS
5761
)
58-
claims.validate()
62+
claims.validate(leeway=self.LEEWAY)
5963
except JoseError as e:
6064
log.debug("Assertion Error: %r", e)
6165
raise InvalidGrantError(description=e.description) from e

0 commit comments

Comments
 (0)