https://auth.example.com 请换成你的 Casdoor 地址(Casdoor 云上类似 https://acme.casdoor.com),其他 example.com 地址也换成你自己的。用 Casdoor 配置 GitLab
- 1
在 Casdoor 中注册 GitLab
在 Casdoor 控制台打开 应用,为 GitLab 添加一个应用,在它的 OIDC/OAuth 标签页复制 客户端ID 和 客户端密钥。把下面的地址加到 重定向URLs:
https://gitlab.example.com/users/auth/openid_connect/callback
- 2
在 gitlab.rb 里添加 Casdoor
GitLab 只通过 HTTPS 和 OpenID 提供方通信,所以 Casdoor 要用 HTTPS 访问。把下面的内容加到
/etc/gitlab/gitlab.rb,然后运行sudo gitlab-ctl reconfigure。gitlab_rails['omniauth_allow_single_sign_on'] = ['openid_connect'] gitlab_rails['omniauth_block_auto_created_users'] = false gitlab_rails['omniauth_providers'] = [ { name: "openid_connect", label: "Casdoor", args: { name: "openid_connect", scope: ["openid", "profile", "email"], response_type: "code", issuer: "https://auth.example.com", discovery: true, client_auth_method: "query", uid_field: "sub", pkce: true, client_options: { identifier: "<client ID>", secret: "<client secret>", redirect_uri: "https://gitlab.example.com/users/auth/openid_connect/callback" } } } ] - 3
映射 Casdoor 群组(GitLab Premium 和 Ultimate)
要让某个 Casdoor 群组的成员成为 GitLab 管理员,或者把外包人员标成外部用户,在
client_options里加一个gitlab块。把 Casdoor 应用的 Token 中的群组格式 设为 Name,这样两边的值才对得上。gitlab: { groups_attribute: "groups", admin_groups: ["gitlab-admins"], external_groups: ["contractors"] } - 4
登录
登录页上会多出 Casdoor 按钮。已有 GitLab 账号的人可以在 User settings → Account → Service sign-in(用户设置 → 账号 → 服务登录)里关联 Casdoor。
注意事项
omniauth_allow_single_sign_on让 GitLab 在用户第一次登录时建账号,omniauth_block_auto_created_users = false让新用户不用等管理员审批就能进来。uid_field: "sub"把每个 GitLab 身份绑定到 Casdoor 的用户 ID,用户改名时这个 ID 不变。
GitLab 的设置取自它的官方文档(核对于 2026年10月:GitLab OpenID Connect);另见 Casdoor 文档。GitLab 是其所有者的商标。
常见问题
需要 GitLab Premium 吗?
单点登录不需要:任何自建 GitLab 都能把 Casdoor 当作 OpenID Connect 提供方。基于 OIDC 群组成员关系的规则(必需群组、外部群组和管理员群组)需要 GitLab Premium 或 Ultimate。
我的 GitLab 是从源码编译的,配置写在哪?
把同样的提供方配置写在 config/gitlab.yml 的 omniauth 下;GitLab 的 OpenID Connect 文档里在 gitlab.rb 格式旁边也给了这种格式。
更多应用集成
查看全部
阿里邮箱
阿里邮箱 AI尊享版可以把 Casdoor 加成 OIDC 身份源:员工在邮箱登录页跳到 Casdoor 登录,按邮箱地址进入对应的邮箱账号。
Argo CD
用 OpenID Connect 把 Argo CD 接入 Casdoor:argocd-cm 里的 oidc.config、客户端密钥、PKCE、CLI 登录,以及按 Casdoor 群组分配 RBAC 权限。

DeepSeek Harness
让 DeepSeek Harness 以智能体身份登录 Casdoor,经 Casdoor MCP 网关使用你所在组织的 MCP 服务器,工具级授权、调用记录和审计都由 Casdoor 管理,全部在 Casdoor 和 DeepSeek Harness 的网页上完成设置。
