A FastAPI-based centralized authentication system with LDAP integration and group-based authorization.
- LDAP authentication with OpenLDAP integration
- Group-based authorization (GroupA/GroupB access control)
- Secure session management
- Docker containerization
- Interactive API documentation
- Docker and Docker Compose
- Git
- Clone the repository:
git clone https://github.com/Emansaeed331/centralized-auth.git
cd centralized-auth- Start the application:
docker-compose up --build- Access the application:
- Web App: http://localhost:8080
- API Docs: http://localhost:8080/docs
| Username | Password | Groups | Dashboard Access |
|---|---|---|---|
user1 |
password1 |
GroupA | Admin Dashboard |
user2 |
password2 |
GroupB | User Dashboard |
If you want to run without Docker:
- Create virtual environment:
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Start LDAP server:
docker-compose up openldap -d- Run application:
uvicorn main:app --reload --host 0.0.0.0 --port 8000- Start the system:
docker-compose up --build-
Open your browser and go to: http://localhost:8080
-
Login with test users:
- user1/password1 → Access to Admin Dashboard
- user2/password2 → Access to User Dashboard
-
Navigate between dashboards:
- Admin users see administrative functions
- Regular users see standard user interface
-
Logout: Click the logout link to end your session
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Redirects to appropriate dashboard |
/login |
GET/POST | Login page and authentication |
/dashboard-a |
GET | Admin dashboard (GroupA) |
/dashboard-b |
GET | User dashboard (GroupB) |
/logout |
GET | Logout and clear session |
/docs |
GET | Interactive API documentation |
Create a .env file to customize:
LDAP_SERVER=localhost
LDAP_PORT=1389
LDAP_BASE_DN=dc=example,dc=org# Start services
docker-compose up --build
# Run in background
docker-compose up -d
# Stop services
docker-compose down
# View logs
docker-compose logs app- Start application:
docker-compose up --build - Go to http://localhost:8080
- Try logging in with test users (user1, user2)
- Verify proper dashboard access based on groups
- Test logout functionality
# Test login
curl -X POST http://localhost:8080/login \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=user1&password=password1"LDAP Connection Issues:
docker-compose logs openldapAuthentication Problems:
- Check username/password (case sensitive)
- Verify user exists in LDAP
- Check application logs:
docker-compose logs app
Permission Denied:
- Verify user belongs to correct group
- Check session is active (refresh browser)
centralized-auth/
├── main.py # FastAPI application
├── auth.py # LDAP authentication
├── requirements.txt # Python dependencies
├── Dockerfile # Container configuration
├── docker-compose.yml # Multi-service setup
├── ldap-seed.ldif # Test LDAP data
└── app/templates/ # HTML templates
├── login.html
├── dashboard_a.html
└── dashboard_b.html
- Secure session management (1-hour timeout)
- LDAP authentication with group authorization
- CSRF protection
- HttpOnly cookies
- Input validation and sanitization