A centralized JWT authentication service built with FastAPI. It can be used as a standalone auth backend for multiple projects or dashboards. The JWT validator module is reusable, so other projects can import it to protect their own endpoints.
- JWT Authentication — Access tokens (short-lived) and refresh tokens (long-lived)
- Secure Password Hashing — Uses Argon2, a modern and strong hashing algorithm
- Refresh Token Rotation — A new refresh token is issued on every refresh
- HttpOnly Cookies — Refresh tokens are stored in secure, httpOnly cookies to protect against XSS
- Rate Limiting — Login endpoint is protected against brute-force attacks (5 requests/minute)
- Reusable Validator —
shared_authmodule can be imported by other projects - Docker Ready — Comes with Dockerfile and Docker Compose setup
- FastAPI — Web framework
- SQLAlchemy — Database ORM
- Argon2 — Password hashing
- python-jose — JWT handling
- SlowAPI — Rate limiting
- Pydantic Settings — Configuration management
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/auth/login |
Log in and get an access token |
| POST | /api/v1/auth/refresh |
Get a new access token |
| POST | /api/v1/auth/logout |
Log out and clear the cookie |
| GET | /api/v1/auth/me |
Get the current user info |
| GET | /health |
Health check |
- Python 3.10+
- Docker (optional)
-
Clone the repository:
git clone https://github.com/InanColak/auth-service.git cd auth-service -
Install dependencies:
pip install -r requirements.txt
-
Create a
.envfile (see.env.example) and set yourJWT_SECRET. -
Run the service:
uvicorn app.main:app --reload
python scripts/create_user.py --email admin@example.com --password yourpassworddocker compose up --buildSet these environment variables (see .env.example):
JWT_SECRET— Secret key for signing tokens (required)JWT_ALGORITHM— Default:HS256ACCESS_TOKEN_EXPIRE_MINUTES— Default:15REFRESH_TOKEN_EXPIRE_DAYS— Default:7DATABASE_URL— Default:sqlite:///./data/auth.db
This project is licensed under the MIT License.