Spaces:
Running on CPU Upgrade
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
- Go to Google Cloud Console
- Click "Select a project" β "NEW PROJECT"
- Enter project name:
open-navigator-for-engagement - Click "CREATE"
Step 2: Enable Google Identity Toolkit API
- Navigate to APIs & Services β Library
- Search for:
Google Identity Toolkit API - Click "ENABLE"
Step 3: Configure OAuth Consent Screen
Go to APIs & Services β OAuth consent screen
Select "External" user type β Click "CREATE"
Fill in app information:
- App name:
Open Navigator - User support email: Your email
- App domain:
www.communityone.com - Developer contact: Your email
- App name:
Click "SAVE AND CONTINUE"
Scopes page:
- Click "ADD OR REMOVE SCOPES"
- Select:
userinfo.email,userinfo.profile,openid - Click "UPDATE" β "SAVE AND CONTINUE"
Test users (optional for development):
- Add your Google account email
- Click "SAVE AND CONTINUE"
Step 4: Create OAuth Credentials
Go to APIs & Services β Credentials
Click "+ CREATE CREDENTIALS" β "OAuth client ID"
Configure:
- Application type: Web application
- Name:
Open Navigator Web App
Authorized JavaScript origins:
http://localhost:5173 http://localhost:8000 https://www.communityone.com https://your-space.hf.spaceAuthorized redirect URIs:
http://localhost:8000/auth/callback/google https://www.communityone.com/auth/callback/google https://your-space.hf.space/auth/callback/googleClick "CREATE"
Copy your credentials (you'll need these for environment variables):
- Client ID:
[long string].apps.googleusercontent.com - Client Secret:
GOCSPX-[random string]
- Client ID:
Step 5: Add to Environment Variables
Local (.env):
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
- Go to Facebook Developers
- Click "Create App"
- Choose "Other" β "Next" β "Consumer" β "Next"
- Enter details:
- App name:
Open Navigator - Contact email: Your email
- App name:
- Click "Create App"
Step 2: Add Facebook Login Product
- In app dashboard, find "Add Products"
- Find "Facebook Login" β Click "Set Up"
- Choose "Web" platform
- Enter site URL:
http://localhost:5173 - Click "Save" β "Continue"
Step 3: Configure OAuth Settings
Left sidebar: Click "Use cases β Authentication and account creation β Customize"
OR: "Facebook Login β Settings"
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/facebookEnable these settings:
- β Client OAuth Login: ON
- β Web OAuth Login: ON
- β Native or desktop app: OFF
Click "Save Changes"
Step 4: Configure App Settings
Left sidebar: Click "App settings β Basic"
App Domains:
localhost www.communityone.com your-space.hf.spacePrivacy Policy URL:
https://www.communityone.com/privacyfacebook.htmlClick "Save Changes"
Step 5: Get App Credentials
- Still in "App settings β Basic"
- Copy your credentials:
- App ID: 15-digit number
- App Secret: Click "Show" β 32-character string
Step 6: Add to Environment Variables
Local (.env):
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
- Go to GitHub Settings β Developer settings
- Click "OAuth Apps" β "New OAuth App"
Step 2: Configure Application
Fill in details:
- Application name:
Open Navigator - Homepage URL:
https://www.communityone.com - Authorization callback URL:
http://localhost:8000/auth/callback/github
- Application name:
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
On the OAuth app page:
- Client ID: 20-character string
- Client secrets: Click "Generate a new client secret"
Copy both values immediately (secret won't be shown again)
Step 5: Add to Environment Variables
Local (.env):
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
- Go to HuggingFace Settings β Applications
- Click "Create a new application"
Step 2: Configure Application
Fill in details:
- Application name:
Open Navigator - Homepage URL:
https://www.communityone.com - Scopes:
openid profile email
- Application name:
Redirect URIs (add all):
http://localhost:8000/auth/callback/huggingface https://www.communityone.com/auth/callback/huggingface https://your-space.hf.space/auth/callback/huggingfaceClick "Create application"
Step 3: Get Credentials
On the application page:
- Client ID: UUID format (8-4-4-4-12 characters)
- Client Secret: Long random string starting with
oauth_app_secret_
Copy both values
Step 4: Add to Environment Variables
Local (.env):
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:
# 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:
# 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
Start all services:
./start-all.shOpen application: http://localhost:5173
Test each provider:
- Click "Login" β Select provider
- Authorize the app
- Should redirect back with your profile
Check for errors in:
- Browser console (F12)
- API server logs
- Network tab (watch redirect flow)
Production Testing
Deploy to HuggingFace Spaces (see HuggingFace Deployment Guide)
Add all environment secrets in Space settings
Test each provider at https://www.communityone.com
Common issues:
- β 400 Bad Request β Redirect URI not registered
- β redirect_uri_mismatch β Using
http://instead ofhttps:// - β 401 Unauthorized β Wrong client secret or missing env vars
π§ Troubleshooting
"Redirect URI Mismatch"
Cause: OAuth provider doesn't recognize the callback URL
Fix:
- Check exact URL in error message
- Add that exact URL to provider settings
- Ensure
http://vshttps://matches - No trailing slashes
"Invalid Client"
Cause: Wrong client ID or secret
Fix:
- Verify credentials copied correctly
- Check for extra spaces
- Ensure environment variables are loaded
- 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:
# 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 - Database and JWT configuration
- HuggingFace Deployment - Deploy to production
- Environment Configuration - Full environment setup
π Security Best Practices
- Never commit secrets - Use
.envfiles (gitignored) - Use HTTPS in production - Required by OAuth providers
- Rotate secrets regularly - Generate new secrets periodically
- Limit OAuth scopes - Only request necessary permissions
- Use separate apps - Different OAuth apps for dev/staging/prod
- Monitor usage - Check OAuth app dashboards for suspicious activity
π Quick Reference
| Provider | Setup URL | Redirect URI Format |
|---|---|---|
| console.cloud.google.com | /auth/callback/google |
|
| developers.facebook.com | /auth/callback/facebook |
|
| GitHub | github.com/settings/developers | /auth/callback/github |
| HuggingFace | huggingface.co/settings/applications | /auth/callback/huggingface |
:::tip Start with one provider (e.g., Google) to verify the flow works, then add others incrementally. :::