OAuth Setup
Configure OAuth providers like Google and GitHub for social login
OAuth Setup
Klubbil supports social login through OAuth providers like Google and GitHub. This guide will walk you through setting up these integrations.
GitHub OAuth Setup
Step 1: Create a GitHub OAuth App
- Go to GitHub Developer Settings
- Click New OAuth App
- Fill in the application details:
- Application name:
Klubbil
(or your preferred name) - Homepage URL:
https://yourdomain.com
(your Klubbil instance URL) - Authorization callback URL:
https://yourdomain.com/api/auth/callback/github
- Application name:
- Click Register application
Step 2: Get Client Credentials
After creating the OAuth app:
- Copy the Client ID from the app page
- Click Generate a new client secret and copy the Client Secret
- Keep these credentials secure - you'll need them for your environment variables
Step 3: Configure Environment Variables
Add the GitHub credentials to your .env
file:
GITHUB_CLIENT_ID=your_github_client_id_here
GITHUB_CLIENT_SECRET=your_github_client_secret_here
Step 4: Restart Your Application
After adding the environment variables, restart your Klubbil instance to apply the changes.
Google OAuth Setup
Step 1: Create a Google Cloud Project
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Enable the Google+ API for your project
Step 2: Configure OAuth Consent Screen
- Navigate to APIs & Services → OAuth consent screen
- Configure the consent screen with your application details:
- Application name:
Klubbil
- User support email: Your email address
- Developer contact information: Your email address
- Application name:
- Add your domain to Authorized domains
- Save and continue
Step 3: Create OAuth 2.0 Credentials
- Go to APIs & Services → Credentials
- Click Create Credentials → OAuth 2.0 Client IDs
- Select Web application as the application type
- Configure the settings:
- Name:
Klubbil Web Client
- Authorized JavaScript origins:
https://yourdomain.com
- Authorized redirect URIs:
https://yourdomain.com/api/auth/callback/google
- Name:
- Click Create
Step 4: Get Client Credentials
After creating the OAuth client:
- Copy the Client ID
- Copy the Client Secret
- Keep these credentials secure
Step 5: Configure Environment Variables
Add the Google credentials to your .env
file:
GOOGLE_CLIENT_ID=your_google_client_id_here
GOOGLE_CLIENT_SECRET=your_google_client_secret_here
Step 6: Restart Your Application
Restart your Klubbil instance to apply the changes.
Testing OAuth Integration
After configuring the OAuth providers:
- Navigate to the login page
- You should see "Sign in with Google" and "Sign in with GitHub" buttons
- Click on either button to test the OAuth flow
- Complete the authorization process
- You should be redirected back to Klubbil and logged in
Troubleshooting
Common Issues
"OAuth provider not configured" error
- Ensure environment variables are set correctly
- Restart your application after adding environment variables
- Check that variable names match exactly:
GITHUB_CLIENT_ID
,GITHUB_CLIENT_SECRET
, etc.
"Invalid redirect URI" error
- Verify the callback URL in your OAuth app settings matches your domain
- For GitHub:
https://yourdomain.com/api/auth/callback/github
- For Google:
https://yourdomain.com/api/auth/callback/google
OAuth flow starts but fails to complete
- Check your client secret is correct and hasn't expired
- Ensure your OAuth app is not in development mode (for production use)
- Verify your domain is authorized in the OAuth app settings
Development vs Production
For development:
- Use
http://localhost:3000
as your domain - Callback URLs should be
http://localhost:3000/api/auth/callback/[provider]
For production:
- Use your actual domain
https://yourdomain.com
- Ensure HTTPS is enabled
- Update callback URLs to use HTTPS
Security Considerations
- Keep your OAuth client secrets secure and never commit them to version control
- Use different OAuth apps for development and production environments
- Regularly rotate client secrets for enhanced security
- Monitor OAuth app usage in provider dashboards for suspicious activity