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
Add Casdoor to gitlab.rb
GitLab only talks to OpenID providers over HTTPS, so serve Casdoor over HTTPS. Add this to
/etc/gitlab/gitlab.rband runsudo 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
Map Casdoor groups (GitLab Premium and Ultimate)
To make members of a Casdoor group GitLab administrators, or to mark contractors as external users, add a
gitlabblock insideclient_options. Set the Casdoor application's Token group format to Name so the values match.gitlab: { groups_attribute: "groups", admin_groups: ["gitlab-admins"], external_groups: ["contractors"] } - 4
Sign in
The sign-in page now has a Casdoor button. People who already have a GitLab account can connect Casdoor under User settings → Account → Service sign-in.
注意事项
omniauth_allow_single_sign_onlets GitLab create an account on first sign-in, andomniauth_block_auto_created_users = falselets new users in without waiting for an administrator to approve them.uid_field: "sub"ties each GitLab identity to the Casdoor user ID, which doesn't change when a user is renamed.
GitLab 的设置取自它的官方文档(核对于 2026年10月:GitLab OpenID Connect);另见Casdoor 文档。GitLab 是其所有者的商标。
常见问题
Do I need GitLab Premium?
Not for single sign-on: any self-managed GitLab can use Casdoor as its OpenID Connect provider. Rules based on OIDC group membership (required, external and admin groups) need GitLab Premium or Ultimate.
I compiled GitLab from source. Where do the settings go?
Put the same provider settings under omniauth in config/gitlab.yml; GitLab's OpenID Connect documentation shows that format next to the gitlab.rb one.
更多应用集成
查看全部Argo CD
应用集成Connect Argo CD to Casdoor over OpenID Connect: oidc.config in argocd-cm, the client secret, PKCE, CLI login and RBAC from Casdoor groups.
Gitea
应用集成Add Casdoor to Gitea as an OpenID Connect authentication source: the add-oauth command, callback URL, and admins from a Casdoor group.
Grafana
应用集成Set up Grafana single sign-on with Casdoor over OpenID Connect: Generic OAuth settings, PKCE, and Grafana roles mapped from Casdoor groups.
