Overview
TrailBase supports OAuth 2.0 authentication with popular identity providers. Users can sign in with their existing accounts from Google, GitHub, Microsoft, and other providers.Supported Providers
TrailBase includes built-in support for:Google OAuth 2.0
GitHub
GitHub OAuth
Microsoft
Microsoft Azure AD
GitLab
GitLab OAuth
Facebook Login
Discord
Discord OAuth 2.0
Twitch
Twitch Authentication
Yandex
Yandex OAuth
Apple
Sign in with Apple
OIDC
Custom OpenID Connect
Configuration
Basic Provider Configuration
Provider Setup Guides
Google OAuth
Create OAuth Client
- Go to Google Cloud Console
- Create a new project or select existing
- Navigate to “APIs & Services” → “Credentials”
- Click “Create Credentials” → “OAuth client ID”
- Choose “Web application”
GitHub OAuth
Create OAuth App
- Go to GitHub Developer Settings
- Click “New OAuth App”
- Fill in application details
Microsoft Azure AD
Register Application
- Go to Azure Portal
- Navigate to “Azure Active Directory” → “App registrations”
- Click “New registration”
- Name your application
Create Client Secret
- Go to “Certificates & secrets”
- Click “New client secret”
- Copy the secret value immediately
Discord
Create Application
- Go to Discord Developer Portal
- Click “New Application”
- Go to “OAuth2” settings
GitLab
https://yourdomain.com/api/auth/v1/oauth/gitlab/callback
Custom OIDC Provider
For providers not explicitly supported, use OpenID Connect:OAuth Flow
TrailBase implements the OAuth 2.0 authorization code flow with PKCE:Security Features
PKCE (Proof Key for Code Exchange)
TrailBase uses PKCE for all OAuth flows:State Parameter
Prevents CSRF attacks by validating state:User Linking
Users can link multiple OAuth providers to one account:API Endpoints
Initiate OAuth Flow
redirect_url(optional): Where to redirect after successful auth
OAuth Callback
- Validates state parameter
- Exchanges authorization code for access token
- Fetches user profile
- Creates or updates user
- Sets session cookies
- Redirects to
redirect_urlor default page
List Available Providers
Frontend Integration
Sign In Buttons
React Component
User Profile Data
OAuth providers return different user information:Admin API
List Available OAuth Providers
Provider Implementation
Each provider implements theOAuthProvider trait:
Troubleshooting
Redirect URI mismatch
Redirect URI mismatch
Error: “redirect_uri_mismatch”Solution: Ensure the callback URL in your provider settings exactly matches:Check:
- Protocol (http vs https)
- Domain name
- Port (if not 80/443)
- Path (including
/callback)
No site_url configured
No site_url configured
Error: “OAuth requires a public URL”Solution: Add
site_url to your config:Invalid client credentials
Invalid client credentials
Error: “invalid_client”Solution:
- Verify client_id is correct
- Ensure client_secret hasn’t expired
- Check provider dashboard for any issues
- Regenerate credentials if necessary
Scope issues
Scope issues
Error: User data missing (email, name, etc.)Solution: Check OAuth scopes. TrailBase requests:
- Google:
openid email profile - GitHub:
user:email - Discord:
identify email
Best Practices
Use HTTPS in production
OAuth requires HTTPS for redirect URIs in production. Use certificates from Let’s Encrypt or your provider.
Handle provider outages
Implement fallback authentication methods (email/password) in case OAuth providers are unavailable.
Next Steps
Configure email for fallback auth
Custom Endpoints
Build custom auth flows
Object Storage
Store user avatars
Jobs Scheduler
Sync OAuth data