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

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

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

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

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

对于 Linux 软件包安装:

swift 复制代码
sudo editor /etc/gitlab/gitlab.rb

对于自编译安装:

bash 复制代码
cd /home/git/gitlab
sudo -u git -H editor config/gitlab.yml

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

3.添加提供者配置。

对于 Linux 软件包安装:

bash 复制代码
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
    }
  }
]

对于自编译安装:

bash 复制代码
- { 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 并登录。

相关推荐
路西法013 小时前
Office-Word-MCP-Server在Cursor中使用方法
cursor·mcp
HIT_Weston7 小时前
63、【Ubuntu】【Gitlab】拉出内网 Web 服务:Gitlab 配置审视(七)
前端·ubuntu·gitlab
HIT_Weston10 小时前
65、【Ubuntu】【Gitlab】拉出内网 Web 服务:Gitlab 配置审视(九)
前端·ubuntu·gitlab
victory043112 小时前
GitLab部署报告
gitlab
HIT_Weston12 小时前
64、【Ubuntu】【Gitlab】拉出内网 Web 服务:Gitlab 配置审视(八)
前端·ubuntu·gitlab
HIT_Weston12 小时前
62、【Ubuntu】【Gitlab】拉出内网 Web 服务:Gitlab 配置审视(六)
前端·ubuntu·gitlab
Light6013 小时前
【MCP原生时代】第2篇|前端如何舞动 MCP:新一代交互范式——从 Hook 到流式渲染,打造 AI 原生前端体验
状态模式·前端架构·mcp·react hook·流式渲染·ai交互
不爱吃米饭_1 天前
Gitea 轻量级的Git方案 - Gitlab的替代品
git·gitlab·gitea
嘻哈baby1 天前
自建GitLab与CI/CD实战:团队协作完整方案
ci/cd·gitlab
秦时明月天明1 天前
GitLab SSH Key 过期:git pull failed : remote your ssh key has expired
git·ssh·gitlab