Skip to content

Commit

Permalink
feat(google): update URLs
Browse files Browse the repository at this point in the history
URLs are updated to ones recommended by https://accounts.google.com/.well-known/openid-configuration currently.
  • Loading branch information
illia-v authored and pennersr committed Dec 23, 2022
1 parent 0bfc710 commit fe1d55c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions allauth/socialaccount/providers/google/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_auth_params(self, request, action):
return ret

def extract_uid(self, data):
return str(data["id"])
return data["sub"]

def extract_common_fields(self, data):
return dict(
Expand All @@ -51,7 +51,7 @@ def extract_common_fields(self, data):
def extract_email_addresses(self, data):
ret = []
email = data.get("email")
if email and data.get("verified_email"):
if email and data.get("email_verified"):
ret.append(EmailAddress(email=email, verified=True, primary=True))
return ret

Expand Down
26 changes: 13 additions & 13 deletions allauth/socialaccount/providers/google/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_mocked_response(
given_name="Raymond",
name="Raymond Penners",
email="raymond.penners@example.com",
verified_email=True,
email_verified=True,
):
return MockedResponse(
200,
Expand All @@ -46,15 +46,15 @@ def get_mocked_response(
"locale": "nl", "gender": "male",
"email": "%s",
"link": "https://plus.google.com/108204268033311374519",
"given_name": "%s", "id": "108204268033311374519",
"verified_email": %s }
"given_name": "%s", "sub": "108204268033311374519",
"email_verified": %s }
"""
% (
family_name,
name,
email,
given_name,
(repr(verified_email).lower()),
(repr(email_verified).lower()),
),
)

Expand Down Expand Up @@ -106,15 +106,15 @@ def test_username_based_on_email(self):
email=email,
given_name=first_name,
family_name=last_name,
verified_email=True,
email_verified=True,
)
)
user = User.objects.get(email=email)
self.assertEqual(user.username, "raymond.penners")

def test_email_verified(self):
test_email = "raymond.penners@example.com"
self.login(self.get_mocked_response(verified_email=True))
self.login(self.get_mocked_response(email_verified=True))
email_address = EmailAddress.objects.get(email=test_email, verified=True)
self.assertFalse(
EmailConfirmation.objects.filter(email_address__email=test_email).exists()
Expand All @@ -132,13 +132,13 @@ def on_signed_up(sender, request, user, **kwargs):
sent_signals.append(sender)

user_signed_up.connect(on_signed_up)
self.login(self.get_mocked_response(verified_email=True))
self.login(self.get_mocked_response(email_verified=True))
self.assertTrue(len(sent_signals) > 0)

@override_settings(ACCOUNT_EMAIL_CONFIRMATION_HMAC=False)
def test_email_unverified(self):
test_email = "raymond.penners@example.com"
resp = self.login(self.get_mocked_response(verified_email=False))
resp = self.login(self.get_mocked_response(email_verified=False))
email_address = EmailAddress.objects.get(email=test_email)
self.assertFalse(email_address.verified)
self.assertTrue(
Expand All @@ -161,7 +161,7 @@ def test_email_verified_stashed(self):
adapter.stash_verified_email(request, test_email)
request.session.save()

self.login(self.get_mocked_response(verified_email=False))
self.login(self.get_mocked_response(email_verified=False))
email_address = EmailAddress.objects.get(email=test_email)
self.assertTrue(email_address.verified)
self.assertFalse(
Expand All @@ -175,7 +175,7 @@ def test_account_connect(self):
user.save()
EmailAddress.objects.create(user=user, email=email, primary=True, verified=True)
self.client.login(username=user.username, password="test")
self.login(self.get_mocked_response(verified_email=True), process="connect")
self.login(self.get_mocked_response(email_verified=True), process="connect")
# Check if we connected...
self.assertTrue(
SocialAccount.objects.filter(user=user, provider=GoogleProvider.id).exists()
Expand All @@ -190,7 +190,7 @@ def test_account_connect(self):
)
def test_social_email_verification_skipped(self):
test_email = "raymond.penners@example.com"
self.login(self.get_mocked_response(verified_email=False))
self.login(self.get_mocked_response(email_verified=False))
email_address = EmailAddress.objects.get(email=test_email)
self.assertFalse(email_address.verified)
self.assertFalse(
Expand All @@ -202,9 +202,9 @@ def test_social_email_verification_skipped(self):
SOCIALACCOUNT_EMAIL_VERIFICATION=account_settings.EmailVerificationMethod.OPTIONAL,
)
def test_social_email_verification_optional(self):
self.login(self.get_mocked_response(verified_email=False))
self.login(self.get_mocked_response(email_verified=False))
self.assertEqual(len(mail.outbox), 1)
self.login(self.get_mocked_response(verified_email=False))
self.login(self.get_mocked_response(email_verified=False))
self.assertEqual(len(mail.outbox), 1)


Expand Down
6 changes: 3 additions & 3 deletions allauth/socialaccount/providers/google/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

class GoogleOAuth2Adapter(OAuth2Adapter):
provider_id = GoogleProvider.id
access_token_url = "https://accounts.google.com/o/oauth2/token"
authorize_url = "https://accounts.google.com/o/oauth2/auth"
profile_url = "https://www.googleapis.com/oauth2/v1/userinfo"
access_token_url = "https://oauth2.googleapis.com/token"
authorize_url = "https://accounts.google.com/o/oauth2/v2/auth"
profile_url = "https://openidconnect.googleapis.com/v1/userinfo"

def complete_login(self, request, app, token, **kwargs):
resp = requests.get(
Expand Down

0 comments on commit fe1d55c

Please sign in to comment.