OAuth Login Configuration Guide
This document explains how to configure Google and Microsoft OAuth login for VoiceAssist.
Overview
VoiceAssist supports OAuth 2.0 authentication with:
- Google (Google Sign-In)
- Microsoft (Microsoft Entra ID / Azure AD)
When configured, users can sign in using their existing Google or Microsoft accounts instead of creating a separate password.
Environment Variables
Add these environment variables to your .env file or deployment configuration:
Google OAuth
# Google OAuth (optional - leave empty to disable) GOOGLE_CLIENT_ID=your-google-client-id.apps.googleusercontent.com GOOGLE_CLIENT_SECRET=your-google-client-secret GOOGLE_OAUTH_REDIRECT_URI=https://your-domain.com/auth/callback/google
Microsoft OAuth
# Microsoft OAuth (optional - leave empty to disable) MICROSOFT_CLIENT_ID=your-microsoft-application-client-id MICROSOFT_CLIENT_SECRET=your-microsoft-client-secret MICROSOFT_OAUTH_REDIRECT_URI=https://your-domain.com/auth/callback/microsoft
Setting Up OAuth Providers
Google OAuth 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
- Select Web application as the application type
- Configure authorized redirect URIs:
- For development:
http://localhost:5173/auth/callback/google - For production:
https://your-domain.com/auth/callback/google
- For development:
- Copy the Client ID and Client Secret to your environment variables
Microsoft OAuth Setup
- Go to Azure Portal
- Navigate to Microsoft Entra ID > App registrations
- Click New registration
- Enter a name for your application
- Select supported account types (typically "Accounts in any organizational directory and personal Microsoft accounts")
- Add redirect URI:
- Platform: Web
- For development:
http://localhost:5173/auth/callback/microsoft - For production:
https://your-domain.com/auth/callback/microsoft
- Under Certificates & secrets, create a new client secret
- Copy the Application (client) ID and client secret value to your environment variables
API Endpoints
Get OAuth Authorization URL
GET /api/auth/oauth/{provider}/authorize
Parameters:
provider:googleormicrosoft
Response (200 OK):
{ "success": true, "data": { "url": "https://accounts.google.com/o/oauth2/v2/auth?...", "state": "random-csrf-state-token" }, "error": null, "metadata": {...}, "timestamp": "2024-01-15T10:00:00.000Z" }
Response (503 Service Unavailable): When provider is not configured:
{ "detail": "Google OAuth is not configured. Please contact the administrator." }
OAuth Callback
POST /api/auth/oauth/{provider}/callback
Parameters:
provider:googleormicrosoft
Request Body:
{ "code": "authorization-code-from-provider" }
Response (200 OK):
{ "access_token": "jwt-access-token", "refresh_token": "jwt-refresh-token", "token_type": "bearer", "expires_in": 900 }
Check Provider Status
GET /api/auth/oauth/{provider}/status
Response:
{ "success": true, "data": { "provider": "google", "configured": true, "enabled": true }, "error": null, "metadata": {...}, "timestamp": "2024-01-15T10:00:00.000Z" }
Frontend Integration
The frontend OAuth flow works as follows:
- User clicks "Sign in with Google" or "Sign in with Microsoft"
- Frontend calls
GET /api/auth/oauth/{provider}/authorize - Frontend receives the authorization URL and redirects the browser to it
- User authenticates with the provider
- Provider redirects back to
/auth/callback/{provider}?code=... - Frontend extracts the code and calls
POST /api/auth/oauth/{provider}/callback - Backend exchanges code for tokens and creates/finds the user
- Backend returns JWT tokens
- Frontend stores tokens and redirects to the app
User Account Behavior
New Users
When a user signs in via OAuth for the first time:
- A new account is created using their email from the OAuth provider
- The user's name is taken from the provider profile
- No password is set (OAuth-only account)
Existing Users
If a user with the same email already exists:
- The OAuth provider is linked to the existing account
- User can now sign in with either method (password or OAuth)
Account Security
- OAuth accounts without passwords cannot use password-based login
- OAuth provider ID is stored to prevent account hijacking
- Users cannot change their email to another user's OAuth-linked email
Troubleshooting
"OAuth not configured" Error
- Verify the environment variables are set correctly
- Ensure both
CLIENT_IDandCLIENT_SECRETare provided - Restart the API server after changing environment variables
"Failed to exchange authorization code"
- Check that the redirect URI matches exactly (including trailing slashes)
- Verify the client secret is correct
- Check server logs for detailed error messages
User Not Found After OAuth
- Check that the email scope is included in the OAuth request
- Verify the provider returned an email address
- Check server logs for user creation errors
Running Tests
Run the OAuth integration tests:
cd services/api-gateway source venv/bin/activate pytest tests/integration/test_auth_oauth.py -v
Security Considerations
- State Parameter: The authorize endpoint generates a random state parameter for CSRF protection
- HTTPS Required: OAuth redirect URIs must use HTTPS in production
- Secret Storage: Never commit OAuth secrets to version control
- Token Validation: All tokens from OAuth providers are validated before use
- Rate Limiting: OAuth endpoints have rate limits to prevent abuse