Return the JSON object of a token endpoint response. Raise the HTTP error of the response when its body is not a JSON object, such as a rate-limit page from a gateway.
(resp)
| 18 | |
| 19 | |
| 20 | def _load_token_response(resp): |
| 21 | """Return the JSON object of a token endpoint response. |
| 22 | |
| 23 | Raise the HTTP error of the response when its body is not a JSON object, |
| 24 | such as a rate-limit page from a gateway. |
| 25 | """ |
| 26 | if resp.status_code >= 500: |
| 27 | resp.raise_for_status() |
| 28 | |
| 29 | try: |
| 30 | token = resp.json() |
| 31 | except ValueError: |
| 32 | token = None |
| 33 | |
| 34 | if not isinstance(token, dict): |
| 35 | resp.raise_for_status() |
| 36 | raise ValueError( |
| 37 | f"Token endpoint response is not a JSON object (HTTP {resp.status_code})." |
| 38 | ) |
| 39 | return token |
| 40 | |
| 41 | |
| 42 | class OAuth2Client: |
no outgoing calls
no test coverage detected