fastapi-passkeys
Passkeys / WebAuthn authentication for FastAPI — phishing-resistant passwordless login with cloned-authenticator detection, single-use challenges, and strict origin checks, without locking into a specific auth library or ORM.
If this project helps you, please ⭐ star the repo — it really helps others find it.
·
Table of contents
- Status
- Why
- Install
- Quickstart
- Endpoints
- Run the demo with Docker
- Storage backends
- Security
- Documentation
- Roadmap
- Contributing
- Support the project
- License
Status
0.2.0 — Alpha. Full registration + authentication ceremonies, clone
detection, SQLAlchemy/Redis adapters, and WebAuthn Level 3 features (hints,
Signal API, related origins). 0.2.0 is a security-hardening release — see the
audit report. The public
API may change before 1.0. See CHANGELOG.md and the
roadmap.
Why
Passwords are a liability and WebAuthn is easy to get subtly wrong — dropped
signature counters, replayable challenges, missing origin checks.
fastapi-passkeys owns the hard, security-sensitive part and stays out of the
way of your idea of a session:
- Secure by default — single-use, TTL-bound challenges; strict origin/RP
validation checked at startup; registration bound to the signed-in user;
userHandleownership and backup-flag checks; and monotonicsign_countcloned-authenticator detection (the prior Django solution stores no counter). - Auth-agnostic — it verifies the passkey and hands you the user; you mint
whatever session or JWT you like via an
on_authenticatedhook. - Storage-abstracted — credentials live behind an async
CredentialRepositoryprotocol (in-memory, stateless, SQLAlchemy 2.0, and Redis adapters included), with a shipped contract test-suite for your own. - Async-native and fully typed (
mypy --strict,py.typed).
Install
pip install fastapi-passkeys
# optional extras:
pip install "fastapi-passkeys[sqlalchemy]" # SQLAlchemy 2.0 async credential repo
pip install "fastapi-passkeys[redis]" # Redis challenge store (atomic single-use)
Quickstart
from fastapi import FastAPI, Request
from fastapi_passkeys import (
AuthenticationResult,
Passkeys,
PasskeyConfig,
PasskeyUser,
)
from fastapi_passkeys.contrib import InMemoryCredentialRepository
async def get_user(request: Request) -> PasskeyUser:
# Return the *authenticated* user — from your session or a verified sign-up
# token. Never trust an email/user id sent by the client: whoever this
# returns is who the new passkey is attached to.
account = await current_account(request) # your auth; raise HTTPException(401) if none
return PasskeyUser(
id=account.passkey_id, # opaque, stable, 1-64 bytes (e.g. a UUID) — not an email
name=account.email, # shown in the passkey picker
display_name=account.full_name,
)
async def on_authenticated(request: Request, result: AuthenticationResult) -> dict:
# The passkey is verified — now mint *your* session or token.
return {"access_token": issue_token(result.user_id)}
passkeys = Passkeys(
config=PasskeyConfig(
rp_id="example.com",
rp_name="Example",
expected_origins=["https://example.com"],
),
credential_repository=InMemoryCredentialRepository(),
get_user=get_user,
on_authenticated=on_authenticated,
)
app = FastAPI()
app.include_router(passkeys.router, prefix="/auth/passkeys", tags=["passkeys"])
passkeys.install_exception_handlers(app)
Each ceremony is a begin → finish pair: begin returns the options your
frontend passes to navigator.credentials.create() / .get() plus an opaque
state handle; echo that state back to finish with the authenticator's
response. No server session is required between the calls. A full, runnable
browser demo lives in examples/app.py.
Need full control? Skip the router and drive passkeys.registration /
passkeys.authentication (the services) from your own endpoints.
Endpoints
| Method | Path | Purpose |
|---|---|---|
POST |
/register/begin |
Start registration; returns creation options + state |
POST |
/register/finish |
Verify attestation and store the credential |
POST |
/authenticate/begin |
Start authentication (usernameless or with userId) |
POST |
/authenticate/finish |
Verify assertion; runs your on_authenticated hook |
GET |
/credentials |
List the current user's passkeys |
GET |
/credentials/signals |
WebAuthn Signal API payloads for the current user |
PATCH |
/credentials/{id} |
Rename a passkey (404 if not yours) |
DELETE |
/credentials/{id} |
Revoke a passkey (404 if not yours) |
passkeys.well_known_router (mounted without a prefix) serves
/.well-known/webauthn when related_origins is configured.
get_userdecides whose account a passkey is attached to. Resolve it from your session — never from an id the client sends.
Run the demo with Docker
docker run --rm -p 8000:8000 ghcr.io/javlondevv/fastapi-passkeys
Then open http://localhost:8000 and register / sign in with a real authenticator.
This runs examples/app.py with in-memory storage, so data
resets on restart. Keep host port 8000: the demo's origin is http://localhost:8000.
Storage backends
| Backend | Import | Extra |
|---|---|---|
| In-memory credentials | fastapi_passkeys.contrib.InMemoryCredentialRepository |
— |
| In-memory challenges | fastapi_passkeys.contrib.InMemoryChallengeStore |
— |
| Stateless challenges | fastapi_passkeys.contrib.StatelessChallengeStore |
— |
| SQLAlchemy credentials | fastapi_passkeys.contrib.sqlalchemy.SqlAlchemyCredentialRepository |
[sqlalchemy] |
| Redis challenges | fastapi_passkeys.contrib.redis.RedisChallengeStore |
[redis] |
Implement the CredentialRepository / ChallengeStore protocols for any other
store (SQLModel, Tortoise, Beanie, …) and validate it with the shipped contract
suite in fastapi_passkeys.testing.
Security
- Challenges are CSPRNG-generated, bound to user + ceremony, TTL-enforced server-side, and single-use (in-memory and Redis stores; per-process for the stateless store).
- Registration is bound to the user who started it; assertions must come
from the credential's owner (
userHandle), with BE/BS flag validation. - Clone detection stores and enforces the signature counter, with
strict-reject,flag-disable, oraudit-onlypolicies — all audited. - Origins & RP ID are normalized and validated at startup; multiple origins, Android app origins, and related origins are supported.
- No secrets are logged — audit events carry identifiers and outcomes only.
See the security model
for the full picture, including the stateless-store tradeoff. Report
vulnerabilities privately via SECURITY.md.
Documentation
Full docs: https://javlondevv.github.io/fastapi-passkeys/
- Quickstart
- Concepts — a short WebAuthn primer
- Configuration
- Storage backends
- Security model
- Migrating from django-passkeys
Roadmap
- 0.1 — core ceremonies, clone detection, router + services, in-memory / stateless / SQLAlchemy / Redis adapters, contract suite, docs site.
- 0.2 — security hardening from a full audit, WebAuthn L3 hints / Signal API / related origins, credential limits, conditional-UI example, rate-limiting and deployment guidance.
- 0.3 — soft-disable credentials (with migrations), per-user random user handles, optional FIDO MDS3 attestation + authenticator names, SQLModel / Tortoise / Beanie adapters.
- 1.0 — API freeze + semver guarantee.
Contributing
Contributions are very welcome! See CONTRIBUTING.md for the
dev setup and checks. Good entry points are the issues labelled
good first issue
and help wanted.
Please also read our Code of Conduct.
Support the project
The simplest way to help is a ⭐ star — it boosts visibility for everyone.
Embed a live star button on your own site or docs with GitHub Buttons:
<!-- Place once, before </body> -->
<a class="github-button"
href="https://github.com/javlondevv/fastapi-passkeys"
data-icon="octicon-star"
data-size="large"
data-show-count="true"
aria-label="Star javlondevv/fastapi-passkeys on GitHub">Star</a>
<script async defer src="https://buttons.github.io/buttons.js"></script>
License
MIT — see LICENSE.
Metadata
Release files for fastapi-passkeys 0.2.0
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 |
|---|---|---|---|---|
| fastapi_passkeys-0.2.0.tar.gz | 73.9 kB | With provenance | Details for fastapi_passkeys-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_passkeys-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for fastapi_passkeys-0.2.0-py3-none-any.whl |
Total release size: 124.3 kB
Release files / fastapi_passkeys-0.2.0.tar.gz
| Download URL | fastapi_passkeys-0.2.0.tar.gz |
|---|---|
| Size | 73.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
386c5aff085aca105b120738ffa9e8fe3ce10ce2b55bc1cbf638716238f04b31
|
|
BLAKE2b-256 checksum How to use checksums |
3c40995eb37e30f5c60ba63816417edb9750de21887e62ac46a6c78c38bf90dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.
Transparency logRelease files / fastapi_passkeys-0.2.0-py3-none-any.whl
| Download URL | fastapi_passkeys-0.2.0-py3-none-any.whl |
|---|---|
| Size | 50.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
32d2259ba828dec68ab5e47399667bc3d6485476e173bce875d392483173f8fd
|
|
BLAKE2b-256 checksum How to use checksums |
8b7735b3d10b4174c3d392b8dbb3e022425a50c494c7570683af27b6f6320b3f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.
Transparency logSecurity for fastapi-passkeys 0.2.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for fastapi_passkeys-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.
Transparency logA 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.