This is a template for a FastAPI application with JWT authentication. It uses PostgreSQL for the database and Redis for blacklisting refresh tokens. The project is containerized using Docker.
- Secure JWT-based user authentication with bcrypt hashing for passwords
- API endpoints for login, logout, and token refresh, with expiration handling
- Blacklisting refresh tokens in Redis for enhanced security
- Creating a user with password validation
- Login User
- POST
/api/v1/auth/jwt/login - Description: Authenticates a user and returns an access token and refresh token.
- POST
- Refresh Token
- POST
/api/v1/auth/jwt/refresh - Description: Refreshes the user's JWT access token using the provided refresh token.
- POST
- Logout User
- POST
/api/v1/auth/jwt/logout - Description: Logs out the user by blocking the refresh token.
- POST
- Create User
- POST
/api/v1/users - Description: Creates a new user in the system.
- POST
- Get Current User
- GET
/api/v1/users/me - Description: Retrieves the details of the currently authenticated user.
- GET
Make sure Docker is installed and running on your system. You can download it from here.
-
Clone the repository
git clone https://github.com/steqa/fast-jwtemplate.git project-folder
-
Update the
.envfileRename
.env.exampleto.envand update with your configuration -
Build and start the Docker containers
cd project-folderdocker compose -f docker/docker-compose.yml --env-file .env up --build
- The API will be available at http://localhost:8000
- You can interact with the API using Swagger UI at http://localhost:8000/docs
This project is licensed under the MIT License. See the LICENSE file for more details.