Package: webauthn
py_webauthnA Python3 implementation of the server-side of theWebAuthn APIfocused 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.InstallationThis module is available onPyPI:pip install webauthnRequirementsPython 3.8 and upUsageThe library exposes just a few core methods on the rootwebauthnmodule: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 onwebauthn.helpers.structs. ThesePydantic-powereddataclasses 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 tonavigator.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 frombase64url to avoid introducing any more dependencies than those that are specified in the WebAuthn spec.See theWebAuthnBaseModelstructfor more information on how this is achievedThe examples mentioned below include uses of theoptions_to_json()helper (see above) to show how easilybytesvalues 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 forArrayBuffervalues, intoparse_registration_credential_jsonandparse_authentication_credential_jsonto 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 asbytesare intended to be values stored entirely on the server. Such values can more easily exist asbyteswithout 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.RegistrationSeeexamples/registration.pyfor practical examples of usinggenerate_registration_options()andverify_registration_response().You can also run these examples with the following:# See "Development" below for venv setup instructionsvenv$>python-mexamples.registrationAuthenticationSeeexamples/authentication.pyfor practical examples of usinggenerate_authentication_options()andverify_authentication_response().You can also run these examples with the following:# See "Development" below for venv setup instructionsvenv$>python-mexamples.authenticationDevelopmentInstallationSet up a virtual environment, and then install the project's requirements:$>python3-mvenvvenv
$>sourcevenv/bin/activate
venv$>pipinstall-rrequirements.txtTestingPython's unittest module can be used to execute everything in thetests/directory:venv$>python-munittest