|
14 | 14 | from josepy.jwk import JWK
|
15 | 15 | from josepy.jws import JWS, Header
|
16 | 16 | from requests.auth import HTTPBasicAuth
|
| 17 | +from requests.exceptions import HTTPError |
17 | 18 |
|
18 | 19 | from mozilla_django_oidc.utils import absolutify, import_from_settings
|
19 | 20 |
|
@@ -235,9 +236,20 @@ def get_token(self, payload):
|
235 | 236 | timeout=self.get_settings("OIDC_TIMEOUT", None),
|
236 | 237 | proxies=self.get_settings("OIDC_PROXY", None),
|
237 | 238 | )
|
238 |
| - response.raise_for_status() |
| 239 | + self.raise_token_response_error(response) |
239 | 240 | return response.json()
|
240 | 241 |
|
| 242 | + def raise_token_response_error(self, response): |
| 243 | + """Raises :class:`HTTPError`, if one occurred. |
| 244 | + as per: https://datatracker.ietf.org/doc/html/rfc6749#section-5.2 |
| 245 | + """ |
| 246 | + # if there wasn't an error all is good |
| 247 | + if response.status_code == 200: |
| 248 | + return |
| 249 | + # otherwise something is up... |
| 250 | + http_error_msg = f"Get Token Error (url: {response.url}, status: {response.status_code}, body: {response.text})" |
| 251 | + raise HTTPError(http_error_msg, response=response) |
| 252 | + |
241 | 253 | def get_userinfo(self, access_token, id_token, payload):
|
242 | 254 | """Return user details dictionary. The id_token and payload are not used in
|
243 | 255 | the default implementation, but may be used when overriding this method"""
|
|
0 commit comments