验证 google 令牌真实性时未获取所有配置文件信息
Not getting all profile informations when verifying a google token authenticity
我在客户端使用 omniauth 来连接 google 帐户。一切正常,我能够获得 id_token 和一些更多信息,例如电子邮件、姓名、family_name、given_name 等...
以下是我在 app/config/initializer/omniauth.rb 中配置提供程序的方式:
provider :google_oauth2, ENV['GOOGLE_ID'], ENV['GOOGLE_SECRET'], scope: "profile,email"
然后,作为测试,为了验证 id_token 的真实性,我使用 Postman 发送了一个 POST 请求,例如:
https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=x
将 x 替换为 id_token 我的客户
我得到了一个有效的答案,例如:
{
"iss": "accounts.google.com",
"at_hash": "xxx-xxx",
"aud": "xxx-xxx.apps.googleusercontent.com",
"sub": "xxx",
"email_verified": "true",
"azp": "xxx-xxx.apps.googleusercontent.com",
"email": "xxx@gmail.com",
"iat": "xxx",
"exp": "xxx",
"alg": "xxx",
"kid": "xxx"
}
当我连接到我的客户时,我允许应用程序访问我的个人资料信息和我的电子邮件,我一直在关注这个教程:
https://developers.google.com/identity/sign-in/web/backend-auth
谁说:
// These seven fields are only included when the user has granted the "profile" and
// "email" OAuth scopes to the application.
"email": "testuser@gmail.com",
"email_verified": "true",
"name" : "Test User",
"picture": "https://lh4.googleusercontent.com/-kYgzyAWpZzJ/ABCDEFGHI/AAAJKLMNOP/tIXL9Ir44LE/s99-c/photo.jpg",
"given_name": "Test",
"family_name": "User",
"locale": "en"
我不明白为什么我无法获得最后 5 个字段
我正在开发 API,我希望我的 API 能够自己填充用户模型,只需获取 id_token。
我可以在客户端获取这些信息,但我认为将这些额外信息发送到我的 API 不是客户端的工作,对吗?
因为你是用 ruby 做的,所以我可以建议尝试两件事
- 尝试将范围添加为数组 ["profile"、"email"]
- 从 here
添加一个额外的参数 fetch_basic_profile
令牌调用不包含个人资料信息...您认为使用:
https://www.googleapis.com/plus/v1/people/me/openIdConnect?access_token=YOUR_ACCESS_TOKEN
我在客户端使用 omniauth 来连接 google 帐户。一切正常,我能够获得 id_token 和一些更多信息,例如电子邮件、姓名、family_name、given_name 等...
以下是我在 app/config/initializer/omniauth.rb 中配置提供程序的方式:
provider :google_oauth2, ENV['GOOGLE_ID'], ENV['GOOGLE_SECRET'], scope: "profile,email"
然后,作为测试,为了验证 id_token 的真实性,我使用 Postman 发送了一个 POST 请求,例如:
https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=x
将 x 替换为 id_token 我的客户
我得到了一个有效的答案,例如:
{
"iss": "accounts.google.com",
"at_hash": "xxx-xxx",
"aud": "xxx-xxx.apps.googleusercontent.com",
"sub": "xxx",
"email_verified": "true",
"azp": "xxx-xxx.apps.googleusercontent.com",
"email": "xxx@gmail.com",
"iat": "xxx",
"exp": "xxx",
"alg": "xxx",
"kid": "xxx"
}
当我连接到我的客户时,我允许应用程序访问我的个人资料信息和我的电子邮件,我一直在关注这个教程:
https://developers.google.com/identity/sign-in/web/backend-auth
谁说:
// These seven fields are only included when the user has granted the "profile" and
// "email" OAuth scopes to the application.
"email": "testuser@gmail.com",
"email_verified": "true",
"name" : "Test User",
"picture": "https://lh4.googleusercontent.com/-kYgzyAWpZzJ/ABCDEFGHI/AAAJKLMNOP/tIXL9Ir44LE/s99-c/photo.jpg",
"given_name": "Test",
"family_name": "User",
"locale": "en"
我不明白为什么我无法获得最后 5 个字段
我正在开发 API,我希望我的 API 能够自己填充用户模型,只需获取 id_token。 我可以在客户端获取这些信息,但我认为将这些额外信息发送到我的 API 不是客户端的工作,对吗?
因为你是用 ruby 做的,所以我可以建议尝试两件事
- 尝试将范围添加为数组 ["profile"、"email"]
- 从 here 添加一个额外的参数 fetch_basic_profile
令牌调用不包含个人资料信息...您认为使用:
https://www.googleapis.com/plus/v1/people/me/openIdConnect?access_token=YOUR_ACCESS_TOKEN