Python WebAuthN
Server side handlers for WebAuthN with support for Apple's FaceID, and the FIDO metadata service.
Demo
A small Flask app showcasing this library is provided in the demo folder.
Basic usage
Register a credential
Part 1: generate request to be sent to browser
# User the credential is to be registered to
user = webauthn.types.User(
id=b"test",
display_name="Test user",
name="test@example.com",
icon=None
)
# Who is requesting the credential
rp = webauthn.types.RelyingParty(
id="as207960-webauthn.eu.ngrok.io",
name="AS207960",
icon="https://as207960.net/assets/img/logo.svg"
)
data, challenge = webauthn.create_webauthn_credentials(
rp=rp, user=user, existing_keys=[],
attachment=None, require_resident=False,
user_verification=webauthn.types.UserVerification.Preferred,
attestation_request=webauthn.types.Attestation.DirectAttestation,
)
# Store the challenge and user for part 3
Part 2: Create credential through the browser
function b64decode(input) {
return Uint8Array.from(window.atob(input), c => c.charCodeAt(0));
}
function b64encode(input) {
return window.btoa(String.fromCharCode.apply(null, new Uint8Array(input)));
}
// Data having already been retrieved from the server
data.user.id = b64decode(data.user.id);
data.challenge = b64decode(data.challenge);
data.excludeCredentials = data.excludeCredentials.map(function (cred) {
cred.id = b64decode(cred.id);
return cred;
})
navigator.credentials.create({
publicKey: data
}).then(function (response) {
let data = {
id: b64encode(response.rawId),
response: {
data: b64encode(response.response.clientDataJSON),
attestation: b64encode(response.response.attestationObject),
}
}
// Send response data back to the server
});
Part 3: Complete registration on the server
# Response is the data from the browser as above
# This should be cached
fido_metadata = webauthn.metadata.get_metadata()
auth_data = webauthn.verify_create_webauthn_credentials(
rp=rp, challenge_b64=challenge,
client_data_b64=response["data"],
attestation_b64=response["attestation"],
fido_metadata=fido_metadata
)
The auth_data response can be inspected to decide if the authenticator is to be allowed by the server. Such rules are
outside the scope of this package.
Perform a login
Part 1: generate request to be sent to browser
options, challenge = webauthn.get_webauthn_credentials(
rp=rp,
existing_keys=[pkey_id],
user_verification=webauthn.types.UserVerification.Preferred,
)
# Store the challenge and user for part 3
Part 2: Sign challenge
// Data having already been retrieved from the server
data.challenge = b64decode(data.challenge);
data.allowCredentials = data.allowCredentials.map(function (cred) {
cred.id = b64decode(cred.id);
return cred;
})
return navigator.credentials.get({
publicKey: data
}).then(function (response) {
let data = {
response: {
data: b64encode(response.response.clientDataJSON),
authenticator: b64encode(response.response.authenticatorData),
signature: b64encode(response.response.signature),
user: b64encode(response.response.userHandle),
}
}
// Send response data back to the server
});
Part 3: Verify response on the server
# Response is the data from the browser as above
# This should be cached
fido_metadata = webauthn.metadata.get_metadata()
auth_data = webauthn.verify_create_webauthn_credentials(
rp=rp, challenge_b64=challenge,
client_data_b64=response["data"],
attestation_b64=response["attestation"],
fido_metadata=fido_metadata
)
Metadata
Release files for py-webauthn 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| py_webauthn-0.0.7.tar.gz | 13.4 kB | Without provenance | Details for py_webauthn-0.0.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py_webauthn-0.0.7-py3-none-any.whl | Python 3 | none | any | Details for py_webauthn-0.0.7-py3-none-any.whl |
Total release size: 28.8 kB
Release files / py_webauthn-0.0.7.tar.gz
| Download URL | py_webauthn-0.0.7.tar.gz |
|---|---|
| Size | 13.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3e7576c216d5904ac5dfe3dc456cb72eeb12ed73efd1b622da67e793092ac845
|
|
BLAKE2b-256 checksum How to use checksums |
763553f454e3c42b44aace07da3eae1187a22b9ce2332aa33d1ee07bcd345ce2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / py_webauthn-0.0.7-py3-none-any.whl
| Download URL | py_webauthn-0.0.7-py3-none-any.whl |
|---|---|
| Size | 15.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b06625a5600e4af456442afc71112728ee6b76eff7e7abb8e9d56a401f0f325c
|
|
BLAKE2b-256 checksum How to use checksums |
c10defbc7330d6f2fa29cf7fe7c67eb1a1facf2502959a86ad1bb8e629ba18c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Security for py-webauthn 0.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.