Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: token error response handling #464

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 15 additions & 1 deletion mozilla_django_oidc/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

from mozilla_django_oidc.utils import absolutify, import_from_settings

from requests.exceptions import HTTPError

LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -229,9 +231,21 @@ def get_token(self, payload):
verify=self.get_settings('OIDC_VERIFY_SSL', True),
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