sources/oauth: fix not all token errors being logged with response

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens Langhammer 2023-02-17 13:22:41 +01:00
parent e19c4886fe
commit 153bd3aaf1
No known key found for this signature in database
3 changed files with 23 additions and 5 deletions

View File

@ -43,7 +43,11 @@ class BaseOAuthClient:
try:
response.raise_for_status()
except RequestException as exc:
self.logger.warning("Unable to fetch user profile", exc=exc, body=response.text)
self.logger.warning(
"Unable to fetch user profile",
exc=exc,
response=exc.response.text if exc.response else str(exc),
)
return None
return response.json()

View File

@ -41,7 +41,11 @@ class OAuthClient(BaseOAuthClient):
)
response.raise_for_status()
except RequestException as exc:
LOGGER.warning("Unable to fetch access token", exc=exc)
LOGGER.warning(
"Unable to fetch access token",
exc=exc,
response=exc.response.text if exc.response else str(exc),
)
return None
return self.parse_raw_token(response.text)
return None
@ -61,7 +65,9 @@ class OAuthClient(BaseOAuthClient):
)
response.raise_for_status()
except RequestException as exc:
raise OAuthSourceException from exc
raise OAuthSourceException(
response=exc.response.text if exc.response else str(exc),
) from exc
return response.text
def get_redirect_args(self) -> dict[str, Any]:

View File

@ -84,7 +84,11 @@ class OAuth2Client(BaseOAuthClient):
)
response.raise_for_status()
except RequestException as exc:
LOGGER.warning("Unable to fetch access token", exc=exc)
LOGGER.warning(
"Unable to fetch access token",
exc=exc,
response=exc.response.text if exc.response else str(exc),
)
return None
return response.json()
@ -147,6 +151,10 @@ class UserprofileHeaderAuthClient(OAuth2Client):
try:
response.raise_for_status()
except RequestException as exc:
LOGGER.warning("Unable to fetch user profile", exc=exc, body=response.text)
LOGGER.warning(
"Unable to fetch user profile",
exc=exc,
response=exc.response.text if exc.response else str(exc),
)
return None
return response.json()