Skip to content

Commit 0081ca4

Browse files
committed
auth: make TokenOIDCAuthenticationBackend closer to OIDCAuthenticationBackend by using \store_tokens\
1 parent 334713c commit 0081ca4

1 file changed

Lines changed: 4 additions & 13 deletions

File tree

mozilla_django_oidc/auth.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -392,20 +392,11 @@ def authenticate(self, request, **kwargs):
392392
if authorization := request.META.get("HTTP_AUTHORIZATION"):
393393
scheme, token = authorization.split(maxsplit=1)
394394
if scheme.lower() == "bearer":
395+
self.store_tokens(token, None)
395396
try:
396-
# get_or_create_user and get_userinfo uses neither id_token nor payload.
397397
return self.get_or_create_user(token, None, None)
398-
except HTTPError as exc:
399-
# get_or_create_user forwards the token to the
400-
# OIDC_OP_USER_ENDPOINT. If the token is invalid, that endpoint will
401-
# return a 401 error.
402-
# We also cover 403 response statuses as they would indicate a
403-
# similar authentication failure.
404-
if exc.response.status_code in [401, 403]:
405-
LOGGER.warning(
406-
"failed to authenticate user from bearer token: %s", exc
407-
)
408-
return None
409-
raise exc
398+
except SuspiciousOperation as exc:
399+
LOGGER.warning("failed to get or create user: %s", exc)
400+
return None
410401

411402
return None

0 commit comments

Comments
 (0)