Overview
OAuth2 provides flexible authentication for identity providers that don’t support OpenID Connect (OIDC). While OIDC is recommended when available, OAuth2 allows you to integrate with providers that only offer OAuth2 endpoints.When to use OAuth2
Use OAuth2 instead of OIDC when:- Your identity provider doesn’t support OIDC
- You need custom user attribute mapping
- You’re integrating with legacy authentication systems
- Your provider requires non-standard OAuth2 flows
If your provider supports OIDC, use the OIDC configuration instead. OIDC provides standardized user information and better security.
Configuration via admin UI
1
Navigate to SSO providers
Go to Admin → SSO Providers in your dashboard
2
Add OAuth2 provider
Click “Add Provider” and select “OAuth2” as the provider type
3
Enter basic information
4
Configure OAuth2 settings
5
Configure attribute mapping
Map OAuth2 response fields to user attributes
6
Save and test
Save the configuration and test the login flow
Required configuration fields
| Field | Description | Required | Example |
|---|---|---|---|
| Authorization URL | OAuth2 authorization endpoint | Yes | https://provider.com/oauth/authorize |
| Token URL | OAuth2 token exchange endpoint | Yes | https://provider.com/oauth/token |
| User info URL | Endpoint to fetch user profile | Yes | https://provider.com/api/user |
| Client ID | OAuth2 client identifier | Yes | abc123xyz |
| Client secret | OAuth2 client secret | Yes | secret_abc123 |
| Scopes | Space-separated OAuth2 scopes | No | user:email profile |
Provider-specific guides
GitHub
1
Create OAuth App
- Go to GitHub Settings
- Click “OAuth Apps” → “New OAuth App”
- Fill in application details
2
Configure callback URL
3
Get credentials
Copy the Client ID and generate a Client secret
4
Configure in admin UI
5
Configure attribute mapping
GitHub requires the
user:email scope to access the user’s email address. Without this scope, email will not be available.GitLab
1
Create OAuth application
- Go to GitLab → User Settings → Applications
- Click “Add new application”
- Enter application details
2
Configure scopes and redirect URI
3
Save and get credentials
Copy the Application ID and Secret
4
Configure in admin UI
5
Configure attribute mapping
Slack
1
Create Slack app
- Go to Slack API
- Click “Create New App”
- Choose “From scratch”
- Enter app name and workspace
2
Configure OAuth & Permissions
- Go to “OAuth & Permissions”
- Add redirect URL:
3
Add OAuth scopes
Under “User Token Scopes”, add:
4
Get credentials
Go to “Basic Information” and copy:
- Client ID
- Client Secret
5
Configure in admin UI
6
Configure attribute mapping
Discord
1
Create Discord application
- Go to Discord Developer Portal
- Click “New Application”
- Enter application name
2
Configure OAuth2
- Go to OAuth2 settings
- Add redirect:
3
Get credentials
Copy the Client ID and Client Secret from the OAuth2 page
4
Configure in admin UI
5
Configure attribute mapping
Attribute mapping
OAuth2 providers return user information in different formats. Configure attribute mapping to extract user data from the provider’s response.Common mapping patterns
| Provider Field | Application Field | Description |
|---|---|---|
email | User’s email address | |
name | Full name | User’s display name |
given_name | First name | User’s first name |
family_name | Last name | User’s last name |
picture or avatar_url | Avatar URL | User’s profile picture |
login or username | Username | User’s username |
Nested attributes
For nested JSON responses, use dot notation:Array attributes
For array values, specify the index:OAuth2 scopes
Scopes determine what user information your application can access. Common scopes include:| Scope | Description | Providers |
|---|---|---|
email | Access to user’s email address | Most providers |
profile | Access to basic profile information | Most providers |
user:email | Access to email (GitHub-specific) | GitHub |
read_user | Read user information | GitLab |
identify | Basic user information | Discord |
users:read | Read user data | Slack |
Redirect URI format
The redirect URI (callback URL) follows this pattern:https://app.example.com/auth/callback/githubhttps://app.example.com/auth/callback/gitlabhttps://app.example.com/auth/callback/slack
Token handling
Access tokens
OAuth2 access tokens are used to authenticate API requests to the provider. The application:- Exchanges the authorization code for an access token
- Uses the access token to fetch user information
- Stores the token for future API calls (optional)
Refresh tokens
Some providers issue refresh tokens for long-lived access. Configure theoffline_access or equivalent scope to request refresh tokens.
Token expiration
Access tokens typically expire after a short period (1 hour to 24 hours). The application handles token refresh automatically when refresh tokens are available.Troubleshooting
Invalid redirect URI
Problem: Provider rejects the redirect URI Solution:- Verify the redirect URI exactly matches in both systems
- Check for trailing slashes or protocol mismatches
- Ensure the provider ID in the URL matches your configuration
- Some providers require exact URL matching (including query parameters)
Missing email address
Problem: User email is not populated after login Solution:- Verify you’re requesting the correct scope for email access
- Check that the user has a verified email in their provider account
- Review the user info response in audit logs
- Update attribute mapping to match the provider’s response format
Scope not granted
Problem: Provider doesn’t grant requested scopes Solution:- Verify the scopes are valid for your provider
- Check that your OAuth application is approved for the requested scopes
- Some scopes require additional provider configuration or approval
- Review provider documentation for scope requirements
User info endpoint fails
Problem: Cannot fetch user information after authentication Solution:- Verify the user info URL is correct
- Check that the access token is being sent correctly
- Review the provider’s API documentation for authentication requirements
- Some providers require specific headers (e.g.,
Accept: application/json)
Security best practices
Use HTTPS only
Use HTTPS only
Always use HTTPS for redirect URIs. OAuth2 over HTTP is insecure.
Validate state parameter
Validate state parameter
The application automatically validates the state parameter to prevent CSRF attacks.
Rotate client secrets
Rotate client secrets
Regularly rotate your client secrets and update them in the admin UI.
Limit scopes
Limit scopes
Only request the scopes necessary for your application’s functionality.
Secure token storage
Secure token storage
Access tokens are encrypted in the database. Never log or expose tokens in client-side code.
Advanced configuration
Custom headers
Some providers require custom headers for the user info request. Contact support if you need to configure custom headers.Token endpoint authentication
The application supports multiple token endpoint authentication methods:client_secret_post(default): Send credentials in request bodyclient_secret_basic: Send credentials in Authorization header