Skip to main content

Pythonic WebAuthn

Project description

py_webauthn

PyPI GitHub license Pythonic WebAuthn

A Python3 implementation of the server-side 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.9 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 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:

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 parse_registration_credential_json and parse_authentication_credential_json 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

Auto-watching unittests can be achieved with a tool like nodemon.

All tests:

venv $> nodemon --exec "python -m unittest" --ext py

An individual test file:

venv $> nodemon --exec "python -m unittest tests/test_aaguid_to_string.py" --ext py

Linting and Formatting

Linting is handled via mypy:

venv $> python -m mypy webauthn
Success: no issues found in 52 source files

The entire library is formatted using black:

venv $> python -m black webauthn --line-length=99
All done!  🍰 52 files left unchanged.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

webauthn-2.7.0.tar.gz (123.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

webauthn-2.7.0-py3-none-any.whl (71.3 kB view details)

Uploaded Python 3

File details

Details for the file webauthn-2.7.0.tar.gz.

File metadata

  • Download URL: webauthn-2.7.0.tar.gz
  • Upload date:
  • Size: 123.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for webauthn-2.7.0.tar.gz
Algorithm Hash digest
SHA256 3c45c25e75a7d7d419220ccd10b8b899984de8012732e10d898f0a8f8c480575
MD5 c87b4a264911e6e0a97db11e3fbab237
BLAKE2b-256 a4f0e1036df8842782a2947e5f41e76a4accb92e3dba972dba882321ebe15af0

See more details on using hashes here.

File details

Details for the file webauthn-2.7.0-py3-none-any.whl.

File metadata

  • Download URL: webauthn-2.7.0-py3-none-any.whl
  • Upload date:
  • Size: 71.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for webauthn-2.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ecfee7959b09ebeaaffee9f8982ecdbbdc369a11766d20d4bc0637b36e235b7
MD5 c5826133f19bddedfdb663d7835a67e8
BLAKE2b-256 73b13f380d02552f1d75d3db789f761a1ee0dafd6181ebc07dd4b9ded61225a4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page