Facebook OAuth Setup
This guide walks you through setting up Facebook OAuth authentication for your UIGen application.
Prerequisites
- A Facebook account
- Your UIGen application's redirect URI (e.g.,
http://localhost:3000/auth/callbackfor development)
Step 1: Create a Facebook App
- Go to Facebook for Developers
- Click My Apps in the top navigation
- Click Create App
- Select Consumer as the app type (for user authentication)
- Click Next
Step 2: Configure Basic App Settings
Fill in the app details:
Display Name:
- Enter your application name (e.g., "My UIGen App")
- This name will be shown to users during login
App Contact Email:
- Enter your email address for Facebook to contact you
App Purpose (Optional):
- Select the purpose that best describes your app
Click Create App
Step 3: Add Facebook Login Product
- In your app dashboard, find Facebook Login in the products list
- Click Set Up on the Facebook Login card
- Select Web as your platform
- Enter your site URL:
- Development:
http://localhost:3000 - Production:
https://yourdomain.com
- Development:
- Click Save and Continue
Step 4: Configure OAuth Settings
- In the left sidebar, go to Facebook Login > Settings
- Configure the following settings:
Client OAuth Login: Enable (toggle ON)
Web OAuth Login: Enable (toggle ON)
Valid OAuth Redirect URIs:
- Add your redirect URIs (one per line):
- Development:
http://localhost:3000/auth/callback - Production:
https://yourdomain.com/auth/callback
- Development:
Login with the JavaScript SDK: Enable (toggle ON)
- Click Save Changes
Step 5: Get Your App Credentials
- In the left sidebar, go to Settings > Basic
- You'll see your app credentials:
- App ID: Copy this value - you'll need it for UIGen configuration
- App Secret: Click Show to reveal (keep this secure)
Step 6: Configure App Domains
- Still in Settings > Basic
- Scroll to App Domains
- Add your domains (without protocol):
- Development:
localhost - Production:
yourdomain.com
- Development:
- Click Save Changes
Step 7: Configure UIGen
Add the Facebook OAuth provider to your OpenAPI spec:
openapi: 3.0.0
info:
title: My API
version: 1.0.0
x-uigen-auth:
providers:
- provider: facebook
clientId: ${FACEBOOK_CLIENT_ID}
redirectUri: ${FACEBOOK_REDIRECT_URI}
scopes:
- email
- public_profile
Step 8: Set Environment Variables
Create a .env file or set environment variables:
export FACEBOOK_CLIENT_ID="1234567890123456"
export FACEBOOK_REDIRECT_URI="http://localhost:3000/auth/callback"
Step 9: Test Your Integration
-
Start your UIGen application:
npx @uigen-dev/cli serve openapi.yaml -
Navigate to
http://localhost:3000 -
Click the Continue with Facebook button
-
You should be redirected to Facebook's login page
-
Sign in with your Facebook account
-
Grant the requested permissions
-
You should be redirected back to your application and logged in
Scopes Explained
Default Scopes
UIGen requests these scopes by default:
| Scope | Description | Data Accessed |
|---|---|---|
email |
Email address | User's primary email address |
public_profile |
Public profile information | Name, profile picture, age range, gender |
Additional Scopes
You can request additional scopes if needed (requires app review):
| Scope | Description | Use Case | Review Required |
|---|---|---|---|
user_friends |
Friends list | Social features | Yes |
user_birthday |
Birthday | Age verification | Yes |
user_location |
Location | Location-based features | Yes |
user_photos |
Photos | Photo integration | Yes |
pages_show_list |
Pages managed | Page management | Yes |
See Facebook Permissions Reference for a complete list.
App Review Process
When Review Is Required
Facebook requires app review for:
- Apps requesting permissions beyond
emailandpublic_profile - Apps used by more than a few test users
- Apps going to production
How to Submit for Review
- In your app dashboard, go to App Review > Permissions and Features
- Click Request Advanced Access for the permissions you need
- Provide:
- Detailed description of how you use each permission
- Step-by-step instructions for reviewers
- Screencast demonstrating the feature
- Submit for review (typically takes 3-7 days)
Development Mode vs Live Mode
Development Mode:
- Only app admins, developers, and testers can use the app
- No app review required
- Suitable for testing
Live Mode:
- Available to all Facebook users
- Requires app review for advanced permissions
- Required for production
To switch to Live Mode:
- Complete app review (if needed)
- Go to Settings > Basic
- Toggle App Mode to Live
Production Checklist
Before deploying to production:
- Complete Facebook app review (if requesting advanced permissions)
- Switch app to Live Mode
- Update redirect URI to your production domain
- Add production domain to App Domains
- Store App ID securely (environment variables, secrets manager)
- Never commit App Secret to version control
- Enable HTTPS for your production domain
- Test the complete OAuth flow in production
- Add Privacy Policy URL in app settings
- Add Terms of Service URL in app settings
- Configure Data Deletion Request URL (GDPR compliance)
Troubleshooting
"redirect_uri_mismatch" Error
Problem: The redirect URI doesn't match what's configured in Facebook app settings.
Solution:
- Check that the redirect URI in your OpenAPI spec exactly matches the one in Facebook Login Settings
- Ensure there are no trailing slashes
- Verify protocol (http vs https) matches
- Facebook requires exact match including protocol and path
"Can't Load URL: The domain of this URL isn't included in the app's domains"
Problem: Your domain is not listed in App Domains.
Solution:
- Go to Settings > Basic
- Add your domain to App Domains (without protocol)
- Save changes and try again
"App Not Set Up: This app is still in development mode"
Problem: App is in development mode and user is not a tester.
Solution:
- For testing: Add user as a tester in Roles > Testers
- For production: Complete app review and switch to Live Mode
Email Not Returned
Problem: User's email is not included in the profile data.
Solution:
- Ensure you're requesting the
emailscope - User must have a verified email address on Facebook
- User must grant email permission during authorization
- Some users may not have an email associated with their Facebook account
"This app has not been approved for login with Facebook"
Problem: App requires review but hasn't been approved yet.
Solution:
- Submit app for review with required permissions
- Wait for approval (typically 3-7 days)
- Or add users as testers for development
"Invalid OAuth access token"
Problem: Access token has expired or been revoked.
Solution:
- UIGen automatically attempts token refresh
- If refresh fails, user will be redirected to login
- User may have revoked app access in Facebook settings
Security Best Practices
- Never expose App Secret: Keep App Secret server-side only
- Use HTTPS in production: Always use HTTPS for production redirect URIs
- Validate state parameter: UIGen automatically validates the state parameter for CSRF protection
- Request minimum scopes: Only request the scopes your application actually needs
- Implement data deletion: Provide a data deletion callback URL for GDPR compliance
- Monitor access: Regularly review app analytics in Facebook dashboard
Data Deletion Callback (GDPR Compliance)
Facebook requires apps to implement a data deletion callback:
-
Create an endpoint that handles data deletion requests:
POST https://yourdomain.com/facebook/data-deletion -
Add the URL in Settings > Basic > Data Deletion Request URL
-
Implement the endpoint to:
- Verify the signed request from Facebook
- Delete user data from your database
- Return confirmation
Example response:
{
"url": "https://yourdomain.com/deletion-status?id=12345",
"confirmation_code": "abc123"
}
Managing Test Users
Add Test Users
- Go to Roles > Test Users
- Click Add
- Enter number of test users to create
- Click Create Test Users
Add Real Users as Testers
- Go to Roles > Testers
- Click Add Testers
- Enter Facebook user IDs or usernames
- Click Submit
- Users must accept the tester invitation
User Experience Tips
- Clear app name: Use a descriptive name that users will recognize
- Add app icon: Upload a 1024x1024 icon in Settings > Basic
- Provide privacy policy: Required for app review and user trust
- Request minimal permissions: Users are more likely to authorize apps requesting fewer permissions
- Explain permission usage: Tell users why you need each permission
Facebook Login Button Guidelines
Facebook provides design guidelines for login buttons:
Recommended:
- Use Facebook blue (#1877F2)
- Include Facebook logo
- Text: "Continue with Facebook" or "Log in with Facebook"
- Minimum height: 40px
Not Allowed:
- Don't modify the Facebook logo
- Don't use "Sign in with Facebook" (use "Log in" or "Continue")
- Don't make the button smaller than 40px height
UIGen follows these guidelines automatically.
Next Steps
- Microsoft OAuth Setup - Set up Microsoft OAuth
- OAuth Security Best Practices - Learn about OAuth security
- OAuth Troubleshooting - Common issues and solutions