Overview
OAuth authentication is optional and can be enabled independently for each provider. Users can still register and log in with email/password even if OAuth is not configured.All OAuth providers are optional. You can enable one, all, or none of them based on your needs.
Google OAuth
Allow users to sign in with their Google accounts.Configuration
Google OAuth 2.0 Client ID.Example:
123456789-abc123def456.apps.googleusercontent.comGoogle OAuth 2.0 Client Secret.
Setup Steps
Create Google Cloud Project
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Enable the Google+ API (now part of Google Identity)
Configure OAuth Consent Screen
- Navigate to APIs & Services → OAuth consent screen
- Choose “External” user type (or “Internal” for Google Workspace)
- Fill in:
- App name: “ClassQuiz”
- User support email: Your email
- Developer contact: Your email
- Add scopes:
openid,email,profile - Save and continue
Create OAuth Credentials
- Go to APIs & Services → Credentials
- Click “Create Credentials” → “OAuth client ID”
- Application type: “Web application”
- Name: “ClassQuiz”
- Authorized redirect URIs:
- Click “Create”
- Copy the Client ID and Client Secret
Google OAuth Scopes
ClassQuiz requests the following OAuth scopes:openid- OpenID Connect authenticationemail- User’s email addressprofile- User’s basic profile information (name, avatar)
GitHub OAuth
Allow users to sign in with their GitHub accounts.Configuration
GitHub OAuth App Client ID.Example:
Iv1.1234567890abcdefGitHub OAuth App Client Secret.
Setup Steps
Create GitHub OAuth App
- Go to GitHub Settings → Developer settings → OAuth Apps
- Click “New OAuth App”
Configure OAuth App
Fill in the following details:
- Application name: ClassQuiz
- Homepage URL:
https://your-domain.com - Authorization callback URL:
https://your-domain.com/api/v1/users/oauth/github/auth - Application description: (optional)
Generate Client Secret
- On the OAuth App page, click “Generate a new client secret”
- Copy both the Client ID and Client Secret immediately
GitHub OAuth Scopes
ClassQuiz requests the following OAuth scopes:read:user- Read user profile informationuser:email- Access user’s email address
ClassQuiz requires users to have a public email address on their GitHub account. Users without a public email will see an error during authentication.
Custom OpenID Connect Provider
Connect to any OpenID Connect (OIDC) compatible identity provider such as:- Keycloak
- Auth0
- Okta
- Azure AD
- Any other OIDC-compliant provider
Configuration
Client ID for your OpenID Connect provider.
Note the double underscore (
__) in the variable name for nested configurationClient secret for your OpenID Connect provider.
URL to the OpenID Connect discovery document.Format:
https://your-provider.com/.well-known/openid-configurationExamples:- Keycloak:
https://keycloak.example.com/realms/myrealm/.well-known/openid-configuration - Auth0:
https://your-tenant.auth0.com/.well-known/openid-configuration - Azure AD:
https://login.microsoftonline.com/{tenant}/v2.0/.well-known/openid-configuration
Space-separated list of OAuth scopes to request.Default:
openid email profileSetup Steps
Configure your OIDC provider
- Create a new OAuth/OIDC client in your identity provider
- Set the redirect URI to:
https://your-domain.com/api/v1/users/oauth/custom/auth - Note the client ID and client secret
- Find the OpenID discovery URL (usually ends with
/.well-known/openid-configuration)
Custom Provider Examples
Complete OAuth Configuration Example
OAuth Redirect URLs
When configuring OAuth providers, use these redirect URLs:| Provider | Redirect URL |
|---|---|
https://your-domain.com/api/v1/users/oauth/google/auth | |
| GitHub | https://your-domain.com/api/v1/users/oauth/github/auth |
| Custom | https://your-domain.com/api/v1/users/oauth/custom/auth |
How OAuth Authentication Works
User authorizes
User logs in to the OAuth provider and authorizes ClassQuiz to access their profile information.
Token exchange
ClassQuiz exchanges the authorization code for an access token and retrieves user information.
User Account Linking
When a user signs in with OAuth:- A new account is created if the email doesn’t exist
- If an account with the same email exists but uses a different auth method, registration will fail
- Each OAuth provider creates a separate auth type (
GOOGLE,GITHUB,CUSTOM) - Users cannot link multiple OAuth providers to the same account
Troubleshooting
OAuth provider not showing on login page
OAuth provider not showing on login page
Check that both CLIENT_ID and CLIENT_SECRET are set for the provider. ClassQuiz only displays OAuth buttons for fully configured providers.Verify configuration:
Redirect URI mismatch
Redirect URI mismatch
Ensure the redirect URI configured in your OAuth provider exactly matches the format:Common issues:
- Missing or wrong protocol (http vs https)
- Trailing slash
- Wrong domain or ROOT_ADDRESS
User already exists error
User already exists error
This occurs when:
- A user with the same email is registered with a different auth method
- Trying to use a different OAuth provider with an email that’s already linked
Custom OpenID provider not working
Custom OpenID provider not working
Verify:
- The discovery URL returns valid JSON
- Your provider supports the required scopes
- The CLIENT_ID and CLIENT_SECRET are correct
- The redirect URI is registered in your provider
Email not provided by GitHub
Email not provided by GitHub
GitHub users must have a public email address. To fix:
- Go to GitHub Settings → Emails
- Ensure at least one email is public
- Or configure your GitHub OAuth App to request private emails
Security Considerations
- Store OAuth secrets securely using environment variables or secrets management
- Never commit CLIENT_SECRET values to version control
- Regularly rotate OAuth credentials
- Use the principle of least privilege when requesting OAuth scopes
- Monitor OAuth login logs for suspicious activity
- Implement rate limiting on OAuth endpoints
Next Steps
Email Configuration
Configure SMTP for email notifications
Environment Variables
View all configuration options