All projects
Project case study
JWT Authentication Service
A FastAPI authentication service with bcrypt password hashing, OAuth2 password login, expiring HS256 JWTs, and protected profile and user-management routes.
FastAPISQLAlchemySQLiteOAuth2JWTbcrypt
Open source repositoryThe problem
Authenticate users with passwords and use bearer tokens to protect profile and user-management routes.
Request flow
- 01OAuth2 password form
- 02bcrypt password verification
- 03signed HS256 access token
- 04bearer-protected route
Example route: POST /token
Implementation decisions
- Store bcrypt password hashes rather than plaintext passwords.
- Use email as the JWT subject and set a 30-minute token expiry.
- Use active-user checks on protected endpoints and response schemas that omit password hashes.
Validation and failure handling
- Reject duplicate registrations and invalid credentials.
- Block self-deletion in user management.