Overview
The API supports OAuth 2.0 authentication with three providers:- GitHub - OAuth authentication via GitHub
- Google - OpenID Connect authentication via Google
- Microsoft - OAuth authentication via Microsoft Azure AD
OAuth Flow
The OAuth authentication process follows these steps:- Initiate OAuth - Client calls
/auth/oauth/{provider}to get authorization URL - User Authorization - Redirect user to authorization URL
- Provider Callback - Provider redirects to
/auth/oauth/{provider}/callback - Token Exchange - Server exchanges authorization code for JWT access token
Endpoints
Initiate OAuth
Get the authorization URL to redirect users to the OAuth provider.GET
Path: /auth/oauth/{provider}
OAuth provider name:
github, google, or microsoftResponse
OAuth provider authorization URL to redirect the user to
Signed state token for CSRF protection (valid for 15 minutes)
OAuth Callback
Handle the OAuth provider callback and exchange authorization code for JWT access token.GET
Path: /auth/oauth/{provider}/callback
OAuth provider name:
github, google, or microsoftAuthorization code from OAuth provider
State token from initiate OAuth response
Response
JWT access token for API authentication
Token type (always “bearer”)
User UUID
User email address
User role name
Provider Details
GitHub OAuth
Authorization URL:https://github.com/login/oauth/authorize
Token URL: https://github.com/login/oauth/access_token
Scopes: user:email
Configuration:
GITHUB_CLIENT_ID- GitHub OAuth App client IDGITHUB_CLIENT_SECRET- GitHub OAuth App client secretGITHUB_REDIRECT_URI- OAuth callback URL
https://api.github.com/user and verified emails from https://api.github.com/user/emails.
Requirements:
- GitHub account must have a verified email
- If email is not public, the primary verified email is used
Google OAuth
Authorization URL: Retrieved from OpenID Connect discovery document Token URL: Retrieved from OpenID Connect discovery document Discovery URL:https://accounts.google.com/.well-known/openid-configuration
Scopes: openid email profile
Configuration:
GOOGLE_CLIENT_ID- Google OAuth 2.0 client IDGOOGLE_CLIENT_SECRET- Google OAuth 2.0 client secretGOOGLE_REDIRECT_URI- OAuth callback URL
- Google account email must be verified
- Fails with 400 error if email is not verified
Microsoft OAuth
Authorization URL:https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize
Token URL: https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token
Graph Endpoint: https://graph.microsoft.com/v1.0/me
Scopes: openid email profile User.Read
Configuration:
MICROSOFT_CLIENT_ID- Azure AD application client IDMICROSOFT_CLIENT_SECRET- Azure AD application client secretMICROSOFT_REDIRECT_URI- OAuth callback URLMICROSOFT_TENANT_ID- Azure AD tenant ID (defaults to “common” for multi-tenant)
mail field or falls back to userPrincipalName for email.
Requirements:
- Microsoft account must have email address (mail or userPrincipalName)
User Linking
When a user authenticates via OAuth:- Existing OAuth Identity - If provider + provider_user_id exists, log in as that user
- Existing Email - If email matches existing user, link OAuth identity to account
- New User - Create new user with OAuth identity and default “Basic User” role
State Validation
The OAuth state parameter is a signed JWT token that:- Prevents CSRF attacks
- Validates the provider matches
- Confirms the purpose is “login”
- Expires after 15 minutes
sub- Always “oauth_state”provider- Provider name (github, google, microsoft)purpose- Always “login”exp- Expiration timestampiat- Issued at timestamp
Error Handling
OAuth Initiation Errors
403 Forbidden - Provider is disabledOAuth Callback Errors
400 Bad Request - Invalid or expired stateImplementation Notes
Timeout Configuration
All HTTP requests to OAuth providers have a 30-second timeout.Discovery Document Caching
Google’s OpenID Connect discovery document is cached for 1 hour to reduce external API calls.Provider Registry
OAuth providers are registered insrc/api/auth/providers/__init__.py:7 via the PROVIDER_REGISTRY dictionary.
Next Steps
Authentication Overview
Learn about authentication concepts and flows
JWT Tokens
Understand JWT token structure and validation