|
| 1 | +# Authentication & API Configuration Guide |
| 2 | + |
| 3 | +This guide helps administrators obtain all necessary API keys and configure authentication for the EmailBridge NLP app. |
| 4 | + |
| 5 | +## 📧 Email Provider Configuration |
| 6 | + |
| 7 | +### Gmail / Google Workspace Setup |
| 8 | + |
| 9 | +#### 1. Create Google Cloud Project |
| 10 | +1. Go to [Google Cloud Console](https://console.cloud.google.com/) |
| 11 | +2. Create a new project or select existing one |
| 12 | +3. Enable the **Gmail API**: |
| 13 | + - Go to "APIs & Services" > "Library" |
| 14 | + - Search for "Gmail API" |
| 15 | + - Click "Enable" |
| 16 | + |
| 17 | +#### 2. Configure OAuth 2.0 |
| 18 | +1. Go to "APIs & Services" > "Credentials" |
| 19 | +2. Click "Create Credentials" > "OAuth 2.0 Client IDs" |
| 20 | +3. Configure OAuth consent screen if prompted: |
| 21 | + - User Type: External (for general use) or Internal (for workspace) |
| 22 | + - Fill required fields (App name, User support email, Developer email) |
| 23 | + - Add scopes: `https://www.googleapis.com/auth/gmail.readonly`, `https://www.googleapis.com/auth/gmail.send` |
| 24 | +4. Create OAuth 2.0 Client ID: |
| 25 | + - Application type: **Web application** |
| 26 | + - Name: "EmailBridge NLP - Gmail" |
| 27 | + - Authorized redirect URIs: `https://your-rocketchat-server.com/api/apps/public/[app-id]/google-oauth-callback` |
| 28 | + |
| 29 | +#### 3. Get Credentials |
| 30 | +- Copy **Client ID** and **Client Secret** |
| 31 | +- Configure these in Rocket.Chat App Settings under "Google OAuth" |
| 32 | + |
| 33 | +### Outlook / Microsoft 365 Setup |
| 34 | + |
| 35 | +#### 1. Register Application in Azure Portal |
| 36 | +1. Go to [Azure Portal](https://portal.azure.com/) |
| 37 | +2. Navigate to "App registrations" |
| 38 | +3. Click "New registration" |
| 39 | +4. Configure: |
| 40 | + - Name: "EmailBridge NLP - Outlook" |
| 41 | + - Supported account types: "Accounts in any organizational directory and personal Microsoft accounts" |
| 42 | + - Redirect URI: Web - `https://your-rocketchat-server.com/api/apps/public/[app-id]/outlook-oauth-callback` |
| 43 | + |
| 44 | +#### 2. Configure API Permissions |
| 45 | +1. Go to "API permissions" in your app registration |
| 46 | +2. Add permissions: |
| 47 | + - **Microsoft Graph** > **Delegated permissions**: |
| 48 | + - `Mail.Read` - Read user mail |
| 49 | + - `Mail.Send` - Send mail as a user |
| 50 | + - `User.Read` - Sign in and read user profile |
| 51 | +3. Click "Grant admin consent" (if you're an admin) |
| 52 | + |
| 53 | +#### 3. Create Client Secret |
| 54 | +1. Go to "Certificates & secrets" |
| 55 | +2. Click "New client secret" |
| 56 | +3. Add description and set expiration |
| 57 | +4. Copy the **Value** (not the Secret ID) |
| 58 | + |
| 59 | +#### 4. Get Application Details |
| 60 | +- Copy **Application (client) ID** from "Overview" page |
| 61 | +- Copy **Client Secret** from previous step |
| 62 | +- Configure these in Rocket.Chat App Settings under "Outlook OAuth" |
| 63 | + |
| 64 | +## 🤖 LLM Provider Configuration |
| 65 | + |
| 66 | +### OpenAI Setup |
| 67 | + |
| 68 | +#### 1. Create OpenAI Account |
| 69 | +1. Go to [OpenAI Platform](https://platform.openai.com/) |
| 70 | +2. Sign up or sign in to your account |
| 71 | +3. Go to [API Keys page](https://platform.openai.com/api-keys) |
| 72 | + |
| 73 | +#### 2. Generate API Key |
| 74 | +1. Click "Create new secret key" |
| 75 | +2. Give it a name (e.g., "EmailBridge NLP") |
| 76 | +3. Copy the API key (starts with `sk-`) |
| 77 | +4. **Important**: Store this key securely - you won't be able to see it again |
| 78 | + |
| 79 | +#### 3. Configure Billing (Required) |
| 80 | +1. Go to [Billing page](https://platform.openai.com/account/billing) |
| 81 | +2. Add payment method |
| 82 | +3. Set usage limits if desired |
| 83 | + |
| 84 | +#### 4. App Configuration |
| 85 | +- Configure the API key in Rocket.Chat App Settings under "LLM Configuration" |
| 86 | +- Or users can configure personal API keys via `/email llm-config` |
| 87 | + |
| 88 | +### Google Gemini Setup |
| 89 | + |
| 90 | +#### 1. Get Gemini API Key |
| 91 | +1. Go to [Google AI Studio](https://aistudio.google.com/) |
| 92 | +2. Sign in with your Google account |
| 93 | +3. Click "Get API key" |
| 94 | +4. Create new API key or use existing project |
| 95 | +5. Copy the API key |
| 96 | + |
| 97 | +#### 2. App Configuration |
| 98 | +- Configure the API key in Rocket.Chat App Settings under "LLM Configuration" |
| 99 | +- Or users can configure personal API keys via `/email llm-config` |
| 100 | + |
| 101 | +### Groq Setup |
| 102 | + |
| 103 | +#### 1. Create Groq Account |
| 104 | +1. Go to [Groq Console](https://console.groq.com/) |
| 105 | +2. Sign up with your account |
| 106 | +3. Go to API Keys section |
| 107 | + |
| 108 | +#### 2. Generate API Key |
| 109 | +1. Click "Create API Key" |
| 110 | +2. Give it a name |
| 111 | +3. Copy the generated key |
| 112 | +4. Store securely |
| 113 | + |
| 114 | +#### 3. App Configuration |
| 115 | +- Configure the API key in Rocket.Chat App Settings under "LLM Configuration" |
| 116 | +- Or users can configure personal API keys via `/email llm-config` |
| 117 | + |
| 118 | +### Self-Hosted LLM Setup |
| 119 | + |
| 120 | +#### 1. Supported Formats |
| 121 | +The app supports OpenAI-compatible APIs, including: |
| 122 | +- **Ollama** (with OpenAI compatibility layer) |
| 123 | +- **LocalAI** |
| 124 | +- **OpenAI-compatible servers** |
| 125 | +- **Custom LLM APIs** |
| 126 | + |
| 127 | +#### 2. Requirements |
| 128 | +- Your LLM server must support OpenAI-compatible chat completions endpoint |
| 129 | +- Endpoint format: `POST /v1/chat/completions` |
| 130 | +- JSON request/response format matching OpenAI specification |
| 131 | + |
| 132 | +#### 3. Configuration |
| 133 | +1. In app settings or via `/email llm-config`, set: |
| 134 | + - **Provider**: Self-hosted |
| 135 | + - **URL**: Your LLM server URL (e.g., `http://localhost:11434` for Ollama) |
| 136 | +2. The app will automatically append `/v1/chat/completions` if needed |
| 137 | + |
| 138 | +#### 4. Example URLs |
| 139 | +- **Ollama**: `http://localhost:11434` |
| 140 | +- **LocalAI**: `http://localhost:8080` |
| 141 | +- **Custom server**: `https://your-llm-server.com:8000` |
| 142 | + |
| 143 | +## 🔧 Rocket.Chat App Configuration |
| 144 | + |
| 145 | +### Admin Settings |
| 146 | +1. Go to Administration > Apps > EmailBridge NLP > Settings |
| 147 | +2. Configure global settings: |
| 148 | + - **Google OAuth Client ID & Secret** |
| 149 | + - **Outlook OAuth Client ID & Secret** |
| 150 | + - **Default LLM Provider** |
| 151 | + - **Default LLM API Keys** |
| 152 | + |
| 153 | +### User Settings |
| 154 | +Users can override admin settings with personal configurations: |
| 155 | +- Use `/email config` for email provider preferences |
| 156 | +- Use `/email llm-config` for personal LLM settings |
| 157 | + |
| 158 | +## 🔒 Security Best Practices |
| 159 | + |
| 160 | +### API Key Management |
| 161 | +- **Never commit API keys to version control** |
| 162 | +- Use environment variables or secure storage |
| 163 | +- Rotate keys regularly |
| 164 | +- Monitor API usage and costs |
| 165 | +- Set usage limits where possible |
| 166 | + |
| 167 | +### OAuth Configuration |
| 168 | +- Use HTTPS for all redirect URIs |
| 169 | +- Verify redirect URI matches exactly |
| 170 | +- Configure appropriate scopes (minimum required) |
| 171 | +- Review and audit OAuth permissions regularly |
| 172 | + |
| 173 | +### App Permissions |
| 174 | +- Grant minimum required permissions |
| 175 | +- Review user access regularly |
| 176 | +- Monitor API usage logs |
| 177 | +- Configure rate limiting if available |
| 178 | + |
| 179 | +## 🆘 Troubleshooting |
| 180 | + |
| 181 | +### Common Issues |
| 182 | + |
| 183 | +#### "Invalid API Key" Errors |
| 184 | +- Verify API key is correct and not expired |
| 185 | +- Check if billing is configured (OpenAI) |
| 186 | +- Ensure API key has required permissions |
| 187 | + |
| 188 | +#### OAuth Redirect Errors |
| 189 | +- Verify redirect URI matches exactly (including http/https) |
| 190 | +- Check app ID in the callback URL |
| 191 | +- Ensure OAuth app is approved/published |
| 192 | + |
| 193 | +#### "Rate Limit Exceeded" |
| 194 | +- Check API usage limits |
| 195 | +- Upgrade plan if needed |
| 196 | +- Implement usage monitoring |
| 197 | + |
| 198 | +#### Self-hosted LLM Connection Issues |
| 199 | +- Verify server is running and accessible |
| 200 | +- Check URL format and endpoint availability |
| 201 | +- Test with curl/Postman first |
| 202 | +- Review server logs for errors |
| 203 | + |
| 204 | +### Getting Help |
| 205 | +- Check Rocket.Chat app logs in Administration > View Logs |
| 206 | +- Enable debug logging in app settings |
| 207 | +- Review provider-specific documentation |
| 208 | +- Open GitHub issue with detailed error information |
| 209 | + |
| 210 | +## 📋 Quick Setup Checklist |
| 211 | + |
| 212 | +### For Gmail Integration: |
| 213 | +- [ ] Google Cloud project created |
| 214 | +- [ ] Gmail API enabled |
| 215 | +- [ ] OAuth 2.0 credentials configured |
| 216 | +- [ ] Redirect URI added with correct app ID |
| 217 | +- [ ] Client ID & Secret added to app settings |
| 218 | + |
| 219 | +### For Outlook Integration: |
| 220 | +- [ ] Azure app registration created |
| 221 | +- [ ] Microsoft Graph permissions configured |
| 222 | +- [ ] Client secret generated |
| 223 | +- [ ] Application ID & Secret added to app settings |
| 224 | + |
| 225 | +### For LLM Integration: |
| 226 | +- [ ] LLM provider account created |
| 227 | +- [ ] API key generated |
| 228 | +- [ ] Billing configured (if required) |
| 229 | +- [ ] API key added to app settings or user config |
| 230 | +- [ ] Test query executed successfully |
| 231 | + |
| 232 | +## 🔗 Useful Links |
| 233 | + |
| 234 | +- [Google Cloud Console](https://console.cloud.google.com/) |
| 235 | +- [Azure Portal](https://portal.azure.com/) |
| 236 | +- [OpenAI Platform](https://platform.openai.com/) |
| 237 | +- [Google AI Studio](https://aistudio.google.com/) |
| 238 | +- [Groq Console](https://console.groq.com/) |
| 239 | +- [Rocket.Chat Apps Documentation](https://docs.rocket.chat/extend-rocket.chat/rocket.chat-marketplace/rocket.chat-public-apps-guides) |
0 commit comments