1

我们的应用程序允许用户使用 Google 帐户登录并使用 Google API 客户端库进行 ID 令牌验证。

根据Google doc,当范围包含范围值时,email声明应该包含在 ID 令牌有效负载中。email

但是,我注意到在某些情况下,email尽管包含范围值email_verified,但 ID 令牌有效负载中缺少声明。email

为什么会这样?我想 Google 帐户的个人资料上总是有一个经过验证的电子邮件地址。

4

2 回答 2

0
GET /oauth2/v2/userinfo HTTP/1.1
Host: www.googleapis.com
Content-length: 0
Authorization: Bearer [accessToken]

{
  "picture": "https://lh3.googleusercontent.com/a-/AOh14GhroCYJp2P9xeYeYk1npchBPK-zbtTxzNQo0WAHI20", 
  "verified_email": true, 
  "id": "11720047553267277534", 
  "email": "xxxxxxx@gmail.com"
}
于 2020-06-26T01:19:21.637 回答
0

几年前我就这个问题问过团队。他们不保证每次通话都会提出索赔。

解决方法是

如果您向 userinfoendpoint 发出请求

GET /oauth2/v2/userinfo HTTP/1.1
Host: www.googleapis.com
Content-length: 0
Authorization: Bearer [accessToken]

回复

{
  "picture": "https://lh3.googleusercontent.com/a-/AOh14GhroCYJp2P9xeYeYk1npchBPK-zbtTxzNQo0WAHI20", 
  "verified_email": true, 
  "id": "11720047553267277534", 
  "email": "xxxxxxx@gmail.com"
}

假设您已经请求了电子邮件范围 email 并且 verify_email 每次都会返回。

于 2020-06-23T07:08:38.520 回答