
- Set up FastAPI project structure with main.py and requirements.txt - Create User model with SQLAlchemy and SQLite database - Implement JWT token-based authentication system - Add password hashing with bcrypt - Create auth endpoints: register, login, and protected /me route - Set up Alembic for database migrations - Add health check endpoint with database status - Configure CORS to allow all origins - Update README with setup instructions and environment variables
56 lines
1.4 KiB
Markdown
56 lines
1.4 KiB
Markdown
# User Authentication Service
|
|
|
|
A FastAPI-based user authentication service with JWT token support and SQLite database.
|
|
|
|
## Features
|
|
|
|
- User registration and login
|
|
- JWT token-based authentication
|
|
- Password hashing with bcrypt
|
|
- SQLite database with SQLAlchemy ORM
|
|
- Database migrations with Alembic
|
|
- CORS enabled for all origins
|
|
- Health check endpoint
|
|
- API documentation at `/docs` and `/redoc`
|
|
|
|
## Installation
|
|
|
|
1. Install dependencies:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
2. Set up environment variables (optional):
|
|
```bash
|
|
export SECRET_KEY="your-secret-key-here"
|
|
export ACCESS_TOKEN_EXPIRE_MINUTES="30"
|
|
```
|
|
|
|
## Running the Application
|
|
|
|
Start the development server:
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
The API will be available at `http://localhost:8000`
|
|
|
|
## API Endpoints
|
|
|
|
- `GET /` - Service information
|
|
- `POST /auth/register` - Register a new user
|
|
- `POST /auth/login` - Login and get access token
|
|
- `GET /auth/me` - Get current user info (requires authentication)
|
|
- `GET /health` - Health check endpoint
|
|
- `GET /docs` - Interactive API documentation
|
|
- `GET /redoc` - Alternative API documentation
|
|
|
|
## Environment Variables
|
|
|
|
- `SECRET_KEY` - Secret key for JWT token signing (default: "your-secret-key-change-this-in-production")
|
|
- `ACCESS_TOKEN_EXPIRE_MINUTES` - Token expiration time in minutes (default: 30)
|
|
|
|
## Database
|
|
|
|
The application uses SQLite database stored at `/app/storage/db/db.sqlite`. Database migrations are managed with Alembic.
|