当使用谷歌的OpenIDConnect认证系统,它可以指定email
或profile
或两者的scope
参数.如果您请求email
范围,则"email"和"email_verified"声明将包含在id_token
作为成功OAuth2身份验证会话的一部分返回的声明中.
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"
}
Run Code Online (Sandbox Code Playgroud)
但是,请求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
}
Run Code Online (Sandbox Code Playgroud)
理想情况下,我更愿意获取name
id_token JWT中包含的配置文件信息(只是,实际上),而不是必须单独调用.有没有办法指定其他字段并将它们作为声明包含在id_token中?如果没有,为什么要email
特别处理并返回id_token?