Skip to content

Commit

Permalink
fix: token error response handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dopry authored and akatsoulas committed Nov 24, 2023
1 parent adea094 commit 061b888
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion mozilla_django_oidc/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from josepy.jwk import JWK
from josepy.jws import JWS, Header
from requests.auth import HTTPBasicAuth
from requests.exceptions import HTTPError

from mozilla_django_oidc.utils import absolutify, import_from_settings

Expand Down Expand Up @@ -235,9 +236,20 @@ def get_token(self, payload):
timeout=self.get_settings("OIDC_TIMEOUT", None),
proxies=self.get_settings("OIDC_PROXY", None),
)
response.raise_for_status()
self.raise_token_response_error(response)
return response.json()

def raise_token_response_error(self, response):
"""Raises :class:`HTTPError`, if one occurred.
as per: https://datatracker.ietf.org/doc/html/rfc6749#section-5.2
"""
# if there wasn't an error all is good
if response.status_code == 200:
return
# otherwise something is up...
http_error_msg = f"Get Token Error (url: {response.url}, status: {response.status_code}, body: {response.text})"
raise HTTPError(http_error_msg, response=response)

def get_userinfo(self, access_token, id_token, payload):
"""Return user details dictionary. The id_token and payload are not used in
the default implementation, but may be used when overriding this method"""
Expand Down

0 comments on commit 061b888

Please sign in to comment.