-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(socialaccount): Facebook Limited Login
Squashed commit of the following: commit b70b8ab8bc10be4341af3d3479f26a3324da6914 Author: Raymond Penners <[email protected]> Date: Tue Oct 22 20:22:21 2024 +0200 tests(socialaccount): Facebook limited login commit e165bb1ca3ba20005cdead1092b8245cfaa9b885 Author: Andre Borie <[email protected]> Date: Sun Oct 20 19:46:37 2024 +0200 chore(facebook): remove more type hints. commit 271eb4fd1a854a519128a60a8e25760e7be663a2 Author: Andre Borie <[email protected]> Date: Sun Oct 20 19:37:08 2024 +0200 lint: fix isort. commit 8f7c4942982c5e2e1e9e7436ebc7cc6488085198 Author: Andre Borie <[email protected]> Date: Sun Oct 20 19:36:19 2024 +0200 chore(facebook): remove faulty type hint. commit 265853c7bded414b984a5baee085c6105534488d Author: Andre Borie <[email protected]> Date: Sun Oct 20 19:34:49 2024 +0200 lint: fix linting commit ba663d3c7f3e94afd6dc3ace1c669e7f89152211 Author: Andre Borie <[email protected]> Date: Sun Oct 20 19:09:44 2024 +0200 chore(facebook): PR feedback, skip (redundant) JWT replay attack protection, fix super() call with proper verify_token call. commit df30314747564715b57f09960b89b884fa2efc48 Author: Andre Borie <[email protected]> Date: Sun Oct 20 18:12:54 2024 +0200 docs(facebook): update docs. commit 0ace116ffeeb2ae0d473449c34e2652a7c1cbb3e Author: Andre Borie <[email protected]> Date: Sun Oct 20 18:05:25 2024 +0200 docs(changelog): update changelog. commit 43de00922f5479f4d52574b01962ccce463817bc Author: Andre Borie <[email protected]> Date: Sun Oct 20 18:01:22 2024 +0200 feat(facebook): implement support for Facebook Limited Login.
- Loading branch information
Showing
6 changed files
with
142 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
from contextlib import contextmanager | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from allauth.account.models import EmailAddress | ||
|
@@ -33,3 +36,31 @@ def factory( | |
return sociallogin | ||
|
||
return factory | ||
|
||
|
||
@pytest.fixture | ||
def jwt_decode_bypass(): | ||
@contextmanager | ||
def f(jwt_data): | ||
with patch("allauth.socialaccount.internal.jwtkit.verify_and_decode") as m: | ||
data = { | ||
"iss": "https://accounts.google.com", | ||
"aud": "client_id", | ||
"sub": "123sub", | ||
"hd": "example.com", | ||
"email": "[email protected]", | ||
"email_verified": True, | ||
"at_hash": "HK6E_P6Dh8Y93mRNtsDB1Q", | ||
"name": "Raymond Penners", | ||
"picture": "https://lh5.googleusercontent.com/photo.jpg", | ||
"given_name": "Raymond", | ||
"family_name": "Penners", | ||
"locale": "en", | ||
"iat": 123, | ||
"exp": 456, | ||
} | ||
data.update(jwt_data) | ||
m.return_value = data | ||
yield | ||
|
||
return f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
from allauth.account import app_settings as account_settings | ||
from allauth.account.models import EmailAddress | ||
from allauth.socialaccount.adapter import get_adapter | ||
from allauth.socialaccount.models import SocialAccount | ||
from allauth.socialaccount.tests import OAuth2TestsMixin | ||
from allauth.tests import MockedResponse, TestCase, mocked_response | ||
|
@@ -163,3 +164,28 @@ def test_login_unverified(self): | |
def _login_verified(self): | ||
self.login(self.get_mocked_response()) | ||
return EmailAddress.objects.get(email="[email protected]") | ||
|
||
|
||
def test_limited_token(rf, db, settings, jwt_decode_bypass): | ||
settings.SOCIALACCOUNT_PROVIDERS = { | ||
"facebook": { | ||
"AUTH_PARAMS": {}, | ||
"VERIFIED_EMAIL": False, | ||
"APPS": [{"client_id": "123"}], | ||
} | ||
} | ||
request = rf.get("/") | ||
adapter = get_adapter(request) | ||
provider = adapter.get_provider(request, FacebookProvider.id) | ||
token = {"id_token": "X"} | ||
with jwt_decode_bypass( | ||
{ | ||
"sub": "f123", | ||
"email": "[email protected]", | ||
"given_name": "John", | ||
"family_name": "Doe", | ||
} | ||
): | ||
login = provider.verify_token(request, token) | ||
assert login.account.uid == "f123" | ||
assert login.email_addresses[0].email == "[email protected]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters