Authentication Setup Guide
Complete guide for setting up OAuth authentication with HuggingFace, Google, Facebook, and GitHub, plus Neon serverless PostgreSQL.
๐ฅ Database Setup: Neon (Serverless PostgreSQL)โ
Recommended Choice - Free tier, zero-config, perfect for production.
Why Neon?โ
โ
Free tier: 0.5 GB storage with scale-to-zero
โ
Managed backups: Point-in-time recovery included
โ
Encrypted: At rest + in transit
โ
Public internet: Perfect for HuggingFace Spaces
โ
Standard PostgreSQL: No vendor lock-in
โ
Enterprise backing: Acquired by Databricks (2025)
Setup Stepsโ
-
Sign up at neon.tech
- Click "Sign up" (free, no credit card required)
- Sign in with GitHub or email
-
Create a new project
- Click "New Project"
- Name:
open-navigator-engagement - Region: Choose closest to your users (e.g.,
US East) - PostgreSQL version: 16 (latest)
-
Copy connection string
- Go to Dashboard โ Connection Details
- Copy the "Connection string"
- Format:
postgresql://user:password@ep-xxx.us-east-2.aws.neon.tech/neondb?sslmode=require
-
Add to
.envfileDATABASE_URL=postgresql://user:password@ep-xxx.us-east-2.aws.neon.tech/neondb?sslmode=require -
Database auto-initialization
- Tables are created automatically on first API startup
- No migration scripts needed!
Verify Connectionโ
# Start the API server
source .venv/bin/activate
python main.py serve
# You should see:
# โ
Database initialized at: postgresql://...
๐ OAuth Provider Setupโ
1. HuggingFace OAuthโ
Get credentials: huggingface.co/settings/applications
Steps:โ
- Go to HuggingFace Settings โ Applications
- Click "Create an OAuth app"
- Fill in:
- Application name:
Open Navigator - Homepage URL:
https://www.communityone.com - Redirect URI:
- Development:
http://localhost:8000/auth/callback/huggingface - Production:
https://www.communityone.com/api/auth/callback/huggingface
- Development:
- Scopes:
openid profile email
- Application name:
- Click "Create"
- Copy Client ID and Client Secret
Add to .env:โ
HUGGINGFACE_CLIENT_ID=hf_oauth_xxx
HUGGINGFACE_CLIENT_SECRET=hf_oauth_secret_xxx
2. Google OAuthโ
Get credentials: console.cloud.google.com/apis/credentials
Steps:โ
-
Create a project (or select existing)
- Go to Google Cloud Console
- Select project or click "New Project"
- Name:
Open Navigator
-
Enable Google+ API
- Go to APIs & Services โ Library
- Search "Google+ API"
- Click Enable
-
Configure OAuth consent screen
- Go to APIs & Services โ OAuth consent screen
- User Type: External
- App name:
Open Navigator - User support email: Your email
- Developer contact: Your email
- Scopes:
email,profile,openid
-
Create OAuth 2.0 Client ID
- Go to APIs & Services โ Credentials
- Click "Create Credentials" โ OAuth client ID
- Application type: Web application
- Name:
Open Navigator Web Client - Authorized redirect URIs:
http://localhost:8000/auth/callback/google(development)https://www.communityone.com/api/auth/callback/google(production)
- Click "Create"
-
Copy Client ID and Client Secret
Add to .env:โ
GOOGLE_CLIENT_ID=123456789-xxxxx.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=GOCSPX-xxxxx
3. Facebook OAuthโ
Get credentials: developers.facebook.com/apps
Steps:โ
-
Create a new app
- Click "Create App"
- Type: Consumer
- App Name:
Open Navigator
-
Add Facebook Login
- Dashboard โ Add Product
- Select "Facebook Login" โ Set up
-
Configure OAuth settings
- Go to Facebook Login โ Settings
- Valid OAuth Redirect URIs:
http://localhost:8000/auth/callback/facebookhttps://www.communityone.com/api/auth/callback/facebook
- Client OAuth Login: Yes
- Web OAuth Login: Yes
-
Get App ID and Secret
- Go to Settings โ Basic
- Copy App ID and App Secret
Add to .env:โ
FACEBOOK_APP_ID=1234567890123456
FACEBOOK_APP_SECRET=xxxxxxxxxxxxx
4. GitHub OAuthโ
Get credentials: github.com/settings/developers
Steps:โ
-
Register new OAuth application
- Go to Settings โ Developer settings โ OAuth Apps
- Click "New OAuth App"
-
Fill in details
- Application name:
Open Navigator - Homepage URL:
https://www.communityone.com - Authorization callback URL:
- Development:
http://localhost:8000/auth/callback/github - Production:
https://www.communityone.com/api/auth/callback/github
- Development:
- Application name:
-
Create application
- Click "Register application"
- Copy Client ID
- Generate Client Secret and copy it
Add to .env:โ
GITHUB_CLIENT_ID=Iv1.xxxxxxxxxxxxx
GITHUB_CLIENT_SECRET=xxxxxxxxxxxxx
๐ Generate JWT Secretโ
Create a secure random secret for JWT tokens:
# Generate 32-byte random secret
openssl rand -hex 32
# Or use Python
python -c "import secrets; print(secrets.token_urlsafe(32))"
Add to .env:
JWT_SECRET_KEY=your_random_32_char_secret_here
๐ Environment Configurationโ
Development .env:โ
# Database
DATABASE_URL=postgresql://user:password@ep-xxx.us-east-2.aws.neon.tech/neondb?sslmode=require
# JWT
JWT_SECRET_KEY=your_random_secret_key
# Frontend URL
FRONTEND_URL=http://localhost:5173
# OAuth (all providers)
HUGGINGFACE_CLIENT_ID=hf_oauth_xxx
HUGGINGFACE_CLIENT_SECRET=hf_oauth_secret_xxx
GOOGLE_CLIENT_ID=123456789-xxx.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=GOCSPX-xxx
FACEBOOK_APP_ID=123456789
FACEBOOK_APP_SECRET=xxx
GITHUB_CLIENT_ID=Iv1.xxx
GITHUB_CLIENT_SECRET=xxx
Production (HuggingFace Spaces)โ
Add secrets in Space Settings โ Repository secrets:
| Secret Name | Value |
|---|---|
DATABASE_URL | postgresql://...neon.tech/... |
JWT_SECRET_KEY | Your random secret |
FRONTEND_URL | https://www.communityone.com |
HUGGINGFACE_CLIENT_ID | From HF OAuth app |
HUGGINGFACE_CLIENT_SECRET | From HF OAuth app |
GOOGLE_CLIENT_ID | From Google Cloud |
GOOGLE_CLIENT_SECRET | From Google Cloud |
FACEBOOK_APP_ID | From Facebook app |
FACEBOOK_APP_SECRET | From Facebook app |
GITHUB_CLIENT_ID | From GitHub OAuth app |
GITHUB_CLIENT_SECRET | From GitHub OAuth app |
๐งช Testing Authenticationโ
1. Start the API serverโ
source .venv/bin/activate
python main.py serve
2. Start the frontendโ
cd frontend
npm run dev
3. Test OAuth flowsโ
- Visit
http://localhost:5173 - Click "Login" in top-right
- Select a provider (HuggingFace, Google, Facebook, or GitHub)
- Complete OAuth flow
- You should be redirected back with your profile visible
4. Verify databaseโ
Check that user was created in Neon:
# Option 1: Neon SQL Editor (in dashboard)
SELECT * FROM users;
# Option 2: psql client
psql "postgresql://user:password@ep-xxx.neon.tech/neondb?sslmode=require"
\dt # List tables
SELECT * FROM users;
๐ Database Schemaโ
The authentication system creates these tables automatically:
users tableโ
| Column | Type | Description |
|---|---|---|
id | Integer | Primary key |
email | String(255) | User email (unique) |
username | String(100) | Optional username |
full_name | String(255) | Display name |
avatar_url | String(500) | Profile picture URL |
oauth_provider | String(50) | huggingface, google, facebook, github |
oauth_id | String(255) | Provider's user ID |
hashed_password | String(255) | For email/password (optional) |
is_active | Boolean | Account status |
is_verified | Boolean | Email verification status |
created_at | DateTime | Account creation |
updated_at | DateTime | Last update |
last_login | DateTime | Last login timestamp |
preferences | Text | User settings (JSON) |
oauth_states tableโ
| Column | Type | Description |
|---|---|---|
id | Integer | Primary key |
state_token | String(255) | CSRF protection token |
provider | String(50) | OAuth provider name |
redirect_uri | String(500) | Callback URL |
created_at | DateTime | Creation timestamp |
expires_at | DateTime | Expiration (10 minutes) |
๐ Security Best Practicesโ
โ DO:โ
- Use HTTPS in production
- Rotate JWT secrets regularly
- Keep OAuth secrets in environment variables (never commit to git)
- Use Neon's connection pooling
- Enable Neon's IP allowlist for production
โ DON'T:โ
- Commit
.envfile to git (it's in.gitignore) - Share OAuth secrets publicly
- Use weak JWT secrets
- Disable SSL mode on Neon connections
๐ Production Deploymentโ
HuggingFace Spacesโ
All environment variables are automatically loaded from Repository secrets.
Update OAuth redirect URIsโ
After deploying, update all OAuth apps with production callback URLs:
- HuggingFace:
https://www.communityone.com/api/auth/callback/huggingface - Google:
https://www.communityone.com/api/auth/callback/google - Facebook:
https://www.communityone.com/api/auth/callback/facebook - GitHub:
https://www.communityone.com/api/auth/callback/github
๐ Troubleshootingโ
Database connection failsโ
โ could not connect to server
Fix:
- Verify
DATABASE_URLis correct - Check Neon project is not suspended (free tier auto-suspends after inactivity)
- Ensure
?sslmode=requireis in connection string
OAuth redirect mismatchโ
โ redirect_uri_mismatch
Fix:
- Check redirect URI in OAuth app settings matches your server
- Ensure
http://vshttps://matches - Verify port number (
:8000for API)
JWT token invalidโ
โ Could not validate credentials
Fix:
- Ensure
JWT_SECRET_KEYis set and matches between sessions - Check token hasn't expired (7-day default)
- Clear browser localStorage and re-login
Tables not createdโ
โ relation "users" does not exist
Fix:
- Restart API server to trigger
init_db() - Check database connection is successful
- Manually run:
from api.database import init_db; init_db()
๐ Additional Resourcesโ
โ Checklistโ
Before going live, ensure:
- Neon database created and connected
- All 4 OAuth apps configured with production redirect URIs
- JWT secret generated (32+ characters)
- Environment variables added to HuggingFace Spaces secrets
- Database tables created (
users,oauth_states) - OAuth flows tested with all 4 providers
- HTTPS enabled on custom domain
- Neon IP allowlist configured (optional, for extra security)
Need help? Open an issue on GitHub