diff --git a/.env.example b/.env.example index 56bd2a8..5484389 100644 --- a/.env.example +++ b/.env.example @@ -8,7 +8,7 @@ OPENAI_API_KEY=your_openai_api_key_here # Provider Settings DEFAULT_PROVIDER=claude CLAUDE_MODEL=claude-3-5-sonnet-20241022 -OPENAI_MODEL=gpt-4-turbo-preview +OPENAI_MODEL=gpt-4o-mini # API Configuration MAX_TOKENS=4000 diff --git a/CLAUDE.md b/CLAUDE.md index 04ec36b..e60c433 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -6,7 +6,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co DevDen is a self-hosted AI chat platform that enables organizations to provide AI-powered Q&A based on their own knowledge bases. Users interact through a clean chat interface while administrators manage knowledge bases, AI providers, and user access through a terminal-style dashboard. -**Current Status:** MVP with AI integration complete. Backend FastAPI server with Claude and OpenAI support. Frontend streams responses in real-time. +**Current Status:** MVP with AI integration and Microsoft Entra ID authentication. Backend FastAPI server with Claude and OpenAI support. Frontend streams responses in real-time. ## Architecture @@ -26,14 +26,16 @@ DevDen is a self-hosted AI chat platform that enables organizations to provide A ## Current Files **Frontend:** -- `index.html` - Main chat interface structure with welcome screen -- `script.js` - Chat interaction logic with SSE streaming +- `index.html` - Main chat interface with login, welcome, and chat screens +- `script.js` - Chat interaction logic with SSE streaming and auth handling - `style.css` - Catppuccin Mocha theme with pixel aesthetic **Backend:** - `backend/app/main.py` - FastAPI application entry point -- `backend/app/config.py` - Environment configuration -- `backend/app/api/chat.py` - Chat endpoints (POST /api/chat, POST /api/chat/stream) +- `backend/app/config.py` - Environment configuration (AI providers, Entra ID, JWT) +- `backend/app/api/chat.py` - Chat endpoints (POST /api/chat, POST /api/chat/stream) - protected +- `backend/app/api/auth.py` - Auth endpoints (login, callback, me, logout, status) +- `backend/app/middleware/auth.py` - JWT validation middleware - `backend/app/services/provider_manager.py` - Provider abstraction and fallback - `backend/app/services/provider_claude.py` - Claude implementation - `backend/app/services/provider_openai.py` - OpenAI implementation @@ -77,12 +79,16 @@ docker compose down # Health check curl http://localhost:8000/health +# Check auth status +curl http://localhost:8000/api/auth/status + # List available providers curl http://localhost:8000/api/chat/providers -# Test chat (non-streaming) +# Test chat (requires JWT token from auth flow) curl -X POST http://localhost:8000/api/chat \ -H "Content-Type: application/json" \ + -H "Authorization: Bearer YOUR_JWT_TOKEN" \ -d '{"message": "Hello!"}' ``` diff --git a/README.md b/README.md index 5a9b4fc..3385d3d 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ ### Prerequisites - Docker and Docker Compose installed - API key from [Anthropic](https://console.anthropic.com/) or [OpenAI](https://platform.openai.com/api-keys) +- Microsoft Entra ID app registration (for authentication) ### Setup @@ -21,15 +22,22 @@ cd devden 2. **Configure environment variables** ```bash cp .env.example .env -# Edit .env and add your API keys +# Edit .env and add your API keys and Entra ID credentials ``` -3. **Start the services** +3. **Set up Microsoft Entra ID** (Azure AD) + - Go to [Azure Portal - App Registrations](https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps) + - Create a new app registration + - Add redirect URI: `http://localhost:3000/auth/callback` + - Generate a client secret under "Certificates & secrets" + - Copy Tenant ID, Client ID, and Client Secret to your `.env` file + +4. **Start the services** ```bash docker compose up -d --build ``` -4. **Access DevDen** +5. **Access DevDen** - Frontend: http://localhost:3000 - Backend API: http://localhost:8000 - Health Check: http://localhost:8000/health @@ -37,10 +45,19 @@ docker compose up -d --build ### Environment Variables Required variables in `.env`: -``` +```bash +# AI Providers (at least one required) ANTHROPIC_API_KEY=your_key_here # For Claude OPENAI_API_KEY=your_key_here # For OpenAI DEFAULT_PROVIDER=claude # claude or openai + +# Microsoft Entra ID (required for authentication) +ENTRA_TENANT_ID=your-tenant-id +ENTRA_CLIENT_ID=your-client-id +ENTRA_CLIENT_SECRET=your-client-secret + +# JWT (change in production) +JWT_SECRET=generate-a-secure-random-string ``` ---