Modern chat UI with Entra ID login and Azure AI integration
Update (June 2025):
- The app is now fully stateless. No Redis or caching server is required or used.
- All chat state is handled per-request; the backend does not persist or cache chat data.
- Documentation, setup, and troubleshooting have been updated to reflect this change.
Here's a simple, secure chat application that demonstrates how to:
- Authenticate users with Microsoft Entra ID (MSAL) in a FastAPI web app
- Connect to an Azure AI Agent Service agent (deployed in Azure AI Foundry)
- Use a Fabric Data Agent as a knowledge source for natural language queries
- Integrate Microsoft Fabric data with conversational AI using the Semantic Kernel
- Build a professional, cloud-ready Python app following Azure and open-source best practices
Stateless: No Redis or caching server is required. The backend does not store chat state. Each chat request is processed independently.
This project is ideal for developers and architects looking to:
- Learn how to combine Entra ID authentication, Azure AI Agent Service, and Microsoft Fabric
- See a real-world example of secure, scalable, and maintainable cloud app architecture
- Use environment-based configuration and modern Python web development patterns
- 🔐 Microsoft Entra ID (MSAL) authentication
- 🤖 Azure AI Agent Service integration
- 📊 Fabric Data Agent as knowledge source
- 🧠 Semantic Kernel plugin
- 💬 Simple chat UI
- 🔒 Secure session management
- 📝 Easy configuration via
.env
- 🟢 Stateless backend – no Redis or caching required
flowchart LR
Browser["User Browser<br/>(chat.html, form)"]
FastAPI["FastAPI Server<br/>(Python, MSAL, Semantic Kernel)"]
Agent["Azure AI Agent Service Agent<br/>(Azure AI Foundry)"]
Fabric["Fabric Data Agent<br/>(Microsoft Fabric Data Source)"]
AD["Microsoft Entra ID (MSAL)"]
Browser <--> FastAPI
FastAPI <--> Agent
Agent <--> Fabric
FastAPI --> AD
+-------------------+ +-------------------+ +-------------------------------+ +--------------------------+
| User Browser | <-----> | FastAPI Server | <-----> | Azure AI Agent Service Agent | <-----> | Fabric Data Agent |
| (chat.html, form) | | (Python, MSAL, | | (Azure AI Foundry, | | (Microsoft Fabric Data |
+-------------------+ | Semantic Kernel) | | AgentsClient) | | Source) |
+-------------------+ +-------------------------------+ +--------------------------+
^
|
+--------------------------+
| Microsoft Entra ID |
| (MSAL) |
+--------------------------+
Flow:
- User logs in via Microsoft Entra ID (MSAL) in the browser.
- User sends a chat message to the FastAPI server.
- FastAPI server uses the user's access token to call the Azure AI Agent Service agent (in Azure AI Foundry).
- The Azure AI Agent Service agent uses a Fabric Data Agent as a knowledge source to answer the query.
- The response is returned to the user in the chat UI.
Stateless: No chat history or state is stored on the backend. Each request is processed independently. Redis or any caching server is NOT required. You do not need to set up or run Redis for any feature.
# 1. Clone the repo
git clone https://github.com/aliasgarjh/fabric-data-agent-app.git
cd fabric-data-agent-app
# 2. (Recommended) Create and activate a Python virtual environment
python -m venv .venv
# On Windows:
.venv\Scripts\activate
# On macOS/Linux:
source .venv/bin/activate
# 3. Copy and edit .env.example
cp .env.example .env
# 4. Install dependencies
pip install -r requirements.txt
# 5. Run the app
python -m uvicorn fastapi_fabric_chat:app --reload
fastapi_fabric_chat.py
— Main FastAPI appstatic/chat.html
— Chat UI template.env
— Configuration (secrets, endpoints, etc.).env.example
— Example environment filerequirements.txt
— Python dependenciesREADME.md
— Project documentationLICENSE
— MIT License
- Go to Azure Portal > Microsoft Entra ID > App registrations.
- Click New registration.
- Enter a name (e.g.,
Azure AI Fabric Chat
). - Set Supported account types as needed (usually "Accounts in this organizational directory only").
- Set Redirect URI to:
- Type: Web
- Value:
http://localhost:8000/auth/redirect
- Click Register.
- After registration, go to Certificates & secrets and create a Client Secret. Save the value for your
.env
file. - Go to API permissions and add the following delegated permissions (scopes):
- Microsoft Graph:
openid
(for authentication)profile
(to read user profile)email
(to read user email)
- Azure Machine Learning Services:
https://ai.azure.com/.default
(for Azure AI Agent Service access)
- Any other required permissions for your scenario
- Microsoft Graph:
- Click Grant admin consent for your tenant.
- Copy the Application (client) ID and Directory (tenant) ID for your
.env
file.
You can add a Microsoft Fabric Data Agent as a knowledge source to your Azure AI Agent either through the Azure AI Foundry portal (UI) or programmatically. Below are the recommended UI steps:
- Go to Azure AI Foundry and select your Azure subscription and resource group.
- In the left pane, under Build and Customize, select Agents.
- Click New Agent to create a new agent, or select an existing agent to edit.
- In the agent's setup pane, scroll to the Knowledge section and click Add.
- In the menu of supported knowledge source types, select Microsoft Fabric.
- If you have an existing connection to a Fabric Data Agent, select it. Otherwise, click New Connection.
- In the connection dialog:
- Enter the
workspace-id
andartifact-id
from your published Fabric Data Agent endpoint. The endpoint format is:https://fabric.microsoft.com/groups/<workspace_id>/aiskills/<artifact-id>
- Mark both as Is Secret.
- Assign a name to your connection.
- Click Connect.
- Enter the
- The Microsoft Fabric Data Agent will now appear as a Knowledge resource for your agent.
- (Optional) Update your agent's instructions to describe when and how to use the Fabric tool (e.g., "For customer and product sales data, use the Fabric tool").
- Save your agent and test it using the Try in playground feature.
For more details and screenshots, see the official Microsoft documentation.
Fill in your .env
file with the following:
CLIENT_ID=<your-app-client-id>
CLIENT_SECRET=<your-app-client-secret>
TENANT_ID=<your-tenant-id>
FABRIC_PROJECT_ENDPOINT=<your-agent-project-endpoint>
FABRIC_AGENT_ID=<your-agent-id>
SESSION_SECRET=<your-random-session-secret>
Note: Redis or any caching server is NOT required. The app is fully stateless. You can ignore any previous instructions or configuration related to Redis.
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
- Author: Ali Asgar Juzer
- GitHub: aliasgarjh
- Email: ali.juzer@microsoft.com
- Use Managed Identity or Service Principal for Azure authentication in production.
- Never hardcode credentials; use Key Vault or environment variables.
- Implement retry logic and error handling for all Azure SDK/API calls.
- Use HTTPS endpoints and enable encryption.
- Restrict API permissions to the minimum required.
- Use logging for all errors and important events.
- Regularly review and rotate secrets.
- Use Infrastructure as Code (Bicep, Terraform) for Azure deployments.
- State mismatch or session errors: Ensure your
SESSION_SECRET
is set and consistent across restarts. - Authentication issues: Double-check your Entra ID app registration, redirect URI, and tenant settings.
- Fabric/AI Agent errors: Verify your endpoint and agent IDs, and that your user has access.
- No Redis needed: The app is fully stateless and does not require Redis or any caching server. If you see any references to Redis in old documentation or code, you can ignore them.
MIT License