User Authentication Service
A professional and reliable user authentication service built with FastAPI and SQLite. This service provides a secure authentication flow with JWT tokens, including refresh token functionality.
Features
- User registration and login
- JWT-based authentication with access and refresh tokens
- Password hashing with bcrypt
- User profile management
- Role-based access control (superuser and regular user)
- Health check endpoint
- Alembic migrations
- SQLite database
Project Structure
.
├── alembic.ini
├── app
│ ├── api
│ │ ├── deps.py
│ │ ├── endpoints
│ │ │ ├── auth.py
│ │ │ └── users.py
│ │ └── api.py
│ ├── core
│ │ ├── config.py
│ │ └── security.py
│ ├── db
│ │ ├── base.py
│ │ ├── base_class.py
│ │ └── session.py
│ ├── models
│ │ └── user.py
│ ├── schemas
│ │ ├── token.py
│ │ └── user.py
│ ├── services
│ │ └── user.py
│ └── storage
│ └── db
├── main.py
├── migrations
│ ├── env.py
│ ├── README
│ ├── script.py.mako
│ └── versions
│ └── 001_create_user_table.py
└── requirements.txt
Getting Started
Prerequisites
- Python 3.8 or higher
Installation
- Clone the repository
git clone <repository-url>
cd userauthenticationservice
- Install dependencies
pip install -r requirements.txt
- Run the migrations
alembic upgrade head
- Start the server
uvicorn main:app --reload
API Documentation
Once the server is running, you can access the API documentation at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API Endpoints
Authentication
POST /api/v1/auth/register
- Register a new userPOST /api/v1/auth/login
- Login and get tokensPOST /api/v1/auth/refresh-token
- Refresh access token
Users
GET /api/v1/users/me
- Get current user profilePUT /api/v1/users/me
- Update current user profileGET /api/v1/users/{user_id}
- Get user by ID (superuser only)
Health Check
GET /health
- Service health check
Security
- Passwords are hashed using bcrypt
- Authentication is handled via JWT tokens
- Access tokens expire after 30 minutes
- Refresh tokens expire after 7 days
- CORS protection is enabled
Development
For development, you can run the server with auto-reload:
uvicorn main:app --reload
Description
Languages
Python
97.7%
Mako
2.3%