Skip to content

theansh99999/AuthZen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” AuthZen β€” Identity & Access Management Service

FastAPI PostgreSQL Status

⚠️ 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.


🧩 Project Phases

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) βœ…

✨ Key Features

πŸ”‘ Authentication

  • JWT-based login system
  • Redirect-based login (SSO-lite)
  • App-scoped tokens

πŸ‘₯ Authorization (RBAC)

  • Roles + Permissions model
  • App-specific role assignments
  • Centralized permission checks via IAM APIs

🏒 Multi-Tenant Support

  • Same user β†’ different roles per app
  • Strict app_id based isolation
  • No cross-application access

πŸ‘‘ Admin Hierarchy

  • Super Admin

    • Full system access (bypass checks)
    • Manage all applications
  • App Admin

    • Full control within a specific app
    • Cannot access other apps

πŸ”„ Permission Versioning (Advanced)

  • JWT contains perm_version
  • DB maintains version per user per app
  • Mismatch β†’ token refresh required
  • Prevents stale permission issues

πŸ”— External App Integration

  • Apps register with:
    • app_id
    • api_key
    • redirect_uri
  • Apps redirect users to AuthZen for authentication
  • IAM remains the single source of truth

πŸ“‹ Audit Logs

  • Login success/failure tracking
  • Permission checks
  • Role/permission changes
  • IP & metadata logging

πŸ› οΈ Tech Stack

Layer Technology
Backend FastAPI
Database PostgreSQL
ORM SQLAlchemy
Migrations Alembic
Auth JWT (python-jose), bcrypt (passlib)
Templates Jinja2
Config Pydantic Settings, python-dotenv

πŸ“ Project Structure

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

⚑ Getting Started

1. Clone the repo

git clone https://github.com/theansh99999/AuthZen.git
cd "ad fastapi"

2. Create a virtual environment

python -m venv venv
venv\Scripts\activate        # Windows
# source venv/bin/activate   # Linux/Mac

3. Install dependencies

pip install -r requirements.txt

4. Setup environment variables

copy .env.example .env

Edit .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=False

5. Run database migrations

alembic upgrade head

6. Start the server

uvicorn app.main:app --reload

App will be live at: http://localhost:8000

Interactive API docs: http://localhost:8000/docs


πŸ”— Key API Endpoints

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

πŸ”’ Authentication Flow

User β†’ POST /auth/login β†’ JWT Token
                              ↓
         Token in Authorization header (Bearer)
                              ↓
         Protected Route β†’ Dependency checks token
                              ↓
         Permission Check β†’ Role β†’ Application Scope

πŸ—ΊοΈ Roadmap

  • 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

🀝 Contributing

This project is in active development. Feel free to open issues or PRs once the core is stable.


πŸ“„ License

This project is for personal/learning purposes. License TBD.


Built with ❀️ using FastAPI | IN PROGRESS β€” stay tuned!

About

A scalable IAM (Identity and Access Management) system built with FastAPI and PostgreSQL, featuring JWT-based authentication, role-based access control (RBAC), multi-application support, and audit logging. Designed as a reusable API service for managing users, roles, and permissions across multiple applications with a clean, modular architecture.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors