ClouisleClouisle

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

MethodPathPurposeAuth
GET/api/v1/sso/integrationsList enabled login integrations (login page)Public
GET/api/v1/sso/login/{provider_name}Begin SSO login; redirect to the identity providerPublic
GET/api/v1/sso/callback/{provider_name}Identity-provider callback; finish login and redirect backPublic
DELETE/api/v1/sso/connections/{connection_id}Unlink one of the caller's SSO connectionsSigned-in user
GET/api/v1/admin/integrations/typesStatic integration types, capabilities, and singleton flagsEither read domain
GET/api/v1/admin/integrationsDomain-filtered integration listEither read domain
POST/api/v1/admin/integrationsCreate a non-singleton login integrationLogin-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}/testTest login configurationLogin-domain update
DELETE/api/v1/admin/integrations/connections/{connection_id}Unlink any user's SSO connectionadmin:integrations:login:update
GET / PUT/api/v1/admin/integrations/login-settingsGlobal login settings (UI entry: Site Settings > Security)Login-domain read / write
GET / PUT/api/v1/admin/integrations/email, /webhookBuiltin notification configurationSettings-domain read / write
POST/api/v1/admin/integrations/email/test, /webhook/testTest notification deliverySettings-domain update
—Feishu and WeChat iLink specific endpointsConfiguration, directory/knowledge sync, callbacks, personal preferencesSee Messaging integration API

1. List enabled login integrations

GET /api/v1/sso/integrations

Used 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"
}
FieldTypeDescription
idstring (UUID)Integration ID (preserved across the migration)
namestringUnique integration identifier (used in login URLs)
display_namestringUser-facing name
icon_urlstring | nullIcon URL
button_textstring | nullButton text
provider_typestringoauth2, oidc, saml2, cas, or feishu

2. Begin SSO login

GET /api/v1/sso/login/{provider_name}

Query parameters

ParameterTypeRequiredDescription
redirectstringNoSame-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:

  1. Validates that the integration exists and is enabled; otherwise it redirects to {frontend}/sso-callback?error=sso_provider_not_found.
  2. Creates a temporary SSO session that expires after 10 minutes, holding the protocol state (PKCE code_verifier / nonce or relay state).
  3. Builds the callback URL from the backend origin: {backend}/api/v1/sso/callback/{provider_name}.
  4. Returns 307 Temporary Redirect to the identity provider's authorization URL.

Failure redirect:

{frontend}/sso-callback?error=<error_code>&redirect=<path>
errorMeaning
sso_provider_not_foundIntegration missing or disabled
sso_login_failedIntegration 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:

ProtocolCallback parameters
oauth2 / oidc / feishucode, state
casticket (and optionally state)
saml2SAMLResponse, 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:

errorMeaning
sso_provider_not_foundIntegration does not exist
sso_session_expiredSession missing or older than 10 minutes
sso_login_failedUser-info exchange failed or provider_user_id is missing
pending_approvalNew user requires admin approval before signing in
inactiveAccount 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.


DELETE /api/v1/sso/connections/{connection_id}

Path parameters

ParameterTypeRequiredDescription
connection_idstring (UUID)YesUser 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:

HTTPCodeMeaning
4044000sso_connection_not_found: unknown connection or not owned by the caller
4031004cannot_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_capabilities and is_enabled are charged to the domain of the capabilities involved (user_login → login, directory_sync → settings);
  • a builtin's config and credentials go to settings;
  • button_text, display_name, icon_url, login_config, and attribute_mapping go 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}/test

Requires 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.

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:

HTTPCodeMeaning
4004000sso_connection_not_found
4001004cannot_disconnect_only_auth_method

Error handling

HTTPCodeTrigger
4033000Missing required permission (admin:integrations:login:* / admin:integrations:settings:*)
4001004Unlinking would leave the account with no sign-in method
4006300Integration not found (admin endpoints)
4006305Duplicate integration identifier
400 / 4044000SSO connection missing or not owned by the caller
4221001Request 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.

  • Authentication API — password login, JWT tokens, and TOTP two-factor verification
  • SSO configuration — per-protocol settings, the config / attribute_mapping / credentials / login_config boundaries, and upgrade/rollback cautions
  • Users API — the sso_connections field on a user profile
  • Error Handling — recover by HTTP status and business error code

How is this guide?

On this page