【发布时间】:2015-11-17 10:56:35
【问题描述】:
使用 Google 的 OpenIDConnect 身份验证系统时,可以在 scope 参数中指定 email 或 profile 或同时指定两者。如果您请求 email 范围,“email”和“email_verified”声明将包含在作为成功 OAuth2 身份验证会话的一部分返回的 id_token 中。
这是一个例子from Google's documentation:
ID 令牌的有效负载
ID 令牌是包含一组名称/值对的 JSON 对象。 这是一个示例,为便于阅读而格式化:
{"iss":"accounts.google.com",
"at_hash":"HK6E_P6Dh8Y93mRNtsDB1Q",
"email_verified":"true",
"sub":"10769150350006150715113082367",
"azp":"1234987819200.apps.googleusercontent.com",
"email":"jsmith@example.com",
"aud":"1234987819200.apps.googleusercontent.com",
"iat":1353601026,
"exp":1353604926,
"hd":"example.com"
}
但是,请求profile 范围似乎对 id_token 的内容没有任何影响。为了检索配置文件信息,您必须创建一个separate HTTP request to a distinct endpoint(使用您刚刚收到的 access_token 进行身份验证)以获取看起来非常相似但包含更多信息的文档:
{
"kind": "plus#personOpenIdConnect",
"gender": string,
"sub": string,
"name": string,
"given_name": string,
"family_name": string,
"profile": string,
"picture": string,
"email": string,
"email_verified": "true",
"locale": string,
"hd": string
}
理想情况下,我宁愿获取包含在 id_token JWT 中的配置文件信息(实际上只是 name),而不必进行单独的调用。有没有办法指定其他字段并将它们作为声明包含在 id_token 中?如果不是,为什么email会被特殊处理并在id_token中返回?
【问题讨论】:
标签: oauth-2.0 google-openid openid-connect google-oauth