Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 12,429 Bytes
61d29fc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 | ---
sidebar_position: 5
---
# OAuth Providers Setup
Complete guide to configuring OAuth authentication with Google, Facebook, GitHub, and HuggingFace for Open Navigator.
## Overview
This application supports four OAuth providers for user authentication:
- π΅ **Google** - Google Account authentication
- π΅ **Facebook** - Facebook Login
- β« **GitHub** - GitHub OAuth Apps
- π€ **HuggingFace** - HuggingFace OAuth
:::info
Each provider requires creating an OAuth application and configuring redirect URIs. **Never commit secrets to git!**
:::
---
## π Required Redirect URIs
For **all providers**, you need to configure these redirect URIs:
### Local Development
```
http://localhost:8000/auth/callback/{provider}
```
### Production (HTTPS required)
```
https://www.communityone.com/auth/callback/{provider}
https://your-space-name.hf.space/auth/callback/{provider}
```
Replace `{provider}` with: `google`, `facebook`, `github`, or `huggingface`
---
## π΅ Google OAuth Setup
### Step 1: Create Google Cloud Project
1. Go to [Google Cloud Console](https://console.cloud.google.com/)
2. Click "Select a project" β "NEW PROJECT"
3. Enter project name: `open-navigator-for-engagement`
4. Click "CREATE"
### Step 2: Enable Google Identity Toolkit API
1. Navigate to **APIs & Services β Library**
2. Search for: `Google Identity Toolkit API`
3. Click "ENABLE"
### Step 3: Configure OAuth Consent Screen
1. Go to **APIs & Services β OAuth consent screen**
2. Select **"External"** user type β Click "CREATE"
3. Fill in app information:
- **App name:** `Open Navigator`
- **User support email:** Your email
- **App domain:** `www.communityone.com`
- **Developer contact:** Your email
4. Click "SAVE AND CONTINUE"
5. **Scopes page:**
- Click "ADD OR REMOVE SCOPES"
- Select: `userinfo.email`, `userinfo.profile`, `openid`
- Click "UPDATE" β "SAVE AND CONTINUE"
6. **Test users** (optional for development):
- Add your Google account email
- Click "SAVE AND CONTINUE"
### Step 4: Create OAuth Credentials
1. Go to **APIs & Services β Credentials**
2. Click **"+ CREATE CREDENTIALS" β "OAuth client ID"**
3. Configure:
- **Application type:** Web application
- **Name:** `Open Navigator Web App`
4. **Authorized JavaScript origins:**
```
http://localhost:5173
http://localhost:8000
https://www.communityone.com
https://your-space.hf.space
```
5. **Authorized redirect URIs:**
```
http://localhost:8000/auth/callback/google
https://www.communityone.com/auth/callback/google
https://your-space.hf.space/auth/callback/google
```
6. Click **"CREATE"**
7. **Copy your credentials** (you'll need these for environment variables):
- Client ID: `[long string].apps.googleusercontent.com`
- Client Secret: `GOCSPX-[random string]`
### Step 5: Add to Environment Variables
**Local (`.env`):**
```bash
GOOGLE_CLIENT_ID=your-client-id-here.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=GOCSPX-your-secret-here
```
**HuggingFace Spaces:**
- Go to Space Settings β Variables and secrets
- Add as Repository secrets (not variables)
---
## π΅ Facebook OAuth Setup
### Step 1: Create Facebook App
1. Go to [Facebook Developers](https://developers.facebook.com/apps/)
2. Click **"Create App"**
3. Choose **"Other"** β **"Next"** β **"Consumer"** β **"Next"**
4. Enter details:
- **App name:** `Open Navigator`
- **Contact email:** Your email
5. Click **"Create App"**
### Step 2: Add Facebook Login Product
1. In app dashboard, find **"Add Products"**
2. Find **"Facebook Login"** β Click **"Set Up"**
3. Choose **"Web"** platform
4. Enter site URL: `http://localhost:5173`
5. Click "Save" β "Continue"
### Step 3: Configure OAuth Settings
1. **Left sidebar:** Click **"Use cases β Authentication and account creation β Customize"**
OR: **"Facebook Login β Settings"**
2. **Valid OAuth Redirect URIs** (one per line):
```
http://localhost:8000/auth/callback/facebook
https://www.communityone.com/auth/callback/facebook
https://your-space.hf.space/auth/callback/facebook
```
3. **Enable these settings:**
- β
Client OAuth Login: ON
- β
Web OAuth Login: ON
- β Native or desktop app: OFF
4. Click **"Save Changes"**
### Step 4: Configure App Settings
1. **Left sidebar:** Click **"App settings β Basic"**
2. **App Domains:**
```
localhost
www.communityone.com
your-space.hf.space
```
3. **Privacy Policy URL:**
```
https://www.communityone.com/privacyfacebook.html
```
4. Click **"Save Changes"**
### Step 5: Get App Credentials
1. Still in **"App settings β Basic"**
2. Copy your credentials:
- **App ID:** 15-digit number
- **App Secret:** Click "Show" β 32-character string
### Step 6: Add to Environment Variables
**Local (`.env`):**
```bash
FACEBOOK_APP_ID=your-app-id-here
FACEBOOK_APP_SECRET=your-app-secret-here
```
**HuggingFace Spaces:**
- Add as Repository secrets
### Step 7: App Mode
**Development Mode** (default):
- Only you can log in
- Good for testing
**Live Mode** (for production):
- Requires App Review
- Toggle in "App settings β Basic"
---
## β« GitHub OAuth Setup
### Step 1: Create OAuth App
1. Go to [GitHub Settings β Developer settings](https://github.com/settings/developers)
2. Click **"OAuth Apps"** β **"New OAuth App"**
### Step 2: Configure Application
1. Fill in details:
- **Application name:** `Open Navigator`
- **Homepage URL:** `https://www.communityone.com`
- **Authorization callback URL:** `http://localhost:8000/auth/callback/github`
2. Click **"Register application"**
### Step 3: Add Additional Callback URLs
GitHub only allows ONE callback URL per OAuth app. For multiple environments:
**Option 1:** Create separate apps for each environment
- Local Dev app β `http://localhost:8000/auth/callback/github`
- Production app β `https://www.communityone.com/auth/callback/github`
**Option 2:** Use production URL only
- Set: `https://www.communityone.com/auth/callback/github`
- For local dev, temporarily change to localhost during testing
### Step 4: Get Credentials
1. On the OAuth app page:
- **Client ID:** 20-character string
- **Client secrets:** Click "Generate a new client secret"
2. Copy both values immediately (secret won't be shown again)
### Step 5: Add to Environment Variables
**Local (`.env`):**
```bash
GITHUB_CLIENT_ID=your-client-id-here
GITHUB_CLIENT_SECRET=your-client-secret-here
```
**HuggingFace Spaces:**
- Add as Repository secrets
---
## π€ HuggingFace OAuth Setup
### Step 1: Create OAuth Application
1. Go to [HuggingFace Settings β Applications](https://huggingface.co/settings/applications)
2. Click **"Create a new application"**
### Step 2: Configure Application
1. Fill in details:
- **Application name:** `Open Navigator`
- **Homepage URL:** `https://www.communityone.com`
- **Scopes:** `openid profile email`
2. **Redirect URIs** (add all):
```
http://localhost:8000/auth/callback/huggingface
https://www.communityone.com/auth/callback/huggingface
https://your-space.hf.space/auth/callback/huggingface
```
3. Click **"Create application"**
### Step 3: Get Credentials
1. On the application page:
- **Client ID:** UUID format (8-4-4-4-12 characters)
- **Client Secret:** Long random string starting with `oauth_app_secret_`
2. Copy both values
### Step 4: Add to Environment Variables
**Local (`.env`):**
```bash
HUGGINGFACE_CLIENT_ID=your-client-id-here
HUGGINGFACE_CLIENT_SECRET=oauth_app_secret_your-secret-here
```
**HuggingFace Spaces:**
- Add as Repository secrets
---
## π Environment Variables Reference
### Local Development (`.env`)
Create a `.env` file in the project root:
```bash
# Database
DATABASE_URL=sqlite:///./data/users.db
# JWT Secret (generate with: openssl rand -hex 32)
JWT_SECRET_KEY=your-random-32-byte-hex-string
# Application URLs
FRONTEND_URL=http://localhost:5173
API_BASE_URL=http://localhost:8000
# Google OAuth
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
# Facebook OAuth
FACEBOOK_APP_ID=
FACEBOOK_APP_SECRET=
# GitHub OAuth
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=
# HuggingFace OAuth
HUGGINGFACE_CLIENT_ID=
HUGGINGFACE_CLIENT_SECRET=
```
:::warning
Never commit `.env` to git! It's already in `.gitignore`.
:::
### Production (HuggingFace Spaces)
Add these as **Repository secrets** in Space Settings β Variables and secrets:
```bash
# CRITICAL: Use HTTPS for production URLs
API_BASE_URL=https://www.communityone.com
FRONTEND_URL=https://www.communityone.com
# Database
DATABASE_URL=sqlite:///./data/users.db
# JWT Secret (same as local for consistency, or generate new)
JWT_SECRET_KEY=your-random-32-byte-hex-string
# OAuth Credentials (same as local)
GOOGLE_CLIENT_ID=...
GOOGLE_CLIENT_SECRET=...
FACEBOOK_APP_ID=...
FACEBOOK_APP_SECRET=...
GITHUB_CLIENT_ID=...
GITHUB_CLIENT_SECRET=...
HUGGINGFACE_CLIENT_ID=...
HUGGINGFACE_CLIENT_SECRET=...
```
:::danger
Production URLs **MUST** use `https://` - OAuth providers reject `http://` for security.
:::
---
## π§ͺ Testing OAuth Configuration
### Local Testing
1. **Start all services:**
```bash
./start-all.sh
```
2. **Open application:** http://localhost:5173
3. **Test each provider:**
- Click "Login" β Select provider
- Authorize the app
- Should redirect back with your profile
4. **Check for errors in:**
- Browser console (F12)
- API server logs
- Network tab (watch redirect flow)
### Production Testing
1. **Deploy to HuggingFace Spaces** (see [HuggingFace Deployment Guide](./huggingface-spaces.md))
2. **Add all environment secrets** in Space settings
3. **Test each provider** at https://www.communityone.com
4. **Common issues:**
- β 400 Bad Request β Redirect URI not registered
- β redirect_uri_mismatch β Using `http://` instead of `https://`
- β 401 Unauthorized β Wrong client secret or missing env vars
---
## π§ Troubleshooting
### "Redirect URI Mismatch"
**Cause:** OAuth provider doesn't recognize the callback URL
**Fix:**
1. Check exact URL in error message
2. Add that exact URL to provider settings
3. Ensure `http://` vs `https://` matches
4. No trailing slashes
### "Invalid Client"
**Cause:** Wrong client ID or secret
**Fix:**
1. Verify credentials copied correctly
2. Check for extra spaces
3. Ensure environment variables are loaded
4. Restart server after changing `.env`
### "Access Blocked"
**Cause:** App not verified or in development mode
**Fix:**
- **Google:** Add yourself as test user in OAuth consent screen
- **Facebook:** Use Development Mode for testing
- **GitHub:** No verification needed
- **HuggingFace:** No verification needed
### Production HTTPS Issues
**Cause:** Using `http://` URLs in production
**Fix:**
```bash
# In HuggingFace Spaces secrets, use HTTPS:
API_BASE_URL=https://www.communityone.com # β
Correct
API_BASE_URL=http://www.communityone.com # β Wrong
```
---
## π Related Documentation
- [Authentication Setup](./authentication-setup.md) - Database and JWT configuration
- [HuggingFace Deployment](./huggingface-spaces.md) - Deploy to production
- [Environment Configuration](../guides/environment-setup.md) - Full environment setup
---
## π Security Best Practices
1. **Never commit secrets** - Use `.env` files (gitignored)
2. **Use HTTPS in production** - Required by OAuth providers
3. **Rotate secrets regularly** - Generate new secrets periodically
4. **Limit OAuth scopes** - Only request necessary permissions
5. **Use separate apps** - Different OAuth apps for dev/staging/prod
6. **Monitor usage** - Check OAuth app dashboards for suspicious activity
---
## π Quick Reference
| Provider | Setup URL | Redirect URI Format |
|----------|-----------|---------------------|
| Google | [console.cloud.google.com](https://console.cloud.google.com/apis/credentials) | `/auth/callback/google` |
| Facebook | [developers.facebook.com](https://developers.facebook.com/apps/) | `/auth/callback/facebook` |
| GitHub | [github.com/settings/developers](https://github.com/settings/developers) | `/auth/callback/github` |
| HuggingFace | [huggingface.co/settings/applications](https://huggingface.co/settings/applications) | `/auth/callback/huggingface` |
---
:::tip
Start with one provider (e.g., Google) to verify the flow works, then add others incrementally.
:::
|