From 38aa828eb87e650cf1df468da3a35261eb52d6c7 Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 11 Oct 2023 17:48:58 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20passkey=20=E5=8F=AA=E5=85=81=E8=AE=B8?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E7=94=A8=E6=88=B7=E5=BC=80=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/backends/passkey/api.py | 2 ++ apps/authentication/backends/passkey/backends.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/apps/authentication/backends/passkey/api.py b/apps/authentication/backends/passkey/api.py index 8f5414122..644636dd2 100644 --- a/apps/authentication/backends/passkey/api.py +++ b/apps/authentication/backends/passkey/api.py @@ -22,6 +22,8 @@ class PasskeyViewSet(AuthMixin, FlashMessageMixin, ModelViewSet): @action(methods=['get', 'post'], detail=False, url_path='register') def register(self, request): + if request.user.source != 'local': + return JsonResponse({'error': _('Only register passkey for local user')}, status=400) if request.method == 'GET': register_data, state = register_begin(request) return JsonResponse(dict(register_data)) diff --git a/apps/authentication/backends/passkey/backends.py b/apps/authentication/backends/passkey/backends.py index dc7e1349b..4be1687d2 100644 --- a/apps/authentication/backends/passkey/backends.py +++ b/apps/authentication/backends/passkey/backends.py @@ -7,3 +7,6 @@ class PasskeyAuthBackend(JMSModelBackend): @staticmethod def is_enabled(): return settings.AUTH_PASSKEY + + def user_can_authenticate(self, user): + return user.source == 'local'