Customize helper class¶
The WebAuthn helper class acts as the bridge between views, models, and py_webauthn. You can customize it to customize the behavior of WebAuthn in your Django application. For example, if you add additional fields to the credential model, you may want to override the create_credential method to populate these fields.
To customize the WebAuthn helper class, follow these steps:
Start by subclassing
django_otp_webauthn.helpers.WebAuthnHelperand override its methods as needed to implement your custom logic. For example, you can override thecreate_credentialmethod by creating awebauthn_helpers.pyfile in your Django app:
from django_otp_webauthn.helpers import WebAuthnHelper
class CustomWebAuthnHelper(WebAuthnHelper):
def create_credential(self, *args, **kwargs):
# Override methods here
credential = super().create_credential(*args, **kwargs)
credential.my_custom_field = "my_custom_value"
# The caller is responsible for saving the credential
return credential
Replace the default helper class with your custom class by updating the
OTP_WEBAUTHN_HELPER_CLASSsetting in your Django settings file. Set it to the dotted path of your custom class:
OTP_WEBAUTHN_HELPER_CLASS = "<your-app>.webauthn_helpers.CustomWebAuthnHelper"
For further customization, modify the WebAuthn configuration options passed to the browser. For more information, see the reference docs on Helper.