My app is a Flask-based web application that implements passkeys authentication using FIDO2 WebAuthn. It demonstrates registration and authentication flow using passkeys, storing user credentials in a PostgreSQL database. After signing in with a passkey, each user can store a private message that only they can see.
The app used to run on my own domain (supej.me), on an ARM Hetzner cloud server with its own PostgreSQL database. That deployment is no longer live.
Tested with Python 3.13.9 and the versions pinned in requirements.txt.
- Create a virtual environment with Python 3.13 and run
pip install -r requirements.txt. - Copy
.env.exampleto.envand fill in the environment variables:APP_SECRET_KEY,DB_URI,DB_HOST,DB_NAME,DB_USER,DB_PASSWORD,RP_ID(uselocalhostfor local runs) andRP_NAME.DB_URImust use thepostgresql+psycopg2://scheme, for examplepostgresql+psycopg2://passkeys:change-me@localhost:5432/passkeys. - Create a PostgreSQL database and run
python init_db.py. - Start the app with
python app.pyand openhttp://localhost:5000, nothttp://127.0.0.1:5000. WebAuthn does not accept an IP address as the RP ID, and the fido2 library only allows plainhttponlocalhost.
Passkeys are bound to a domain (the Relying Party ID), so RP_ID must match the host you open the app on. Browsers allow WebAuthn on localhost without HTTPS; any other domain needs HTTPS.
On macOS, AirPlay Receiver also listens on port 5000 and answers http://localhost:5000 with a 403. Turn it off in System Settings > General > AirDrop & Handoff before starting the app.
| Route | Method | Description |
|---|---|---|
/ |
GET | Renders index.html |
/register |
GET | Renders register.html |
/login |
GET | Renders login.html |
/secret |
GET | Renders secret.html |
/logout |
GET | Logs out the user |
| Route | Method | Description |
|---|---|---|
/register/begin |
POST | Initiates user registration |
/register/complete |
POST | Completes registration with passkey |
/login/begin |
POST | Initiates authentication |
/login/complete |
POST | Completes authentication |
/current_user_string |
GET | Returns stored string for logged-in user |
/check_login |
GET | Checks if user is logged in |
Run the app locally (see Running locally) and open http://localhost:5000.
- Navigate to
/register - Enter a username and secret to store.
- Follow the passkey registration flow.
- Navigate to
/login - Enter your username.
- Authenticate using your passkey.