Skip to content

Commit

Permalink
fix(socialaccount): GitHub/BB: Always fetch emails when QUERY_EMAILS …
Browse files Browse the repository at this point in the history
…is set
  • Loading branch information
mecampbellsoup authored Aug 16, 2024
1 parent eb15165 commit e78a188
Show file tree
Hide file tree
Showing 2 changed files with 9 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
9 changes: 5 additions & 4 deletions allauth/socialaccount/providers/github/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from allauth.socialaccount import app_settings
from allauth.socialaccount.adapter import get_adapter
from allauth.socialaccount.providers.oauth2.views import (
Expand Down Expand Up @@ -30,13 +32,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) -> Optional[list]:
resp = (
get_adapter().get_requests_session().get(self.emails_url, headers=headers)
)
Expand Down

0 comments on commit e78a188

Please sign in to comment.