Skip to content

Commit 36789b4

Browse files
committed
Request user details sync after Passkey login and registration
1 parent 10881b3 commit 36789b4

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/django_otp_webauthn/views.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
from django_otp_webauthn import exceptions
2222
from django_otp_webauthn.models import AbstractWebAuthnCredential
2323
from django_otp_webauthn.settings import app_settings
24-
from django_otp_webauthn.utils import get_credential_model, rewrite_exceptions
24+
from django_otp_webauthn.utils import (
25+
get_credential_model,
26+
request_user_details_sync,
27+
rewrite_exceptions,
28+
)
2529

2630
WebAuthnCredential = get_credential_model()
2731
User = get_user_model()
@@ -153,6 +157,8 @@ def post(self, *args, **kwargs):
153157
# change that indicator.
154158
if not self.request.user.is_verified():
155159
otp_login(self.request, device)
160+
161+
request_user_details_sync(self.request)
156162
return Response(data={"id": device.pk}, content_type="application/json")
157163

158164

@@ -245,6 +251,7 @@ def complete_auth(self, device: AbstractWebAuthnCredential) -> AbstractBaseUser:
245251

246252
# Mark the user as having passed verification
247253
otp_login(self.request, device)
254+
request_user_details_sync(self.request)
248255

249256
success_url_allowed_hosts = set()
250257

tests/integration/test_views_authentication.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ def test_authentication_complete__anonymous_user_passwordless_login_allowed(
212212
assert (
213213
session["_auth_user_backend"] == "django_otp_webauthn.backends.WebAuthnBackend"
214214
)
215+
# Signaled that user details sync is needed
216+
assert session["otp_webauthn_sync_needed"] is True
215217

216218

217219
@pytest.mark.django_db
@@ -235,6 +237,8 @@ def test_authentication_complete__verify_existing_user(api_client, settings, use
235237
session = api_client.session
236238
assert "otp_webauthn_authentication_state" not in session
237239
assert session["otp_device_id"] == credential.persistent_id
240+
# Signaled that user details sync is needed
241+
assert session["otp_webauthn_sync_needed"] is True
238242

239243

240244
@pytest.mark.django_db
@@ -258,6 +262,8 @@ def test_authentication_complete_device_usable__unconfirmed(api_client, user):
258262
session = api_client.session
259263
assert "otp_webauthn_authentication_state" not in session
260264
assert "otp_device_id" not in session
265+
# No user details sync should be requested
266+
assert "otp_webauthn_sync_needed" not in session
261267

262268

263269
@pytest.mark.django_db
@@ -285,6 +291,8 @@ def test_authentication_complete_device_usable__user_disabled(
285291
session = api_client.session
286292
assert "otp_webauthn_authentication_state" not in session
287293
assert "otp_device_id" not in session
294+
# No user details sync should be requested
295+
assert "otp_webauthn_sync_needed" not in session
288296

289297

290298
@pytest.mark.django_db

tests/integration/test_views_registration.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ def test_registration_complete__valid_response_but_already_verified(
241241
assert cred.persistent_id != credential.persistent_id
242242
assert api_client.session["otp_device_id"] == credential.persistent_id
243243

244+
# Signaled that user details sync is needed
245+
assert api_client.session["otp_webauthn_sync_needed"] is True
246+
244247

245248
@pytest.mark.django_db
246249
def test_registration_complete__valid_response(api_client, user, credential_model):
@@ -279,3 +282,6 @@ def test_registration_complete__valid_response(api_client, user, credential_mode
279282

280283
# The user session wasn't 2FA verified before, so now it should be
281284
assert api_client.session["otp_device_id"] == cred.persistent_id
285+
286+
# Signaled that user details sync is needed
287+
assert api_client.session["otp_webauthn_sync_needed"] is True

0 commit comments

Comments
 (0)