β οΈ This project is currently IN PROGRESS. Features are being actively developed and things may change.
A production-ready, multi-tenant IAM (Identity & Access Management) service built with FastAPI and PostgreSQL. Designed to be a reusable authentication and authorization backbone for multiple applications.
| Phase | Feature | Status |
|---|---|---|
| Phase 1 | Authentication (JWT) | β |
| Phase 2 | RBAC (Roles & Permissions) | β |
| Phase 3 | IAM APIs (validate-token, check-permission) | β |
| Phase 4 | Multi-Application Support | β |
| Phase 5 | Advanced Security (JWT, Lock, Rate Limit basics) | β |
| Phase 6 | Admin Dashboard (UI + Management) | β |
| Phase 7 | Audit Logs & Tracking | β |
| Phase 8 | Application Registration (app_id, api_key, redirect_uri) | β |
| Phase 9 | Redirect-based Authentication (/authorize flow) | β |
| Phase 10 | Secure Token Exchange (code β JWT) | β |
| Phase 11 | External App Integration Flow | β |
| Phase 12 | App-scoped RBAC Enforcement | β |
| Phase 13 | App Access Control (no role β no entry) | β |
| Phase 14 | Security & Optimization (perm_version, rate limit, validation) | β |
- JWT-based login system
- Redirect-based login (SSO-lite)
- App-scoped tokens
- Roles + Permissions model
- App-specific role assignments
- Centralized permission checks via IAM APIs
- Same user β different roles per app
- Strict
app_idbased isolation - No cross-application access
-
Super Admin
- Full system access (bypass checks)
- Manage all applications
-
App Admin
- Full control within a specific app
- Cannot access other apps
- JWT contains
perm_version - DB maintains version per user per app
- Mismatch β token refresh required
- Prevents stale permission issues
- Apps register with:
app_idapi_keyredirect_uri
- Apps redirect users to AuthZen for authentication
- IAM remains the single source of truth
- Login success/failure tracking
- Permission checks
- Role/permission changes
- IP & metadata logging
| Layer | Technology |
|---|---|
| Backend | FastAPI |
| Database | PostgreSQL |
| ORM | SQLAlchemy |
| Migrations | Alembic |
| Auth | JWT (python-jose), bcrypt (passlib) |
| Templates | Jinja2 |
| Config | Pydantic Settings, python-dotenv |
ad fastapi/
βββ app/
β βββ core/ # Config, security utilities
β βββ db/ # Database session & base
β βββ middleware/ # Custom middleware
β βββ models/ # SQLAlchemy ORM models
β β βββ user.py
β β βββ role.py
β β βββ permission.py
β β βββ application.py
β β βββ audit_log.py
β β βββ associations.py
β βββ routes/ # API route handlers
β β βββ auth.py
β β βββ users.py
β β βββ roles.py
β β βββ permissions.py
β β βββ applications.py
β β βββ audit_logs.py
β β βββ pages.py
β βββ schemas/ # Pydantic request/response models
β βββ services/ # Business logic layer
β βββ utils/ # Helper functions
β βββ main.py # FastAPI app entry point
βββ templates/ # Jinja2 HTML templates (Admin UI)
βββ requirements.txt
βββ .env.example
βββ README.md
git clone https://github.com/theansh99999/AuthZen.git
cd "ad fastapi"python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # Linux/Macpip install -r requirements.txtcopy .env.example .envEdit .env with your actual values:
DATABASE_URL=postgresql://postgres:yourpassword@localhost:5432/iam_db
SECRET_KEY=your-super-secret-key-change-in-production
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
APP_NAME=IAM Service
DEBUG=Falsealembic upgrade headuvicorn app.main:app --reloadApp will be live at: http://localhost:8000
Interactive API docs: http://localhost:8000/docs
| Method | Endpoint | Description |
|---|---|---|
POST |
/auth/signup |
Register a new user |
POST |
/auth/login |
Login & get JWT token |
GET |
/auth/validate-token |
Validate a JWT token |
POST |
/auth/check-permission |
Check user permission |
GET |
/users/ |
List all users |
GET |
/roles/ |
List all roles |
POST |
/roles/ |
Create a new role |
POST |
/users/{id}/assign-role |
Assign role to user |
GET |
/permissions/ |
List all permissions |
GET |
/applications/ |
List all applications |
POST |
/applications/ |
Create a new application |
GET |
/audit-logs/ |
View audit logs |
User β POST /auth/login β JWT Token
β
Token in Authorization header (Bearer)
β
Protected Route β Dependency checks token
β
Permission Check β Role β Application Scope
- Refresh Token system
- Account lockout after failed login attempts
- Rate limiting on auth endpoints
- Full Admin Dashboard with role/permission management UI
- OAuth2 / SSO flow for external app login
- Docker support
- CI/CD pipeline
This project is in active development. Feel free to open issues or PRs once the core is stable.
This project is for personal/learning purposes. License TBD.
Built with β€οΈ using FastAPI | IN PROGRESS β stay tuned!