Casdoor集成市场

GitLab | 应用集成

自建 GitLab 单点登录

自建 GitLab 通过 OmniAuth 提供方登录,支持任意 OpenID Connect 提供方。把 Casdoor 配成提供方后,开发者用同一个账号登录 GitLab 和你的其他工具。

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

用 Casdoor 配置 GitLab

  1. 1

    在 Casdoor 中注册 GitLab

    在 Casdoor 控制台打开 应用,为 GitLab 添加一个应用,在它的 OIDC/OAuth 标签页复制 客户端ID 和 客户端密钥。把下面的地址加到 重定向URLs:

    • https://gitlab.example.com/users/auth/openid_connect/callback
  2. 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. 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. 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 格式旁边也给了这种格式。