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

chore(oauth): show an informative log when OAuthError is raised #3184

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions allauth/socialaccount/providers/oauth/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ def _get_request_token(self):
response = requests.post(url=rt_url, auth=oauth)
if response.status_code not in [200, 201]:
raise OAuthError(
_("Invalid response while obtaining request token" ' from "%s".')
% get_token_prefix(self.request_token_url)
_("Invalid response while obtaining request token from " +
f"{get_token_prefix(self.request_token_url)}. " +
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: Using f-strings breaks the python 3.5 build.

f"Response text: {response.text}")
)
self.request_token = dict(parse_qsl(response.text))
self.request.session[
Expand Down
3 changes: 3 additions & 0 deletions allauth/socialaccount/providers/oauth/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import

import logging
from django.urls import reverse

from allauth.socialaccount import providers
Expand All @@ -18,6 +19,7 @@
OAuthError,
)

logger = logging.getLogger(__name__)

class OAuthAdapter(object):
def __init__(self, request):
Expand Down Expand Up @@ -76,6 +78,7 @@ def login(self, request, *args, **kwargs):
try:
return client.get_redirect(auth_url, auth_params)
except OAuthError as e:
logger.exception('Error processing OAuth')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: From a logging perspective, these errors can occur in production and don't necessarily indicate exceptional situations that need direct attention. Hence, I think we need to use the regular error level.

Suggested change
logger.exception('Error processing OAuth')
logger.error("OAuth authentication error", exc_info=True)

return render_authentication_error(
request, self.adapter.provider_id, exception=e
)
Expand Down