Skip to content

Commit

Permalink
fix: Always fetch emails when QUERY_EMAILS is set
Browse files Browse the repository at this point in the history
  • Loading branch information
mecampbellsoup committed Aug 16, 2024
1 parent d6e07b2 commit aef1128
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
7 changes: 4 additions & 3 deletions allauth/socialaccount/providers/bitbucket_oauth2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ def complete_login(self, request, app, token, **kwargs):
.get(self.profile_url, params={"access_token": token.token})
)
extra_data = resp.json()
if app_settings.QUERY_EMAIL and not extra_data.get("email"):
extra_data["email"] = self.get_email(token)
if app_settings.QUERY_EMAIL:
if email := self.get_email(token):
extra_data["email"] = email
return self.get_provider().sociallogin_from_response(request, extra_data)

def get_email(self, token):
def get_email(self, token) -> str:
"""Fetches email address from email API endpoint"""
resp = (
get_adapter()
Expand Down
7 changes: 3 additions & 4 deletions allauth/socialaccount/providers/github/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ def complete_login(self, request, app, token, **kwargs):
)
resp.raise_for_status()
extra_data = resp.json()
if app_settings.QUERY_EMAIL and not extra_data.get("email"):
emails = self.get_emails(headers)
if emails:
if app_settings.QUERY_EMAIL:
if emails := self.get_emails(headers):
extra_data["emails"] = emails
return self.get_provider().sociallogin_from_response(request, extra_data)

def get_emails(self, headers):
def get_emails(self, headers) -> list | None:
resp = (
get_adapter().get_requests_session().get(self.emails_url, headers=headers)
)
Expand Down

0 comments on commit aef1128

Please sign in to comment.