A comprehensive, production-ready chatbot application with Azure Entra ID authentication, Azure Foundry integration, and OAuth Identity Passthrough (MCP). Features a mobile-responsive React frontend and FastAPI backend.
Just Added:
- RBAC + Agent Visibility: Users see only agents they have permission to access
- RAG Integration: Azure AI Search and SharePoint knowledge base
- OAuth Consent Flow: Enhanced permissions for SharePoint access
📖 Read Phase 1 Documentation →
- Azure Entra ID OAuth 2.0: Enterprise-grade authentication
- OAuth Identity Passthrough (MCP): Seamless user context propagation to AI agents
- RBAC (Role-Based Access Control): ⭐ NEW - Filter agents by user role
- Secure Token Validation: JWT validation with JWKS
- Row Level Security: Database-level security with Azure Table Storage
- Azure Foundry Integration: Dynamic agent discovery and management
- RAG (Retrieval-Augmented Generation): ⭐ NEW - Azure AI Search + SharePoint
- Multi-Agent Support: Chat with multiple specialized AI agents
- Context-Aware Conversations: Full conversation history maintained
- Real-Time Responses: Responsive chat interface with typing indicators
- Mobile-Responsive Design: Optimized for mobile, tablet, and desktop
- Modern UI: Clean, professional interface with Tailwind CSS
- Session Management: Create, view, and delete chat sessions
- Error Handling: Comprehensive error states and user feedback
- React 18 with TypeScript
- Vite for fast development and building
- Tailwind CSS for styling
- MSAL Browser for Azure authentication
- Axios for API communication
- Lucide React for icons
- FastAPI for REST API
- Python 3.11+
- MSAL for token validation
- Azure AI Projects SDK for Foundry integration
- Supabase for database and storage
- Supabase: PostgreSQL database with RLS
- Azure Entra ID: Identity and access management
- Azure Foundry: AI agent platform
The application implements OAuth Identity Passthrough, ensuring that:
- User Context Preservation: User identity is maintained throughout the conversation
- Secure Authorization: Agents can make authorized API calls on behalf of users
- Audit Trails: All actions are logged with actual user information
- Resource Access: Agents can access user-specific resources securely
User → Azure AD Login → Access Token
↓
Access Token → Frontend → Backend API
↓
Backend validates token → Creates MCP Context
↓
MCP Context + Message → Azure Foundry Agent
↓
Agent uses user's token → Accesses resources
↓
Agent response → Backend → Frontend → User
- Node.js 18+ and npm
- Python 3.11+
- Azure subscription
- Supabase account (already configured in this project)
- Go to Azure Portal
- Navigate to Azure Active Directory > App registrations > New registration
- Configure:
- Name: Azure AI Chatbot
- Supported account types: Single tenant or multi-tenant
- Redirect URI:
- Platform: Single-page application (SPA)
- URI:
http://localhost:5173
- Click Register
- In your app registration, go to Authentication
- Under Implicit grant and hybrid flows, enable:
- Access tokens
- ID tokens
- Add additional redirect URIs as needed for production
- Save changes
- Go to Certificates & secrets > New client secret
- Add description: "Backend API Secret"
- Set expiration (recommend 24 months)
- Copy the secret value immediately (you won't be able to see it again)
Copy these values for configuration:
- Application (client) ID: Found on Overview page
- Directory (tenant) ID: Found on Overview page
- Client secret: Copied from previous step
- Go to Azure AI Foundry Portal
- Create a new project or use an existing one
- Note the following values:
- Project Endpoint: Found in project settings
- API Key: Generate in project settings > Keys and endpoints
- Project ID: Found in project settings
- In Azure AI Foundry, create or configure AI agents
- Ensure agents are published and active
- Note agent capabilities and descriptions
Update /tmp/cc-agent/61459630/project/.env:
VITE_SUPABASE_URL=https://ifxjccehmmukumnftbbl.supabase.co
VITE_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImlmeGpjY2VobW11a3VtbmZ0YmJsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjU2NDY3ODQsImV4cCI6MjA4MTIyMjc4NH0.ljZRZ7Mv4HWB9CP7AeTaaXgM3GzBgkSkEro70XCiFeo
VITE_AZURE_CLIENT_ID=<your_azure_client_id>
VITE_AZURE_TENANT_ID=<your_azure_tenant_id>
VITE_AZURE_REDIRECT_URI=http://localhost:5173
VITE_API_URL=http://localhost:8000/apiCreate backend/.env file (use backend/.env.example as template):
# Azure Entra ID
AZURE_CLIENT_ID=<your_azure_client_id>
AZURE_TENANT_ID=<your_azure_tenant_id>
AZURE_CLIENT_SECRET=<your_client_secret>
# Azure Foundry
AZURE_FOUNDRY_ENDPOINT=<your_foundry_endpoint>
AZURE_FOUNDRY_API_KEY=<your_foundry_api_key>
AZURE_FOUNDRY_PROJECT_ID=<your_project_id>
# Supabase (Service Role Key for backend)
SUPABASE_URL=https://ifxjccehmmukumnftbbl.supabase.co
SUPABASE_SERVICE_KEY=<your_supabase_service_role_key>
# Settings
MCP_ENABLED=true
CORS_ORIGINS=http://localhost:5173,http://localhost:3000
DEBUG=falsenpm installcd backend
pip install -r requirements.txtThe database schema is already created in Supabase. To verify:
- Go to your Supabase project dashboard
- Navigate to Table Editor
- Verify these tables exist:
usersagentschat_sessionschat_messages
cd backend
python main.pyThe backend will run on http://localhost:8000
API documentation available at:
- Swagger UI:
http://localhost:8000/api/docs - ReDoc:
http://localhost:8000/api/redoc
npm run devThe frontend will run on http://localhost:5173
- Open
http://localhost:5173in your browser - Click "Sign in with Microsoft"
- Complete Azure AD authentication
- Select an AI agent from the list
- Start chatting!
GET /api/auth/me- Get current user profile
GET /api/agents- List all available agentsGET /api/agents/{agent_id}- Get specific agent
POST /api/sessions- Create new chat sessionGET /api/sessions- List user's sessionsGET /api/sessions/{session_id}- Get session with message historyDELETE /api/sessions/{session_id}- Delete session
POST /api/chat- Send message and get response
GET /- Basic health checkGET /api/health- Detailed health check
- User Authentication: User logs in with Azure Entra ID and receives an access token
- Token Propagation: Frontend includes token in Authorization header for all API calls
- Token Validation: Backend validates token using Azure AD JWKS endpoint
- MCP Context Creation: Backend creates MCP context with user identity and token
- Agent Communication: MCP context is passed to Azure Foundry with each message
- Agent Authorization: Agent uses user's token to access resources on their behalf
- Token Security: Tokens are transmitted over HTTPS only
- Token Validation: Strict JWT validation with signature, expiration, and audience checks
- Least Privilege: Agents only have access to what user's token permits
- Audit Logging: All actions logged with user identity for compliance
Stores authenticated user information from Azure Entra ID
Stores AI agents synced from Azure Foundry
Tracks conversations between users and agents
Stores all messages with role (user/assistant/system)
All tables have Row Level Security (RLS) enabled with policies ensuring users can only access their own data.
npm run dev # Start dev server
npm run build # Build for production
npm run preview # Preview production build
npm run lint # Run ESLint
npm run typecheck # Run TypeScript type checkingcd backend
uvicorn main:app --reload # Development server with auto-reload
python main.py # Production serverproject/
├── src/
│ ├── components/ # React components
│ │ ├── Login.tsx # Login page
│ │ ├── AgentSelection.tsx # Agent selection UI
│ │ └── Chat.tsx # Chat interface
│ ├── contexts/ # React contexts
│ │ └── AuthContext.tsx # Authentication context
│ ├── config/ # Configuration
│ │ └── azureConfig.ts # Azure MSAL config
│ ├── services/ # API services
│ │ └── api.ts # API client
│ ├── types/ # TypeScript types
│ │ └── index.ts
│ ├── App.tsx # Main app component
│ └── main.tsx # Entry point
├── backend/
│ ├── main.py # FastAPI application
│ ├── auth.py # Authentication & MCP
│ ├── azure_foundry.py # Azure Foundry integration
│ ├── models.py # Pydantic models
│ ├── config.py # Configuration
│ └── requirements.txt # Python dependencies
└── README.md # This file
Problem: "Invalid token" or "Token has expired"
- Solution: Ensure Azure AD app registration is configured correctly
- Check that redirect URI matches exactly
- Verify client ID and tenant ID are correct
Problem: "Failed to fetch user profile"
- Solution: Ensure
User.Readscope is granted in Azure AD - Check that access token has required permissions
Problem: "Failed to load agents"
- Solution: Verify Azure Foundry credentials are correct
- Check that agents are published in Azure Foundry
- Ensure API endpoint is accessible
Problem: "Failed to create session" or "Access denied"
- Solution: Verify Supabase URL and service key are correct
- Check that RLS policies are properly configured
- Ensure user exists in users table
Problem: Frontend can't connect to backend
- Solution: Ensure backend is running on port 8000
- Check CORS settings in backend config
- Verify
VITE_API_URLis set correctly in frontend .env
-
Build the frontend:
npm run build
-
Deploy the
dist/folder to your hosting service (Vercel, Netlify, etc.) -
Update environment variables for production:
- Set production Azure redirect URI
- Update API URL to production backend
-
Choose a hosting service (Azure App Service, AWS, etc.)
-
Set environment variables on hosting platform
-
Deploy backend code
-
Update CORS_ORIGINS to include production frontend URL
- Add production redirect URI to Azure AD app registration
- Update any production-specific scopes or permissions
- Consider using separate app registrations for dev/prod
- Never commit secrets: Use environment variables
- Use HTTPS: Always in production
- Rotate keys: Regularly rotate client secrets and API keys
- Monitor logs: Watch for suspicious authentication attempts
- Update dependencies: Keep all packages up to date
- RLS policies: Never bypass Row Level Security
- Input validation: Backend validates all inputs
- Rate limiting: Consider adding rate limiting in production
MIT License - See LICENSE file for details
For issues or questions:
- Check this documentation
- Review Azure AD and Azure Foundry documentation
- Check application logs for error details
- Review Supabase logs for database issues