Pythonic WebAuthn
Project description
py_webauthn
A Python3 implementation of the WebAuthn API focused on making it easy to leverage the power of WebAuthn.
This library supports all FIDO2-compliant authenticators, including security keys, Touch ID, Face ID, Windows Hello, Android biometrics...and pretty much everything else.
Installation
This module is available on PyPI:
pip install webauthn
Requirements
- Python 3.8 and up
Usage
The library exposes just a few core methods on the root webauthn
module:
generate_registration_options()
verify_registration_response()
generate_authentication_options()
verify_authentication_response()
Two additional helper methods are also exposed:
options_to_json()
base64url_to_bytes()
Additional data structures are available on webauthn.helpers.structs
. These Pydantic-powered dataclasses are useful for constructing inputs to the methods above, and for providing type hinting to help ensure consistency in the shape of data being passed around.
Generally, the library makes the following assumptions about how a Relying Party implementing this library will interface with a webpage that will handle calling the WebAuthn API:
- JSON is the preferred data type for transmitting registration and authentication options from the server to the webpage to feed to
navigator.credentials.create()
andnavigator.credentials.get()
respectively. - JSON is the preferred data type for transmitting WebAuthn responses from the browser to the server.
- Bytes are not directly transmittable in either direction as JSON, and so should be encoded to and decoded from base64url to avoid introducing any more dependencies than those that are specified in the WebAuthn spec.
- See the
WebAuthnBaseModel
struct for more information on how this is achieved
- See the
The examples mentioned below include uses of the options_to_json()
helper (see above) to show how easily bytes
values in registration and authentication options can be encoded to base64url for transmission to the front end.
The examples also include demonstrations of how to pass JSON-ified responses, using base64url encoding for ArrayBuffer
values, into RegistrationCredential.parse_raw()
and AuthenticationCredential.parse_raw()
to be automatically parsed by the methods in this library. An RP can pair this with corresponding custom front end logic, or one of several frontend-specific libraries (like @simplewebauthn/browser, for example) to handle encoding and decoding such values to and from JSON.
Other arguments into this library's methods that are defined as bytes
are intended to be values stored entirely on the server. Such values can more easily exist as bytes
without needing potentially extraneous encoding and decoding into other formats. Any encoding or decoding of such values in the name of storing them between steps in a WebAuthn ceremony is left up to the RP to achieve in an implementation-specific manner.
Registration
See examples/registration.py for practical examples of using generate_registration_options()
and verify_registration_response()
.
You can also run these examples with the following:
# See "Development" below for venv setup instructions
venv $> python -m examples.registration
Authentication
See examples/authentication.py for practical examples of using generate_authentication_options()
and verify_authentication_response()
.
You can also run these examples with the following:
# See "Development" below for venv setup instructions
venv $> python -m examples.authentication
Development
Installation
Set up a virtual environment, and then install the project's requirements:
$> python3 -m venv venv
$> source venv/bin/activate
venv $> pip install -r requirements.txt
Testing
Python's unittest module can be used to execute everything in the tests/ directory:
venv $> python -m unittest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file webauthn-1.7.2.tar.gz
.
File metadata
- Download URL: webauthn-1.7.2.tar.gz
- Upload date:
- Size: 46.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4821ce47d9870a94bb55c23002c4e1969fb1c08ad35e878f4b8cec71e507a1d |
|
MD5 | d3a933c21fb77705ab395f3ebadbf9db |
|
BLAKE2b-256 | aafabb675366244daadbd2f14731efab9469b5a19fd8158407cabf456de51ff8 |
File details
Details for the file webauthn-1.7.2-py3-none-any.whl
.
File metadata
- Download URL: webauthn-1.7.2-py3-none-any.whl
- Upload date:
- Size: 59.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4153dd245dcc44f948f2543a726cbc852353d7c5bc04e7e35c6e05dc744b9a11 |
|
MD5 | e633634f9a897cf89fcc5996f7f9619f |
|
BLAKE2b-256 | b54b4d1c872a745c4cb46b3625d7560561d4a971a4a9775cf8dc20b6e8173a7e |