跳到主要内容

Google 与 GitHub 社交登录

Axis Vertex 通过 OIDC 代理 Google,通过 OAuth2 代理 GitHub。用户从接入应用跳转到提供商,认证后先返回 Axis Vertex callback,再继续到接入应用配置的 OAuth callback。

先确定 Vertex 部署的公网 HTTPS issuer:

VERTEX_ISSUER=https://auth.example.com

以下示例不带末尾 /。提供商 client secret 是服务端只写值。

Google OIDC​

创建 Google client​

  1. 打开 Google Cloud Console。
  2. 选择或创建项目。
  3. 在 Google Auth Platform 中按 Google 要求配置 Branding、Audience 与 Data Access。如果应用仍处于 testing 状态,把用于验收的身份加入 test users。
  4. 打开 Clients,选择 Create client,应用类型选择 Web application。
  5. 添加以下精确的 Authorized redirect URI:
VERTEX_ISSUER/api/v1/identity-providers/oidc/callback

例如:

https://auth.example.com/api/v1/identity-providers/oidc/callback

该代理流程不使用 Google JavaScript SDK,Authorized JavaScript origin 不能替代 redirect URI。如果 Google 或组织策略要求填写 origin,使用不带路径的 VERTEX_ISSUER 精确 HTTPS origin。只有接入应用自己另外使用 Google 浏览器 SDK 时,才添加接入应用 origin。

  1. 复制 Google client ID 与 client secret。不要把 secret 放入接入 SPA。

Google 要求授权请求中的 redirect_uri 与已登记 URI 精确一致;scheme、host、port、path 和末尾斜杠都会参与匹配。 上游要求参见 Google 的 OAuth 2.0 Web Server 指南。

在 Vertex Portal 添加 Google​

  1. 打开应用管理,选择 Application,再打开身份提供商。
  2. 选择添加提供商,类型选择 Google。
  3. 填写稳定的内部名称和用户可见的显示名称。
  4. 填写 Google client ID 与 client secret。
  5. 没有经过评审的额外需求时,Scopes 保持 openid email profile。
  6. 邮箱 Claim 保持 email,姓名 Claim 保持 name。
  7. 保存并启用提供商;可用时执行测试连接。

Google issuer 由后端固定为 https://accounts.google.com,不要填写 authorization endpoint URL。

GitHub OAuth2​

创建 GitHub OAuth App​

  1. 登录 GitHub。
  2. 打开 Developer settings -> OAuth Apps -> New OAuth App。需要 组织持有时,改在 GitHub Organization 的 Developer settings 下创建。GitHub 的 OAuth App 创建指南也使用 Homepage URL 与 Authorization callback URL 这两个字段。
  3. Homepage URL 填接入应用的公网主页,例如:
https://app.example.com
  1. Authorization callback URL 填 Axis Vertex 的精确回调:
VERTEX_ISSUER/api/v1/identity-providers/oauth2/callback

例如:

https://auth.example.com/api/v1/identity-providers/oauth2/callback
  1. 注册 OAuth App,生成 client secret,并立即存入密钥管理系统。

GitHub OAuth App 只支持一个 callback URL。开发、预发布和生产的 Vertex issuer 不同时,应分别创建 OAuth App。

在 Vertex Portal 添加 GitHub​

  1. 打开同一个 Application 的身份提供商页。
  2. 选择添加提供商,类型选择 GitHub。
  3. 填写 GitHub OAuth App 的 client ID 和 client secret。
  4. Scopes 保持 read:user user:email,以便 GitHub 公开资料未展示邮箱时仍能解析已验证邮箱。
  5. 保存并启用提供商。

GitHub 在 Vertex 中是 OAuth2 提供商,不是通用 OIDC issuer。不要填写 GitHub issuer URL,也不要使用 Google OIDC callback。

让提供商显示并允许首次登录​

在 Application 的认证策略中:

  1. 开启社交登录。
  2. 只有允许已验证 Google/GitHub 身份首次登录时创建 Application 用户,才开启 IdP 自动创建用户。
  3. 如果用户必须预先创建或邀请,保持自动创建关闭。

社交登录关闭、提供商未启用、提供商属于其他 Application 或 runtime 未就绪时,已保存的提供商仍不会显示。 自动创建关闭时,即使上游认证成功,当前 Application 中不存在对应用户也会登录失败。

故障排查​

现象检查项
Hosted 登录不显示提供商是否属于同一 Application、提供商已启用、社交登录已开启、使用 public SPA client
Google 报 redirect_uri_mismatchOIDC callback 是否精确登记、是否多了 /、Vertex issuer 是否正确
GitHub 返回错误环境OAuth App callback 是否指向该环境的 OAuth2 callback
Provider callback 最终为 sign_in_failed当前 Application 是否已有用户,或 IdP 自动创建用户是否开启
发起登录返回 502Vertex 是否能访问 provider discovery/token/user-info endpoint,出口代理是否健康
Secret 已轮换编辑提供商并提交新只写 secret;留空表示保留已存 secret

不要记录 authorization code、provider access token、client secret、state、nonce 或 callback query string。