Help us learn about your current experience with the documentation. Take the survey.
使用 Auth0 作为 OAuth 2.0 认证提供商
- Tier: Free, Premium, Ultimate
- Offering: GitLab Self-Managed
要启用 Auth0 OmniAuth 提供商,你必须创建一个 Auth0 账户和一个应用程序。
-
登录 Auth0 控制台。你也可以使用相同的链接创建账户。
-
选择 新建应用/API。
-
输入 应用程序名称。例如,‘GitLab’。
-
创建应用程序后,你应该会看到 快速入门 选项。忽略这些选项,选择 设置。
-
在设置屏幕的顶部,你应该在 Auth0 控制台中看到你的 域名、客户端 ID 和 客户端密钥。记下这些设置,以便稍后完成配置文件。例如:
- 域名:
test1234.auth0.com - 客户端 ID:
t6X8L2465bNePWLOvt9yi41i - 客户端密钥:
KbveM3nqfjwCbrhaUy_gDu2dss8TIlHIdzlyf33pB7dEK5u_NyQdp65O_o02hXs2
- 域名:
-
填写 允许的回调 URL:
http://<your_gitlab_url>/users/auth/auth0/callback(或)https://<your_gitlab_url>/users/auth/auth0/callback
-
填写 允许的来源 (CORS):
http://<your_gitlab_url>(或)https://<your_gitlab_url>
-
在你的 GitLab 服务器上,打开配置文件。
对于 Linux 包安装:
sudo editor /etc/gitlab/gitlab.rb对于自编译安装:
cd /home/git/gitlab sudo -u git -H editor config/gitlab.yml -
配置通用设置以添加
auth0作为单点登录提供商。这为没有现有 GitLab 账户的用户启用即时账户配置。 -
添加提供商配置:
对于 Linux 包安装:
gitlab_rails['omniauth_providers'] = [ { name: "auth0", # label: "Provider name", # 可选的登录按钮标签,默认为 "Auth0" args: { client_id: "<your_auth0_client_id>", client_secret: "<your_auth0_client_secret>", domain: "<your_auth0_domain>", scope: "openid profile email" } } ]对于自编译安装:
- { name: 'auth0', # label: 'Provider name', # 可选的登录按钮标签,默认为 "Auth0" args: { client_id: '<your_auth0_client_id>', client_secret: '<your_auth0_client_secret>', domain: '<your_auth0_domain>', scope: 'openid profile email' } } -
将
<your_auth0_client_id>替换为 Auth0 控制台页面中的客户端 ID。 -
将
<your_auth0_client_secret>替换为 Auth0 控制台页面中的客户端密钥。 -
将
<your_auth0_domain>替换为 Auth0 控制台页面中的域名。 -
根据你的安装方法,重新配置或重启 GitLab:
- 如果你使用 Linux 包安装, 重新配置 GitLab。
- 如果你自编译安装, 重启 GitLab。
在登录页面上,常规登录表单下方现在应该有一个 Auth0 图标。选择该图标开始认证过程。Auth0 会要求用户登录并授权 GitLab 应用程序。如果用户认证成功,用户将被返回到 GitLab 并登录。