在极狐GitLab 身份验证中如何使用 JWT?

发布于:2025-04-18 ⋅ 阅读:(21) ⋅ 点赞:(0)

极狐GitLab 是 GitLab 在中国的发行版,关于中文参考文档和资料有:

使用 JWT 作为身份验证提供者 (BASIC SELF)

要启用 JWT OmniAuth 提供者,您必须向 JWT 注册您的应用程序。JWT 为您提供一个用于使用的密钥。

1.在您的极狐GitLab 服务器上,打开配置文件。

对于 Linux 软件包安装:

sudo editor /etc/gitlab/gitlab.rb

对于自编译安装:

cd /home/git/gitlab
sudo -u git -H editor config/gitlab.yml

2.配置通用设置以添加 jwt 作为单点登录提供者。这为没有现有极狐GitLab 账户的用户启用即时账户配置。

3.添加提供者配置。

对于 Linux 软件包安装:

gitlab_rails['omniauth_providers'] = [
  { name: "jwt",
    label: "Provider name", # optional label for login button, defaults to "Jwt"
    args: {
      secret: "YOUR_APP_SECRET",
      algorithm: "HS256", # Supported algorithms: "RS256", "RS384", "RS512", "ES256", "ES384", "ES512", "HS256", "HS384", "HS512"
      uid_claim: "email",
      required_claims: ["name", "email"],
      info_map: { name: "name", email: "email" },
      auth_url: "https://example.com/",
      valid_within: 3600 # 1 hour
    }
  }
]

对于自编译安装:

- { name: 'jwt',
    label: 'Provider name', # optional label for login button, defaults to "Jwt"
    args: {
      secret: 'YOUR_APP_SECRET',
      algorithm: 'HS256', # Supported algorithms: 'RS256', 'RS384', 'RS512', 'ES256', 'ES384', 'ES512', 'HS256', 'HS384', 'HS512'
      uid_claim: 'email',
      required_claims: ['name', 'email'],
      info_map: { name: 'name', email: 'email' },
      auth_url: 'https://example.com/',
      valid_within: 3600 # 1 hour
    }
  }

WARNING:
不正确地配置这些设置可能导致实例不安全。

4.将 YOUR_APP_SECRET 更改为客户端密钥,并将 auth_url 设置为您的重定向 URL。

5.保存配置文件。

6.为了使更改生效,如果您:

  • 使用 Linux 软件包安装了极狐GitLab,请重新配置极狐GitLab。
  • 自编译了您的极狐GitLab 安装,请重启极狐GitLab。

在登录页面,现在应该在常规登录表单下方有一个 JWT 图标。选择该图标以开始身份验证过程。JWT 要求用户登录并授权极狐GitLab 应用程序。如果一切顺利,用户将被重定向到极狐GitLab 并登录。


网站公告

今日签到

点亮在社区的每一天
去签到