This project demonstrates a FastAPI application with login functionality using passkey authentication.
-
Package Management & Environment:
- Uses Poetry for package management
- Environment variables set up in
.envfile - Async implementation throughout the application
-
Database:
- Uses SQLAlchemy for database access with SQLite for demo purposes
- Database migrations handled by Alembic
- Creates database tables on startup if they do not exist
- Migrates database to the latest version on startup
-
Authentication:
- Users can login using either:
- Email & password
- Passkey (WebAuthn)
- Users can login using either:
WebAuthn
-
POST /auth/webauthn/register/generate-options: Initiates the registration flow -
POST /auth/webauthn/register/verify: Verifies and completes new passkey registration -
GET /auth/webauthn/authenticate/generate-options: Initiates the authentication flow -
POST /auth/webauthn/authenticate/verify: Verifies and completes authentication with existing passkey
Auth
-
POST /auth/register, Register new user -
POST /auth/login, Login using email & password -
POST /auth/logout, Logout -
POST /auth/jwt/refresh, Refresh tokens
Password
-
POST /auth/password/forgot, Request reset password -
POST /auth/password/reset, Reset password using token -
GET /auth/password/reset/verify, Verify if reset token still valid -
POST /auth/password/change, Change password
Users
-
GET /users/me, Get current user information -
POST /users/me, Update current user information -
DELETE /users/me, Delete current user -
GET /users/{user_id}, Get a user information -
POST /users/{user_id}, Update a user information -
DELETE /users/{user_id}, Delete a user
Root
-
GET /health, Health check
-
Clone the repository:
git clone https://github.com/dennislwy/fastapi-passkey-auth.git cd fastapi-passkey-auth -
Install dependencies using Poetry:
poetry install
-
Set up environment variables:
- Copy
.env.exampleto.envand update the values as needed.
- Copy
-
Run database migrations:
alembic upgrade head
- Start the FastAPI application:
poetry run uvicorn app.main:app --reload- Navigate to link below - http://localhost:8000
To add a new database migration, follow these steps:
-
Make changes to your SQLAlchemy models in the
modelsdirectory. -
Generate a new migration script:
alembic revision --autogenerate -m "Description of the migration" -
Apply the migration:
alembic upgrade head
This project is licensed under the MIT License. See the LICENSE file for details.
