Stormbase / django-otp-webauthn

Passkey support for Django. Currently in early stages of development and not ready for production use!
BSD 3-Clause "New" or "Revised" License
10 stars 2 forks source link

How to set device name #16

Closed nijel closed 1 month ago

nijel commented 1 month ago

Users might want to register more webauthn devices to authenticate. At this point, it is useful to name them so that it is possible to manage them reasonably.

What would be a recommended approach to storing user defined name in the WebAuthnCredential model? The field is already there (inherited from the Device model), so it just needs a way to pass from the user to the database.

Stormheg commented 1 month ago

Hi @nijel 👋

While not (yet) explicitly documented anywhere, I consider a UI to manage devices (and by extension, rename devices) out-of-scope for this package.

It is up to the implementer to implement an interface to manage and rename credentials.

As a practical example, if you want to redirect your user to a form to name their Passkey right after they've registered it, you can listen for the otp_webauthn.register_complete JavaScript event on the page. An example implementation can be found in wagtail-mfa: https://github.com/Stormbase/wagtail-mfa/blob/main/client/src/wagtail_mfa.ts, the JS in this implementation fills the returned device id a hidden form and submits that. The view then redirects to a custom edit view.

Hope this answers your question. Going to close this now as not planned, but feel free to continue asking questions here.

nijel commented 1 month ago

Thanks, this indeed works. It makes things a bit more complicated for us because it creates the device without a name and then changes its name. As we log this operation in the audit log, the device creation is without a name. So far, I've workarounded this by delaying maturing the audit log entry, but having a way to pass this in the single request would be nicer.