The `webauthn` library provides a Pythonic implementation for integrating WebAuthn (Web Authentication API) into web applications, enabling strong, phishing-resistant, and passwordless authentication. It handles the server-side verification and generation of WebAuthn credentials, abstracting away the complexities of the FIDO2 protocol. The library is actively maintained with a relatively frequent release cadence, with the current version being 2.7.1, and supports Python 3.9 and newer.
pip install webauthnVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to generate registration options, which is the first step in registering a new WebAuthn credential. It uses placeholder values for RP (Relying Party) and user details. In a real application, these would be dynamic and securely managed. The generated options are then sent to the client-side JavaScript for interaction with the user's authenticator.
Upgrade your Python environment to 3.9 or higher. For example, `pyenv install 3.9.18 && pyenv global 3.9.18`.
Install the optional dependency: `pip install 'webauthn[pqc]'` or `pip install dilithium-py`.
Review your serialization needs. If a custom encoding is required, pass a `Callable[[bytes], Any]` to the `bytes_encoder` argument when calling `options_to_json_dict`.
Update your code to use `Dict[str, Any]` or other specific `dict` type hints where appropriate when interacting with the library's types, or adjust your type checker's configuration if necessary.