SSO API
Single sign-on flows, connection unlinking, and unified integration administration
The SSO API covers three things: login integration discovery for the login page, the browser-redirect single sign-on flow (OAuth2 / OIDC, SAML2, CAS, Feishu), and the user unlinking their own SSO identity. Creating, configuring, and testing integrations belongs to unified integration administration under /api/v1/admin/integrations.
Prerequisites and authentication
GET /api/v1/sso/integrations, GET /api/v1/sso/login/{provider_name}, and GET /api/v1/sso/callback/{provider_name} are public and need no authentication. login and callback return redirects rather than the unified envelope.
DELETE /api/v1/sso/connections/{connection_id} requires a signed-in user (it can only unlink their own connections).
The admin base is /api/v1/admin/integrations: login-domain operations require admin:integrations:login:read / admin:integrations:login:update; builtin configuration (email, webhook, Feishu directory sync, …) requires admin:integrations:settings:read / admin:integrations:settings:update. The catalog and list endpoints accept either read domain, and the list filters instances to authorized domains.
Integration configuration (the config, attribute_mapping, credentials, and login_config boundaries) is covered in SSO configuration.
login and callback return an HTTP 307 redirect, not a {code, data, msg} envelope. The frontend receives a token or error query parameter on its /sso-callback route. When the sso_enabled site setting is false, GET /sso/integrations returns an empty data array even if integrations are configured.
Endpoints
| Method | Path | Purpose | Auth |
|---|---|---|---|
| GET | /api/v1/sso/integrations | List enabled login integrations (login page) | Public |
| GET | /api/v1/sso/login/{provider_name} | Begin SSO login; redirect to the identity provider | Public |
| GET | /api/v1/sso/callback/{provider_name} | Identity-provider callback; finish login and redirect back | Public |
| DELETE | /api/v1/sso/connections/{connection_id} | Unlink one of the caller's SSO connections | Signed-in user |
| GET | /api/v1/admin/integrations/types | Static integration types, capabilities, and singleton flags | Either read domain |
| GET | /api/v1/admin/integrations | Domain-filtered integration list | Either read domain |
| POST | /api/v1/admin/integrations | Create a non-singleton login integration | Login-domain update |
| PUT / DELETE | /api/v1/admin/integrations/{id} | Field-level-authorized update / delete login integration (never a singleton) | See below |
| POST | /api/v1/admin/integrations/{id}/test | Test login configuration | Login-domain update |
| DELETE | /api/v1/admin/integrations/connections/{connection_id} | Unlink any user's SSO connection | admin:integrations:login:update |
| GET / PUT | /api/v1/admin/integrations/login-settings | Global login settings (UI entry: Site Settings > Security) | Login-domain read / write |
| GET / PUT | /api/v1/admin/integrations/email, /webhook | Builtin notification configuration | Settings-domain read / write |
| POST | /api/v1/admin/integrations/email/test, /webhook/test | Test notification delivery | Settings-domain update |
| — | Feishu and WeChat iLink specific endpoints | Configuration, directory/knowledge sync, callbacks, personal preferences | See Messaging integration API |
1. List enabled login integrations
GET /api/v1/sso/integrationsUsed by the login page to render SSO buttons. Only integrations that are enabled and have user_login among their enabled capabilities are returned; an enabled Feishu integration that has not opted in to sign-in stays hidden.
200 OK:
{
"code": 0,
"data": [
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"name": "github",
"display_name": "GitHub",
"icon_url": "https://cdn.example.com/github.svg",
"button_text": "Continue with GitHub",
"provider_type": "oauth2"
}
],
"msg": "success"
}| Field | Type | Description |
|---|---|---|
id | string (UUID) | Integration ID (preserved across the migration) |
name | string | Unique integration identifier (used in login URLs) |
display_name | string | User-facing name |
icon_url | string | null | Icon URL |
button_text | string | null | Button text |
provider_type | string | oauth2, oidc, saml2, cas, or feishu |
2. Begin SSO login
GET /api/v1/sso/login/{provider_name}Query parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
redirect | string | No | Same-origin relative path (e.g. /app/kb) to land on after login. Non-relative or external values are ignored and fall back to /app — for every role |
Behaviour:
- Validates that the integration exists and is enabled; otherwise it redirects to
{frontend}/sso-callback?error=sso_provider_not_found. - Creates a temporary SSO session that expires after 10 minutes, holding the protocol state (PKCE
code_verifier/nonceor relay state). - Builds the callback URL from the backend origin:
{backend}/api/v1/sso/callback/{provider_name}. - Returns
307 Temporary Redirectto the identity provider's authorization URL.
Failure redirect:
{frontend}/sso-callback?error=<error_code>&redirect=<path>error | Meaning |
|---|---|
sso_provider_not_found | Integration missing or disabled |
sso_login_failed | Integration initialization failed (unsupported protocol, bad config, …) |
About state
For OAuth2 / OIDC the state is the server-generated SSO session ID, used on callback to retrieve the PKCE code_verifier / nonce; SAML2 passes the same session ID through RelayState and CAS through state or ticket. The state in the callback URL is therefore not a client-chosen value — do not construct or reuse it yourself.
3. Identity-provider callback
GET /api/v1/sso/callback/{provider_name}The identity provider redirects the browser here after the user authenticates. Parameters differ by protocol:
| Protocol | Callback parameters |
|---|---|
oauth2 / oidc / feishu | code, state |
cas | ticket (and optionally state) |
saml2 | SAMLResponse, RelayState |
Register this URL with the identity provider as https://<backend-host>/api/v1/sso/callback/{name}. For Feishu, the app also needs the login scopes contact:user.base:readonly contact:user.email:readonly; the callback exchanges the code with PKCE and stores the profile union_id (falling back to open_id) as provider_user_id.
Success → the browser is redirected to:
{frontend}/sso-callback?token=<access_token>&redirect=<path>token is a standard JWT access token (see the Authentication API). The SSO session is deleted immediately after success.
Failure → redirect to {frontend}/sso-callback?error=<error_code>&redirect=<path>. Common error values:
error | Meaning |
|---|---|
sso_provider_not_found | Integration does not exist |
sso_session_expired | Session missing or older than 10 minutes |
sso_login_failed | User-info exchange failed or provider_user_id is missing |
pending_approval | New user requires admin approval before signing in |
inactive | Account is deactivated |
For deactivated or pending-approval accounts the SSO flow does not issue a token — it only returns the error to the frontend. Surface it as a message; do not treat the user as signed in.
4. Unlink your own SSO connection
DELETE /api/v1/sso/connections/{connection_id}Path parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
connection_id | string (UUID) | Yes | User SSO connection ID |
Only connections belonging to the caller can be operated on; other users' connections return 404 (sso_connection_not_found). If the account has no password and this is its last SSO connection, deletion is refused with 403 (cannot_disconnect_only_auth_method) — the account would otherwise become unreachable.
The caller's connection list is available from the sso_connections field of GET /api/v1/users/me; see the Users API. Connection fields use the integration_ prefix: integration_id, integration_name, integration_display_name, integration_icon_url; provider_user_id remains the external identity key.
200 OK:
{
"code": 0,
"data": null,
"msg": "success"
}Errors:
| HTTP | Code | Meaning |
|---|---|---|
404 | 4000 | sso_connection_not_found: unknown connection or not owned by the caller |
403 | 1004 | cannot_disconnect_only_auth_method: no password and this is the only sign-in method |
5. Admin: unified integrations
The admin base is /api/v1/admin/integrations. Login-domain operations require admin:integrations:login:read / admin:integrations:login:update; builtin configuration requires admin:integrations:settings:read / admin:integrations:settings:update. The catalog (/types) and list accept either read domain, and the list filters instances to authorized domains.
Old management namespace removed
The old /api/v1/admin/sso/* admin endpoints and the /sso/providers discovery endpoint are removed — use the unified integration endpoints in this section. Login / callback URLs stay unchanged; migration preserves UUIDs and bound identities.
5.1 Create and update fields
Create / update body fields: name, provider_type, display_name, icon_url, button_text, is_enabled, enabled_capabilities, config, attribute_mapping, credentials, and login_config. Signup policy (allow_signup, require_approval, default_role_id) belongs in login_config.
Secrets are plaintext input only in credentials, encrypted at rest (Fernet), and never returned: admin output omits credentials entirely and exposes credentials_configured and supported_capabilities instead. Empty secret inputs preserve stored values.
{
"name": "github",
"provider_type": "oauth2",
"display_name": "GitHub",
"is_enabled": true,
"enabled_capabilities": ["user_login"],
"config": {
"client_id": "client-id",
"authorization_url": "https://github.com/login/oauth/authorize",
"token_url": "https://github.com/login/oauth/access_token",
"userinfo_url": "https://api.github.com/user",
"scopes": "read:user user:email"
},
"credentials": {"client_secret": "client-secret"},
"attribute_mapping": {"email": "email", "username": "login", "avatar_url": "avatar_url"},
"login_config": {"allow_signup": true, "require_approval": false}
}The registry statically supports login for OAuth2 / OIDC / SAML2 / CAS, notification for email / Webhook, and both directory sync and login for Feishu — where login stays an explicit opt-in through enabled_capabilities. Builtins are singletons and use their specialized configuration endpoints; because Feishu is a singleton, it never appears in the protocol list for creating a new login integration.
5.2 Field-level authorization (PUT /{id})
PUT /{id} authorizes per field, not per instance:
enabled_capabilitiesandis_enabledare charged to the domain of the capabilities involved (user_login→ login,directory_sync→ settings);- a builtin's
configandcredentialsgo to settings; button_text,display_name,icon_url,login_config, andattribute_mappinggo to login when the integration type is login-capable (otherwise settings).
The same field set covers Feishu: opting in to Feishu sign-in is {"enabled_capabilities": ["directory_sync", "user_login"], "is_enabled": true} on the generic endpoint and requires admin:integrations:login:update. The /feishu/* endpoints below remain on the settings domain.
PUT / DELETE /{id} only operate on login integrations and never delete a singleton builtin.
5.3 Test configuration
POST /api/v1/admin/integrations/{id}/testRequires login-domain update. Validates whether the login configuration works.
200 OK:
{
"code": 0,
"data": {
"status": "success",
"message": "SSO provider configuration is valid"
},
"msg": "success"
}Configuration test responses omit authorization URLs to avoid exposing query parameters or credentials. An invalid configuration still returns 200 OK, but data.status is "error".
The test outcome is expressed in data.status and is not conveyed by the HTTP status: code: 0 + status: "error" means the configuration is broken.
5.4 Unlink any user's connection
DELETE /api/v1/admin/integrations/connections/{connection_id}Requires admin:integrations:login:update. Semantics match self-service unlinking, but any user's connection may be targeted; the "no password and only sign-in method" protection still applies.
Errors:
| HTTP | Code | Meaning |
|---|---|---|
400 | 4000 | sso_connection_not_found |
400 | 1004 | cannot_disconnect_only_auth_method |
Error handling
| HTTP | Code | Trigger |
|---|---|---|
403 | 3000 | Missing required permission (admin:integrations:login:* / admin:integrations:settings:*) |
400 | 1004 | Unlinking would leave the account with no sign-in method |
400 | 6300 | Integration not found (admin endpoints) |
400 | 6305 | Duplicate integration identifier |
400 / 404 | 4000 | SSO connection missing or not owned by the caller |
422 | 1001 | Request validation failed (integration naming, icon_url format, …) |
The login/callback flow does not use the unified envelope; failures arrive as the error parameter on the frontend's /sso-callback: sso_provider_not_found, sso_session_expired, sso_login_failed, pending_approval, inactive.
Related
- Authentication API — password login, JWT tokens, and TOTP two-factor verification
- SSO configuration — per-protocol settings, the
config/attribute_mapping/credentials/login_configboundaries, and upgrade/rollback cautions - Users API — the
sso_connectionsfield on a user profile - Error Handling — recover by HTTP status and business error code
How is this guide?