Casdoor集成市场

GitLab Self-Managed | OAuth 提供商

用自建 GitLab 登录 Casdoor

GitLab 也是 OpenID Connect 提供商。Casdoor 内置的 GitLab 提供商只连 gitlab.com;这个模板让 Casdoor 连到你自己的 GitLab,开发者用每天都在用的账号登录。

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

用 Casdoor 配置 GitLab Self-Managed

  1. 1

    在 GitLab 里创建 OAuth 应用

    以管理员身份打开 Admin → Applications,点 Add new application。(在群组的 Settings → Applications 或你自己的 Edit profile → Applications 里建也可以,只是没有 Trusted 选项。)填写:

    NameCasdoor
    Redirect URIhttps://auth.example.com/callback
    TrustedOn, to skip the consent screen
    ConfidentialOn
    Scopesopenid, profile, email
  2. 2

    复制凭据

    保存应用,复制 Application ID(即客户端 ID)和 Secret。GitLab 存的是 secret 的哈希,所以只有这一次能看到它。

  3. 3

    在 Casdoor 中添加 GitLab Self-Managed 提供商

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

    类别OAuth
    类型OIDC
    显示名称GitLab
    客户端ID<client ID>
    客户端密钥<client secret>
    Issuer链接https://gitlab.example.com
    认证URLhttps://gitlab.example.com/oauth/authorize
    Token链接https://gitlab.example.com/oauth/token
    范围openid profile email
    UserInfo链接https://gitlab.example.com/oauth/userinfo
    启用PKCE开启

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

  4. 4

    把提供商加到应用上

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

注意事项

  • GitLab 只对设置了公开邮箱的用户发送 email,其他用户进到 Casdoor 时没有邮箱。
  • 在 GitLab 里重新生成 secret 后,登录会失败,直到你把新的 secret 填进 Casdoor。

GitLab Self-Managed 的设置取自它的官方文档(核对于 2026年10月:GitLab as an OpenID Connect provider、GitLab as an OAuth 2.0 provider、GitLab OAuth 2.0 API)。GitLab Self-Managed 是其所有者的商标。

常见问题

能用于 gitlab.com 吗?

可以,GitLab 地址填 https://gitlab.com 即可,不过 Casdoor 内置的 GitLab 提供商已经支持 gitlab.com。

GitLab 的群组会同步过来吗?

不会。GitLab 的 userinfo 端点会返回用户所在的群组,但 Casdoor 只从中填写标准的个人资料,不会填到 Casdoor 的群组里。