使用Google的OpenIDConnect身份验证系统时,可以指定 email
要么 profile
或两者兼而有之 scope
参数。如果你要求的话 email
范围,“电子邮件”和“email_verified”声明将包含在 id_token
作为成功的OAuth2身份验证会话的一部分返回。
这是一个例子 来自Google的文档:
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的内容没有任何影响。要检索配置文件信息,您必须制作一个 将HTTP请求分离到不同的端点 (使用刚刚收到的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
}
理想情况下,我更愿意获取个人资料信息(只是 name
,实际上)包含在id_token JWT中,而不是必须单独调用。有没有办法指定其他字段并将它们作为声明包含在id_token中?如果没有,为什么 email
特别处理并在id_token中返回?