docs: clarify GitHub OAuth email setup

docs: clarify github oauth email setup
This commit is contained in:
Dream Hunter
2026-04-29 02:04:11 +08:00
committed by GitHub
parent 4e01b4e26f
commit c703082391
6 changed files with 26 additions and 2 deletions
@@ -13,6 +13,16 @@
- 默认 GitHub 模板使用 `https://api.github.com/user` 作为用户信息接口,并读取返回 JSON 的 `email` 字段。GitHub 账号如果隐藏公开邮箱,该字段会是 `null`,登录会返回 `[400]: 从 Oauth2 提供商获取用户邮箱失败`
- 解决方式是在 GitHub 个人资料中设置公开邮箱,或改成能返回邮箱的接口/提供商;如果返回值不是标准邮箱,可以使用下方“邮箱格式转换”。
如果不想公开 GitHub 邮箱,可以改用 GitHub 邮箱列表接口:
| 字段 | 值 |
|------|----|
| User Info URL | `https://api.github.com/user/emails` |
| User Email Key | `$[?(@.primary==true)].email` |
| Scope | `user:email` |
GitHub 个人资料中选择了 `Public email` 时,可以继续使用默认的 `https://api.github.com/user` + `email` 配置;只把邮箱从 private 改成可见但没有选择公开邮箱时,`/user` 接口仍可能返回 `email: null`
参考 [Creating an OAuth App](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/creating-an-oauth-app)
### Linux Do