Social Login Setup Guide¶
This guide walks you through setting up social login providers for the OAuth2 server.
Google OAuth2 Setup¶
- Go to Google Cloud Console
- Create a new project or select an existing one
- Navigate to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth client ID"
- Configure the consent screen if prompted
- Select "Web application" as the application type
- Add authorized redirect URIs:
http://localhost:8080/auth/callback/google- Add your production URL when deploying
- Copy the Client ID and Client Secret
- Set environment variables:
export OAUTH2_GOOGLE_CLIENT_ID=your-client-id
export OAUTH2_GOOGLE_CLIENT_SECRET=your-client-secret
Microsoft/Azure AD Setup¶
- Go to Azure Portal
- Navigate to "Azure Active Directory" > "App registrations"
- Click "New registration"
- Enter application name and select account types
- Add redirect URI:
http://localhost:8080/auth/callback/microsoft - After creation, note the "Application (client) ID"
- Go to "Certificates & secrets" > "New client secret"
- Copy the secret value immediately (it won't be shown again)
- Set environment variables:
export OAUTH2_MICROSOFT_CLIENT_ID=your-client-id
export OAUTH2_MICROSOFT_CLIENT_SECRET=your-client-secret
export OAUTH2_MICROSOFT_TENANT_ID=common # or specific tenant ID
GitHub OAuth Setup¶
- Go to GitHub Settings
- Click "OAuth Apps" > "New OAuth App"
- Fill in application details:
- Application name: Your OAuth2 Server
- Homepage URL:
http://localhost:8080 - Authorization callback URL:
http://localhost:8080/auth/callback/github - Click "Register application"
- Generate a new client secret
- Copy the Client ID and Client Secret
- Set environment variables:
export OAUTH2_GITHUB_CLIENT_ID=your-client-id
export OAUTH2_GITHUB_CLIENT_SECRET=your-client-secret
Okta Setup¶
- Sign up for Okta Developer Account
- Go to "Applications" > "Create App Integration"
- Select "OIDC - OpenID Connect"
- Select "Web Application"
- Configure settings:
- Sign-in redirect URIs:
http://localhost:8080/auth/callback/okta - Sign-out redirect URIs:
http://localhost:8080 - Save and note the Client ID and Client Secret
- Note your Okta domain (e.g.,
dev-12345.okta.com) - Set environment variables:
export OAUTH2_OKTA_CLIENT_ID=your-client-id
export OAUTH2_OKTA_CLIENT_SECRET=your-client-secret
export OAUTH2_OKTA_DOMAIN=dev-12345.okta.com
Auth0 Setup¶
- Sign up for Auth0
- Go to "Applications" > "Create Application"
- Select "Regular Web Applications"
- Go to "Settings" tab
- Configure:
- Allowed Callback URLs:
http://localhost:8080/auth/callback/auth0 - Allowed Logout URLs:
http://localhost:8080 - Copy the Domain, Client ID, and Client Secret
- Set environment variables:
export OAUTH2_AUTH0_CLIENT_ID=your-client-id
export OAUTH2_AUTH0_CLIENT_SECRET=your-client-secret
export OAUTH2_AUTH0_DOMAIN=your-tenant.auth0.com
Testing Social Login¶
- Start the OAuth2 server:
cargo run
- Navigate to the login page:
http://localhost:8080/auth/login
-
Click on any social login button to test the integration
-
After successful authentication, you'll be redirected to the success page
Production Considerations¶
Security¶
- Always use HTTPS in production
- Store client secrets securely (use secret management services)
- Implement rate limiting
- Add CSRF protection (already included via session tokens)
- Validate redirect URIs strictly
Environment Variables¶
Create a .env file for local development (DO NOT commit this file):
# Server Configuration
OAUTH2_SERVER_HOST=127.0.0.1
OAUTH2_SERVER_PORT=8080
OAUTH2_DATABASE_URL=sqlite:oauth2.db
OAUTH2_JWT_SECRET=your-super-secret-jwt-key-minimum-32-characters
# Google
OAUTH2_GOOGLE_CLIENT_ID=your-google-client-id
OAUTH2_GOOGLE_CLIENT_SECRET=your-google-client-secret
# Microsoft
OAUTH2_MICROSOFT_CLIENT_ID=your-microsoft-client-id
OAUTH2_MICROSOFT_CLIENT_SECRET=your-microsoft-client-secret
OAUTH2_MICROSOFT_TENANT_ID=common
# GitHub
OAUTH2_GITHUB_CLIENT_ID=your-github-client-id
OAUTH2_GITHUB_CLIENT_SECRET=your-github-client-secret
# Okta
OAUTH2_OKTA_CLIENT_ID=your-okta-client-id
OAUTH2_OKTA_CLIENT_SECRET=your-okta-client-secret
OAUTH2_OKTA_DOMAIN=dev-12345.okta.com
# Auth0
OAUTH2_AUTH0_CLIENT_ID=your-auth0-client-id
OAUTH2_AUTH0_CLIENT_SECRET=your-auth0-client-secret
OAUTH2_AUTH0_DOMAIN=your-tenant.auth0.com
Docker Deployment¶
Update the docker-compose.yml to include environment variables:
oauth2_server:
environment:
- OAUTH2_GOOGLE_CLIENT_ID=${OAUTH2_GOOGLE_CLIENT_ID}
- OAUTH2_GOOGLE_CLIENT_SECRET=${OAUTH2_GOOGLE_CLIENT_SECRET}
# Add other providers as needed
Troubleshooting¶
Common Issues¶
- Redirect URI Mismatch
- Ensure the redirect URI configured in the provider matches exactly
-
Check for trailing slashes and protocol (http vs https)
-
CSRF Token Mismatch
- Clear browser cookies
-
Check session middleware configuration
-
Invalid Client Credentials
- Verify client ID and secret are correct
-
Check if credentials have expired or been revoked
-
Scope Errors
- Ensure required scopes are requested
- Check provider-specific scope requirements
Debug Logging¶
Enable debug logging to troubleshoot issues:
export RUST_LOG=debug
cargo run
Support¶
For issues or questions:
- Check the documentation
- Open an issue on GitHub
- Review provider-specific documentation