{"id":34852044,"url":"https://github.com/bencoderus/py-auth-service","last_synced_at":"2026-04-27T04:32:37.789Z","repository":{"id":327016230,"uuid":"1107152280","full_name":"bencoderus/py-auth-service","owner":"bencoderus","description":"A FastAPI-based authentication service with JWT token support, user management, and distributed rate limiting using Redis.","archived":false,"fork":false,"pushed_at":"2025-12-01T07:43:33.000Z","size":69,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-12-27T04:26:47.031Z","etag":null,"topics":["fastapi","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bencoderus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-30T17:17:40.000Z","updated_at":"2025-12-01T08:07:39.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/bencoderus/py-auth-service","commit_stats":null,"previous_names":["bencoderus/py-auth-service"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bencoderus/py-auth-service","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bencoderus%2Fpy-auth-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bencoderus%2Fpy-auth-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bencoderus%2Fpy-auth-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bencoderus%2Fpy-auth-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bencoderus","download_url":"https://codeload.github.com/bencoderus/py-auth-service/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bencoderus%2Fpy-auth-service/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32323213,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T23:26:28.701Z","status":"online","status_checked_at":"2026-04-27T02:00:06.769Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastapi","python"],"created_at":"2025-12-25T19:25:51.621Z","updated_at":"2026-04-27T04:32:37.783Z","avatar_url":"https://github.com/bencoderus.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Auth Service\n\nA FastAPI-based authentication service with JWT token support, user management, and distributed rate limiting using Redis.\n\n## Features\n\n- **User Authentication**: Register and login with email and password\n- **JWT Tokens**: Access and refresh token generation with configurable expiration\n- **Password Security**: Bcrypt hashing for secure password storage\n- **Rate Limiting**: Distributed rate limiting using Redis (5 requests per 60 seconds on auth endpoints)\n- **Database**: PostgreSQL for persistent data storage\n- **Async Support**: Fully asynchronous operations using SQLAlchemy async\n- **Docker Support**: Docker and Docker Compose setup for easy deployment\n\n## Tech Stack\n\n- **Framework**: FastAPI\n- **Database**: PostgreSQL with SQLAlchemy ORM\n- **Cache/Rate Limiting**: Redis\n- **Authentication**: JWT (PyJWT)\n- **Password Hashing**: Bcrypt\n- **Migration**: Alembic\n- **Python**: 3.13+\n\n## Prerequisites\n\n- Python 3.13 or higher\n- PostgreSQL 16 or higher\n- Redis 7 or higher\n- Docker and Docker Compose (optional, for containerized setup)\n\n## Project Structure\n\n```\nauth-service/\n├── src/\n│   ├── auth/\n│   │   ├── router.py              # Auth endpoints (login, register)\n│   │   ├── services/\n│   │   │   ├── auth_service.py    # Authentication logic\n│   │   │   ├── jwt_service.py     # JWT token generation/verification\n│   │   │   └── password_hash.py   # Password hashing utilities\n│   │   └── validator.py           # Request validation schemas\n│   ├── user/\n│   │   ├── router.py              # User endpoints\n│   │   └── repository.py          # User database operations\n│   ├── common/\n│   │   └── dependencies/\n│   │       └── rate_limiter.py    # Rate limiting dependency\n│   ├── redis_client.py            # Redis client wrapper\n│   ├── db.py                      # Database configuration\n│   └── main.py                    # FastAPI app initialization\n├── alembic/                       # Database migrations\n├── docker-compose.yml             # Docker Compose configuration\n├── Dockerfile                     # Docker image definition\n├── pyproject.toml                 # Project dependencies\n├── .env.example                   # Environment variables template\n└── README.md                      # This file\n```\n\n## Setup Instructions\n\n### 1. Clone the Repository\n\n```bash\ngit clone \u003crepository-url\u003e\ncd auth-service\n```\n\n### 2. Environment Configuration\n\nCopy the example environment file and update with your values:\n\n```bash\ncp .env.example .env\n```\n\nEdit `.env` with your configuration:\n\n```env\n# Database Configuration\nPOSTGRES_USER=postgres\nPOSTGRES_PASSWORD=your_secure_password\nPOSTGRES_DB=auth_db\nPOSTGRES_PORT=5432\nDB_CONNECTION_STRING=postgresql://postgres:your_secure_password@localhost:5432/auth_db\n\n# Redis Configuration\nREDIS_HOST=localhost\nREDIS_PORT=6379\nREDIS_PASSWORD=your_redis_password\n\n# Application Configuration\nAPP_ENV=development\nAPP_PORT=8000\nJWT_SECRET=your-secure-jwt-secret-key\n```\n\n### 3. Installation\n\n#### Option A: Using Docker Compose (Recommended)\n\n```bash\ndocker-compose up -d\n```\n\nThis will:\n- Start PostgreSQL database\n- Start Redis cache\n- Build and start the FastAPI application\n- Run database migrations automatically\n\nThe application will be available at `http://localhost:8000`\n\n#### Option B: Local Setup\n\n**Install dependencies:**\n\n```bash\npip install -r requirements.txt\n# or using uv\nuv sync\n```\n\n**Start PostgreSQL:**\n\n```bash\n# Using Homebrew (macOS)\nbrew services start postgresql\n\n# Or using Docker\ndocker run -d \\\n  --name auth-postgres \\\n  -e POSTGRES_USER=postgres \\\n  -e POSTGRES_PASSWORD=postgres \\\n  -e POSTGRES_DB=auth_db \\\n  -p 5432:5432 \\\n  postgres:16-alpine\n```\n\n**Start Redis:**\n\n```bash\n# Using Homebrew (macOS)\nbrew services start redis\n\n# Or using Docker\ndocker run -d \\\n  --name auth-redis \\\n  -p 6379:6379 \\\n  redis:7-alpine\n```\n\n**Run database migrations:**\n\n```bash\nalembic upgrade head\n```\n\n**Start the application:**\n\n```bash\nuvicorn src.main:app --reload --host 0.0.0.0 --port 8000\n```\n\n## API Endpoints\n\n### Authentication\n\n#### Register User\n```\nPOST /auth/register\nContent-Type: application/json\n\n{\n  \"email\": \"user@example.com\",\n  \"password\": \"SecurePassword123!\",\n  \"name\": \"John Doe\"\n}\n\nResponse:\n{\n  \"status\": true,\n  \"message\": \"User created successfully\",\n  \"data\": {\n    \"id\": \"uuid\",\n    \"email\": \"user@example.com\",\n    \"name\": \"John Doe\"\n  }\n}\n```\n\n#### Login\n```\nPOST /auth/login\nContent-Type: application/json\n\n{\n  \"email\": \"user@example.com\",\n  \"password\": \"SecurePassword123!\"\n}\n\nResponse:\n{\n  \"status\": true,\n  \"message\": \"Login successful\",\n  \"data\": {\n    \"user\": {\n      \"id\": \"uuid\",\n      \"email\": \"user@example.com\",\n      \"name\": \"John Doe\"\n    },\n    \"token\": {\n      \"accessToken\": \"jwt_token\",\n      \"refreshToken\": \"refresh_token\",\n      \"expiresAt\": \"2024-12-01T12:00:00\",\n      \"refreshExpiresAt\": \"2024-12-08T12:00:00\"\n    }\n  }\n}\n```\n\n### Rate Limiting\n\nBoth `/auth/register` and `/auth/login` endpoints are rate limited to **5 requests per 60 seconds** per client IP.\n\nWhen rate limit is exceeded:\n```\nHTTP 429 Too Many Requests\n\n{\n  \"status\": false,\n  \"message\": \"Rate limit exceeded. Maximum 5 requests per 60 seconds allowed.\"\n}\n```\n\n## Database Migrations\n\n### Create a new migration\n\n```bash\nalembic revision --autogenerate -m \"Description of changes\"\n```\n\n### Apply migrations\n\n```bash\nalembic upgrade head\n```\n\n### Rollback migrations\n\n```bash\nalembic downgrade -1\n```\n\n## Development\n\n### Running Tests\n\n```bash\npytest\n```\n\n### Code Quality\n\n```bash\n# Format code\nblack src/\n\n# Lint code\nruff check src/\n\n# Type checking\nmypy src/\n```\n\n### Makefile Commands\n\n```bash\nmake help          # Show available commands\nmake install       # Install dependencies\nmake run           # Run the application\nmake migrate       # Run database migrations\nmake docker-up     # Start Docker containers\nmake docker-down   # Stop Docker containers\n```\n\n## Troubleshooting\n\n### Database Connection Error\n\nEnsure PostgreSQL is running and the connection string in `.env` is correct:\n\n```bash\npsql postgresql://postgres:password@localhost:5432/auth_db\n```\n\n### Redis Connection Error\n\nEnsure Redis is running:\n\n```bash\nredis-cli ping\n# Should return: PONG\n```\n\n### Port Already in Use\n\nIf port 8000 is already in use, change `APP_PORT` in `.env` or use:\n\n```bash\nuvicorn src.main:app --port 8001\n```\n\n### Database Migration Issues\n\nReset the database (caution: deletes all data):\n\n```bash\n# Drop all tables\nalembic downgrade base\n\n# Re-apply migrations\nalembic upgrade head\n```\n\n## Docker Cleanup\n\nTo remove all containers and volumes:\n\n```bash\ndocker-compose down -v\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbencoderus%2Fpy-auth-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbencoderus%2Fpy-auth-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbencoderus%2Fpy-auth-service/lists"}