Skip to main content

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

Google OAuth 2.0

GitHub

GitHub OAuth

Microsoft

Microsoft Azure AD

GitLab

GitLab OAuth

Facebook

Facebook Login

Discord

Discord OAuth 2.0

Twitch

Twitch Authentication

Yandex

Yandex OAuth

Apple

Sign in with Apple

OIDC

Custom OpenID Connect

Configuration

OAuth requires a public URL for redirects. Configure server.site_url in your config:

Basic Provider Configuration

Provider Setup Guides

Google OAuth

1

Create OAuth Client

  1. Go to Google Cloud Console
  2. Create a new project or select existing
  3. Navigate to “APIs & Services” → “Credentials”
  4. Click “Create Credentials” → “OAuth client ID”
  5. Choose “Web application”
2

Configure Redirect URIs

Add authorized redirect URI:
3

Add to Configuration

GitHub OAuth

1

Create OAuth App

  1. Go to GitHub Developer Settings
  2. Click “New OAuth App”
  3. Fill in application details
2

Set Callback URL

3

Configure TrailBase

Microsoft Azure AD

1

Register Application

  1. Go to Azure Portal
  2. Navigate to “Azure Active Directory” → “App registrations”
  3. Click “New registration”
  4. Name your application
2

Configure Redirect URI

Under “Authentication”, add:
3

Create Client Secret

  1. Go to “Certificates & secrets”
  2. Click “New client secret”
  3. Copy the secret value immediately
4

Add to TrailBase

Discord

1

Create Application

  1. Go to Discord Developer Portal
  2. Click “New Application”
  3. Go to “OAuth2” settings
2

Add Redirect

3

Configure

GitLab

Redirect URI: 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

Redirects user to provider’s authorization page. Query Parameters:
  • redirect_url (optional): Where to redirect after successful auth
Example:

OAuth Callback

Handles the callback from OAuth provider. Automatically processes:
  1. Validates state parameter
  2. Exchanges authorization code for access token
  3. Fetches user profile
  4. Creates or updates user
  5. Sets session cookies
  6. Redirects to redirect_url or default page

List Available Providers

Response:

Frontend Integration

Sign In Buttons

React Component

User Profile Data

OAuth providers return different user information:

Admin API

List Available OAuth Providers

Response:

Provider Implementation

Each provider implements the OAuthProvider trait:

Troubleshooting

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)
Error: “OAuth requires a public URL”Solution: Add site_url to your config:
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
Error: User data missing (email, name, etc.)Solution: Check OAuth scopes. TrailBase requests:
  • Google: openid email profile
  • GitHub: user:email
  • Discord: identify email
Ensure these scopes are approved in your OAuth app settings.

Best Practices

1

Use HTTPS in production

OAuth requires HTTPS for redirect URIs in production. Use certificates from Let’s Encrypt or your provider.
2

Rotate secrets regularly

Periodically regenerate client secrets and update your configuration.
3

Request minimal scopes

Only request the OAuth scopes your application actually needs.
4

Handle provider outages

Implement fallback authentication methods (email/password) in case OAuth providers are unavailable.
5

Test thoroughly

Test OAuth flows in development before deploying to production.

Next Steps

Email

Configure email for fallback auth

Custom Endpoints

Build custom auth flows

Object Storage

Store user avatars

Jobs Scheduler

Sync OAuth data