Skip to content

Commit

Permalink
fix(headless): HEADLESS_ONLY + social connect + reauthentication
Browse files Browse the repository at this point in the history
  • Loading branch information
pennersr committed Oct 3, 2024
1 parent 1424154 commit 44ad94f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ChangeLog.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
65.1.0 (unreleased)
*******************

- ...
Fixes
-----

- When using ``HEADLESS_ONLY = True`` together with
``ACCOUNT_REAUTHENTICATION_REQUIRED = True``, you could run into a
``NoReverseMatch`` when connecting a social acount. Fixed.


65.0.2 (2024-09-27)
Expand Down
3 changes: 3 additions & 0 deletions allauth/headless/socialaccount/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from allauth import app_settings as allauth_settings
from allauth.core.exceptions import (
ImmediateHttpResponse,
ReauthenticationRequired,
SignupClosedException,
)
from allauth.core.internal import httpkit
Expand Down Expand Up @@ -61,6 +62,8 @@ def complete_login(request, sociallogin):
error = None
try:
flows.login.complete_login(request, sociallogin, raises=True)
except ReauthenticationRequired:
error = "reauthentication_required"
except SignupClosedException:
error = "signup_closed"
except PermissionDenied:
Expand Down
20 changes: 20 additions & 0 deletions allauth/headless/socialaccount/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,26 @@ def test_connect(user, auth_client, sociallogin_setup_state, headless_reverse, d
assert SocialAccount.objects.filter(user=user, provider="dummy", uid="123").exists()


def test_connect_reauthentication_required(
user, auth_client, sociallogin_setup_state, headless_reverse, db, settings
):
settings.ACCOUNT_REAUTHENTICATION_REQUIRED = True

state = sociallogin_setup_state(
auth_client, process="connect", next="/foo", headless=True
)
resp = auth_client.post(
reverse("dummy_authenticate") + f"?state={state}",
data={
"id": 123,
},
)
assert resp.status_code == 302
assert (
resp["location"] == "/foo?error=reauthentication_required&error_process=connect"
)


def test_connect_already_connected(
user, user_factory, auth_client, sociallogin_setup_state, headless_reverse, db
):
Expand Down

0 comments on commit 44ad94f

Please sign in to comment.