Casdoor集成市场

Keycloak | 身份提供商

用 Keycloak 登录 Casdoor

Already run Keycloak? Add it to Casdoor as an OpenID Connect provider and people sign in to your Casdoor applications with their Keycloak accounts, while Casdoor handles the rest: other social logins, MFA, applications and permissions.

Casdoor 官方核验OIDCPKCE自托管
你需要一个正在运行的 Casdoor,自己部署或用 Casdoor 云都可以。示例中的 https://auth.example.com 请换成你的 Casdoor 地址(Casdoor 云上类似 https://acme.casdoor.com),其他 example.com 地址也换成你自己的。

用 Casdoor 配置 Keycloak

  1. 1

    Create a client in Keycloak

    In the Keycloak admin console, switch to the myrealm realm, open Clients and click Create client. Choose OpenID Connect as the client type, enter a client ID such as casdoor, and click Next.

  2. 2

    Turn on client authentication

    Turn Client authentication on and keep Standard flow enabled, click Next, and fill in the login settings:

    Valid redirect URIshttps://auth.example.com/callback
  3. 3

    Copy the client secret

    Save the client, open its Credentials tab and copy the Client secret. The client ID is the one you entered.

  4. 4

    在 Casdoor 中添加 Keycloak 提供商

    在 Casdoor 控制台打开 提供商,点击 添加,填写:

    类别OAuth
    类型OIDC
    显示名称Keycloak
    客户端ID<client ID>
    客户端密钥<client secret>
    Issuer链接https://keycloak.example.com/realms/myrealm
    认证URLhttps://keycloak.example.com/realms/myrealm/protocol/openid-connect/auth
    Token链接https://keycloak.example.com/realms/myrealm/protocol/openid-connect/token
    范围openid profile email
    UserInfo链接https://keycloak.example.com/realms/myrealm/protocol/openid-connect/userinfo
    登出URLhttps://keycloak.example.com/realms/myrealm/protocol/openid-connect/logout
    启用PKCE开启

    点击 Issuer链接 旁边的 请求,会从 Keycloak 的 discovery 文档自动填好其余地址。同一个组织里所有 OIDC 类型的提供商都通过同一个字段关联用户,所以如果这个组织已经有一个 OIDC 提供商,请把 类型 改成 Custom Flexible,它按提供商分别关联账号。

  5. 5

    把提供商加到应用上

    打开 应用,编辑用户登录的那个应用,在它的 提供商 标签页添加这个提供商。之后登录页上就会出现 Keycloak 按钮。

注意事项

  • Keycloak matches redirect URIs exactly, so enter the Casdoor address people actually use, and avoid wildcards.
  • Casdoor links each account to the Keycloak user ID (sub), so renaming a user in Keycloak doesn't create a second Casdoor account.

Keycloak 的设置取自它的官方文档(核对于 2026年10月:Keycloak OpenID Connect endpoints、Keycloak getting started)。Keycloak 是其所有者的商标。

常见问题

My Keycloak URLs have /auth in them. Does this still work?

Yes. Keycloak 16 and older put /auth in front of every path; include it in the Keycloak URL, for example https://keycloak.example.com/auth.

Can I use SAML instead?

Casdoor also has a Keycloak SAML provider. OpenID Connect needs less setup on both sides, which is why this template uses it.