Skip to content

feat: add generic OAuth2 SSO login with configurable field mapping#337

Open
nap-liu wants to merge 1 commit intodataelement:mainfrom
nap-liu:pr/generic-oauth2-sso
Open

feat: add generic OAuth2 SSO login with configurable field mapping#337
nap-liu wants to merge 1 commit intodataelement:mainfrom
nap-liu:pr/generic-oauth2-sso

Conversation

@nap-liu
Copy link
Copy Markdown

@nap-liu nap-liu commented Apr 8, 2026

Summary

  • New OAuth2AuthProvider: RFC 6749 authorization code flow, urlencode for scope encoding
  • Configurable field mapping (provider_user_id, display_name, email, mobile, avatar_url)
  • Token exchange with redirect_uri (RFC compliance) + token_data fallback for Chinese SSO providers
  • SSO config endpoint returns OAuth2 authorize URL; callback handles full login flow
  • Frontend: OAuth2 config form with Token URL, UserInfo URL, Scope, Field Mapping (i18n zh/en)

Test plan

  • E2E: SSO scan login → redirected to OAuth2 provider → callback → user created ("刘喜") → logged in
  • Frontend: full config form verified in browser

Add a generic OAuth2AuthProvider that works with any OAuth2-compliant
identity provider (Google, Azure AD, Keycloak, Auth0, custom corporate
OAuth2 servers, etc.).

Backend:
- New OAuth2AuthProvider class with configurable authorize_url, token_url,
  userinfo_url, client_id, client_secret, scope, and field_mapping
- Token exchange uses application/x-www-form-urlencoded (RFC 6749)
- Graceful handling of userinfo 401/empty/invalid responses
- Configurable field_mapping maps provider fields to Clawith fields
  (provider_user_id, email, display_name, mobile, avatar_url)
- Standard OIDC field fallbacks when no custom mapping is configured
- Provider registered in auth_registry as "oauth2"
- SSO callback route (GET /auth/oauth2/callback) with session handling
- OAuth2 provider type added to SSO config endpoint

Frontend:
- OAuth2 configuration form with Token URL, UserInfo URL, Scope fields
- Field Mapping section for custom provider field names
- Save/update via dedicated OAuth2 API endpoints

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant