File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 19
19
path (
20
20
"decommission-form/" , views .remove_security_key_form , name = "decommission-form"
21
21
),
22
+ path ("update-security-key/" , views .update_security_key , name = "update-security-key" ),
22
23
]
Original file line number Diff line number Diff line change @@ -295,3 +295,34 @@ def remove_security_key_form(
295
295
remove_security_key (request , ** kwargs )
296
296
297
297
return redirect (reverse ("security-keys:manage-keys" ))
298
+
299
+
300
+ @login_required
301
+ @transaction .atomic
302
+ def update_security_key (request : WSGIRequest , ** kwargs : Any ) -> JsonResponse :
303
+ """
304
+ Update a security key's passkey login status.
305
+
306
+ This requires the following POST data:
307
+ - id (`int`): key id
308
+ - passkey_login (`bool`): whether to enable passkey login
309
+
310
+ Returns a JSON response with the updated key's details
311
+ """
312
+ id = request .POST .get ("id" )
313
+ passkey_login = convert_to_bool (request .POST .get ("passkey_login" , False ))
314
+
315
+ try :
316
+ sec_key = request .user .webauthn_security_keys .get (pk = id )
317
+ except SecurityKey .DoesNotExist :
318
+ return JsonResponse ({"non_field_errors" : [_ ("Key not found" )]}, status = 404 )
319
+
320
+ sec_key .passkey_login = passkey_login
321
+ sec_key .save ()
322
+
323
+ return JsonResponse ({
324
+ "status" : "ok" ,
325
+ "id" : sec_key .id ,
326
+ "name" : sec_key .name ,
327
+ "passkey_login" : sec_key .passkey_login
328
+ })
You can’t perform that action at this time.
0 commit comments