Skip to main content

WebAuthin'

About

WebAuthin' is a Django library for secure, passwordless logins using WebAuthn/FIDO2.

It allows users to associate secure keys (from USB keys like Yubikeys, Titan keys, etc to platform authenticators like macOS TouchID, Windows Hello, and Android biometrics) with your website and log in just by plugging the key in. This means they don't need to remember a username/password, there are no credentials to steal, and they don't need a second factor.

WebAuthin' requires user verification, which means that the user will need to enter a PIN, fingerprint, or some other method of verification locally, to prevent theft of the physical key from allowing logins.

WebAuthn is supported on all major browsers.

PyPI version

Installing django-webauthin

  • First of all, make sure that your site uses the Sites framework properly, as that is what WebAuthin' uses to get your site name and domain.

  • Install django-webauthin using pip: pip install django-webauthin

  • Add webauthin to your INSTALLED_APPS:

# settings.py
INSTALLED_APPS = [... "webauthin", ...]
  • Add webauthin to your authentication backends:
AUTHENTICATION_BACKENDS = (
    "webauthin.auth_backends.WebAuthinBackend",
    "django.contrib.auth.backends.ModelBackend",
)
  • Add the webauthin URL to your urls.py:
# urls.py
urlpatterns += path("auth/", include("webauthin.urls", namespace="webauthin"))
  • You now need two buttons, one for registration and one for login. The registration button should have an ID of webauthin-register. You also need to include a template that will insert the JS code somewhere:
{% include "webauthin_register.html" %}
<button id="webauthin-register">Register new key</button>

Pressing this button will trigger the key registration flow.

  • Add the login button to your login form, as above, this time with an ID of webauthin-login:
{% include "webauthin_login.html" %}
<button id="webauthin-login">Log in using hardware key</button>
  • You can also add a table to allow the user to see and delete their registered keys, though this process is currently somewhat manual:
{% for key in request.user.authdata_set.all %}
<p>
    {{ key.name }}: Created on {{ key.created_on }} and last used on
    {{ key.last_used_on }}.

    <form
        method="POST"
        action="{% url "webauthin:delete-key" %}"
        onsubmit="return confirm('Are you sure you want to delete this key?');"
    >{% csrf_token %}
        <input type="hidden" name="key_id" value="{{ key.id }}" />
        <button type="submit">Delete</button>
    </form>
</p>
{% endfor %}

You can similarly change the key name by POSTing to webauthin:rename-key with a parameter called name.

Do note that you need to have the Django messages framework installed so the library can show the user error/success messages.

Settings

Here are the settings you can change in your settings.py:

  • WEBAUTHIN_LOGIN_REDIRECT_URL (default: LOGIN_REDIRECT_URL): Where to redirect after a successful login.
  • WEBAUTHIN_LOGIN_ERROR_URL (default: LOGIN_URL): Where to redirect after a login error.
  • WEBAUTHIN_REGISTRATION_REDIRECT_URL (default: LOGIN_REDIRECT_URL): Where to redirect after a successful key registration.
  • WEBAUTHIN_REGISTRATION_ERROR_URL (default: LOGIN_REDIRECT_URL): Where to redirect after a key registration error.

Running tests

To run the test suite (requires uv):

./runtests.py

Demo

You can see a demo of the flow by visiting Pastery. Create an account by logging in with your email address, go to your account to register your key, then log out and log back in with your key.

Metadata

Release files for django-webauthin 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-webauthin 0.0.8
File Size Uploaded
django_webauthin-0.0.8.tar.gz 11.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-webauthin 0.0.8
File Interpreter ABI Platform
django_webauthin-0.0.8-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 29.2 kB

Release files / django_webauthin-0.0.8.tar.gz

Download URL django_webauthin-0.0.8.tar.gz
Size 11.9 kB
Tags Source
SHA-256 checksum
How to use checksums
bbd2ec3451f6493a694924ec0134cdc2acb126a5a60c08be83a5488d0c0b0f63
BLAKE2b-256 checksum
How to use checksums
30be4bf0ee3f5197103f67d0600debf1d22c2b0f80a2667a352321a26926b91d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Release files / django_webauthin-0.0.8-py2.py3-none-any.whl

Download URL django_webauthin-0.0.8-py2.py3-none-any.whl
Size 17.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
ab23596b07c22aefcfaff5ab6a998000908b5773e4474b4181f7aa071a25e98b
BLAKE2b-256 checksum
How to use checksums
6ee0c6299d42a4615db60c5432c05aa2afa2e6ed00a697397ba6054e0b4e463b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

0.0.8 This release

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

3 release files

0.0.1

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page