Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ of ``mozilla-django-oidc``.

Controls whether the OpenID Connect client verifies the signature of the JWT tokens

.. py:attribute:: OIDC_JWT_LEEWAY

:default: ``0``

A time margin in seconds for the expiration check.

.. py:attribute:: OIDC_VERIFY_KID

:default: ``True``
Expand Down
13 changes: 11 additions & 2 deletions mozilla_django_oidc/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(self, *args, **kwargs):
self.OIDC_RP_CLIENT_SECRET = self.get_settings("OIDC_RP_CLIENT_SECRET")
self.OIDC_RP_SIGN_ALGO = self.get_settings("OIDC_RP_SIGN_ALGO", "HS256")
self.OIDC_RP_IDP_SIGN_KEY = self.get_settings("OIDC_RP_IDP_SIGN_KEY", None)
self.OIDC_JWT_LEEWAY = self.get_settings("OIDC_JWT_LEEWAY", 0)

if (
self.OIDC_RP_SIGN_ALGO.startswith("RS")
Expand Down Expand Up @@ -142,7 +143,11 @@ def _verify_jws(self, payload, key):
try:
# Maybe add a settings to enforce audiance validation
return jwt.decode(
payload, key, algorithms=alg, options={"verify_aud": False}
payload,
key,
algorithms=alg,
leeway=self.OIDC_JWT_LEEWAY,
options={"verify_aud": False},
)
except jwt.DecodeError:
msg = "JWS token verification failed."
Expand Down Expand Up @@ -186,7 +191,11 @@ def get_payload_data(self, token, key):

# If config allows unsecured JWTs check the header and return the decoded payload
if "alg" in header and header["alg"] == "none":
return jwt.decode(token, options={"verify_signature": False})
return jwt.decode(
token,
leeway=self.OIDC_JWT_LEEWAY,
options={"verify_signature": False},
)

# By default fallback to verify JWT signatures
return self._verify_jws(token, key)
Expand Down