1- # 🔹 Flask-API: Active Directory SSO Integration
1+ # 🔹 Flask-API — Active Directory SSO Integration
22
3- ## 📌 Overview
3+ ![ SSO ] ( https://img.shields.io/badge/SSO-LDAP%20%7C%20Active%20Directory-blue?style=for-the-badge&logo=microsoft ) ![ Python ] ( https://img.shields.io/badge/Python-Flask-3776AB?style=for-the-badge&logo=python&logoColor=white ) ![ API ] ( https://img.shields.io/badge/Type-REST%20API-0A66C2?style=for-the-badge ) ![ Security ] ( https://img.shields.io/badge/Security-Enterprise%20SSO-critical?style=for-the-badge )
44
5- The ** Flask-API** is a ** Python-based REST API** built with ** Flask** that enables ** LDAP-based Single Sign-On (SSO) authentication** with ** Active Directory** using the ` ldap3 ` library.
5+ ## 📝 Overview
6+
7+ The ** Flask-API** module is a ** Python-based REST API** built with ** Flask** that provides ** LDAP-based Single Sign-On (SSO)** authentication against ** Microsoft Active Directory** , using the ` ldap3 ` library.
8+
9+ This integration follows the same ** security, configuration, and architectural standards** defined across the ** ActiveDirectory-SSO-Integrations** suite, ensuring ** consistent, auditable, and reusable SSO patterns** for enterprise environments.
10+
11+ Primary goals:
12+
13+ - Centralized authentication via Active Directory
14+ - Secure LDAP bind using ** service accounts (InetOrgPerson)**
15+ - Middleware-enforced authentication flow
16+ - Lightweight, extensible REST interface
617
718---
819
920## 📁 Folder Structure
1021
1122```
1223ActiveDirectory-SSO-Integrations/
13- │
14- ├── 📂 Flask-API/ # Parent folder for Flask API integration
15- │ ├── 📜 requirements.txt # Python dependencies
16- │ ├── 📁 app.py # Main application file with LDAP logic
17- │ ├── 📜 config.py # LDAP configuration settings
18- │ ├── 📂 controllers/ # API endpoints
19- │ │ ├── 📜 auth_controller.py # Handles authentication
20- │ │ ├── 📜 user_controller.py # Fetches user details
21- │ ├── 📂 middleware/ # Authentication middleware
22- │ │ ├── 📜 ldap_auth_middleware.py # Enforces authentication
23- │ ├── 📂 utils/ # Helper functions
24- │ │ ├── 📜 logger.py # Logs authentication events
25- │ ├── 📖 README.md # Documentation for Flask-API
24+ └── Flask-API/
25+ ├── requirements.txt
26+ ├── app.py
27+ ├── config.py
28+ ├── controllers/
29+ │ ├── auth_controller.py
30+ │ └── user_controller.py
31+ ├── middleware/
32+ │ └── ldap_auth_middleware.py
33+ ├── utils/
34+ │ └── logger.py
35+ └── README.md
2636```
2737
2838---
2939
3040## 🛠️ Prerequisites
3141
32- - ** Python 3.8+**
33- - ** Active Directory instance**
34- - ** LDAP access credentials**
35- - ** Postman or cURL** (for API testing)
42+ - Python ** 3.8+**
43+ - Active Directory domain with LDAP enabled
44+ - Dedicated LDAP bind account (InetOrgPerson, least privilege)
45+ - pip / virtualenv
46+ - Postman or curl for API testing
3647
3748---
3849
39- ## ⚙️ Configuration
50+ ## ⚙️ LDAP Configuration
4051
41- Modify ` config.py ` with your ** LDAP credentials ** :
52+ Edit ` config.py ` and configure LDAP parameters :
4253
4354``` python
4455LDAP_CONFIG = {
@@ -50,91 +61,47 @@ LDAP_CONFIG = {
5061}
5162```
5263
53- ---
54-
55- ## 🚀 How to Run
56-
57- 1 . ** Clone the repository** :
58- ``` bash
59- git clone https://github.com/brazilianscriptguy/Windows-SysAdmin-ProSuite.git
60- cd Windows-SysAdmin-ProSuite/SysAdmin-Tools/ActiveDirectory-SSO-Integrations/Flask-API
61- ```
62-
63- 2 . ** Set the LDAP password as an environment variable** :
64- ``` bash
65- export LDAP_PASSWORD=' your-secure-password'
66- ```
67-
68- 3 . ** Install dependencies** :
69- ``` bash
70- pip install -r requirements.txt
71- ```
72-
73- 4 . ** Run the application** :
74- ``` bash
75- python app.py
76- ```
64+ > 🔐 ** Security note:** never hardcode credentials. Always inject ` LDAP_PASSWORD ` via environment variables or a secure secret store.
7765
7866---
7967
80- ## 🔄 API Endpoints
81-
82- ### 1️⃣ Authenticate User
83-
84- - ** Endpoint** : ` POST /api/auth/login `
85- - ** Request Body** :
86- ``` json
87- {
88- "username" : " john.doe" ,
89- "password" : " SuperSecretPassword"
90- }
91- ```
92- - ** Response** :
93- ``` json
94- {
95- "message" : " Authentication successful"
96- }
97- ```
68+ ## 🚀 Running the API
9869
99- ---
70+ ``` bash
71+ git clone https://github.com/brazilianscriptguy/Windows-SysAdmin-ProSuite.git
72+ cd Windows-SysAdmin-ProSuite/SysAdmin-Tools/ActiveDirectory-SSO-Integrations/Flask-API
73+ ```
10074
101- ### 2️⃣ Get User Details
102-
103- - ** Endpoint** : ` GET /api/user/{username} `
104- - ** Example Request** :
105- ``` bash
106- curl -X GET http://localhost:5000/api/user/john.doe
107- ```
108- - ** Response** :
109- ``` json
110- {
111- "username" : " john.doe" ,
112- "displayName" : " John Doe" ,
113- 114- "department" : " IT" ,
115- "role" : " User"
116- }
117- ```
75+ ``` bash
76+ export LDAP_PASSWORD=" your-secure-password"
77+ pip install -r requirements.txt
78+ python app.py
79+ ```
11880
11981---
12082
121- ## 📜 License
122-
123- [ ![ MIT License] ( https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge )] ( https://github.com/brazilianscriptguy/Windows-SysAdmin-ProSuite/blob/main/.github/LICENSE.txt )
83+ ## 🔄 API Endpoints
12484
125- ---
85+ ### Authenticate User
86+ ` POST /api/auth/login `
12687
127- ## 🤝 Contributing
88+ ### Retrieve User Details
89+ ` GET /api/user/{username} `
12890
129- [ ![ Contributions Welcome] ( https://img.shields.io/badge/Contributions-Welcome-brightgreen?style=for-the-badge )] ( https://github.com/brazilianscriptguy/Windows-SysAdmin-ProSuite/blob/main/.github/CONTRIBUTING.md )
91+ Example:
92+ ``` bash
93+ curl -X GET http://localhost:5000/api/user/john.doe
94+ ```
13095
13196---
13297
133- ## 📩 Support
98+ ## 🔐 Security Notes
13499
135- [ ![ Email Badge
] ( https://img.shields.io/badge/[email protected] ?style=for-the-badge&logo=gmail )] ( mailto:[email protected] ) 136- [ ![ GitHub Issues] ( https://img.shields.io/badge/GitHub%20Issues-Report%20Here-blue?style=for-the-badge&logo=github )] ( https://github.com/brazilianscriptguy/Windows-SysAdmin-ProSuite/blob/main/.github/BUG_REPORT.md )
100+ - LDAP bind uses ** least-privilege service account**
101+ - Interactive logon disabled for bind account
102+ - Authentication enforced via middleware
103+ - Suitable for containerized and on-prem deployments
137104
138105---
139106
140- < p align = " center " >🚀 < strong >Enjoy Seamless SSO Integration!</ strong > 🎯</ p >
107+ © 2026 Luiz Hamilton Silva. All rights reserved.
0 commit comments