在极狐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 并登录。

相关推荐
惜年_night3 小时前
Docker部署05-GitLab的CI-CD发布
ci/cd·docker·gitlab
yyk的萌5 小时前
创建属于自己的mysql的mcp
mysql·adb·ai·mcp
winlife_6 小时前
全程用 AI 做一款商业级手游 · EP0 立项:能做到吗、怎么做、边界在哪
人工智能·unity·ai编程·游戏开发·商业化·mcp·funplay
星马梦缘7 小时前
MCP 模型上下文协议、Agent Skills 智能体技能、Harness操作系统 课程内容
人工智能·大模型·llm·agent·智能体·mcp·skills
winlife_21 小时前
全程用 AI 做一款商业级手游 · EP1 地基:先搭框架层,不急着写玩法
unity·ai编程·游戏架构·mcp·框架设计·funplay
无人生还别怕1 天前
搭建gitlab服务并接入openldap认证
git·gitlab·github·openldap·ldap·统一认证
Super Scraper1 天前
如何使用 cURL 发送 JSON:-d、--json 及常见错误的完整指南
人工智能·爬虫·python·自动化·json·mcp
Bolt1 天前
Kimi code 用不了 Figma?看这里解决
shell·mcp
*_潇_*1 天前
0095__日常--记一次gitlab Runner配置与CI/CD环境搭建流程
ci/cd·gitlab