我刚试着使用OAuth2和Google API,但只得到了以下结果。唯一的问题是:在文档中,我找不到id_token的用途。
{
"access_token": "xxxx",
"token_type": "Bearer",
"expires_in": 3600,
"id_token": "veryverylongstring",
"refresh_token": "abcdefg"
}
我刚试着使用OAuth2和Google API,但只得到了以下结果。唯一的问题是:在文档中,我找不到id_token的用途。
{
"access_token": "xxxx",
"token_type": "Bearer",
"expires_in": 3600,
"id_token": "veryverylongstring",
"refresh_token": "abcdefg"
}
id_token是一个JSON Web Token(JWT)。如果您解码它,您将看到它包含多个声明,包括用户的ID。有关更多详细信息,请参见此答案。
id_token是用于OpenID Connect协议的,在此协议中,用户通过身份验证和授权。 (在身份验证和授权之间有一个重要的区别。)您将获得id_token和access_token。
id_token值包含有关用户身份验证的信息。该ID令牌类似于标准JWT格式的身份证概念,由OpenID提供程序(OIDP)签名。为了获取ID令牌,客户端需要向其OIDP发送身份验证请求。
ID令牌的特点:
ID令牌语句或声明在一个简单的JSON对象中打包:
{
"sub" : "alice",
"iss" : "https://openid.c2id.com",
"aud" : "client-12345",
"nonce" : "n-0S6_WzA2Mj",
"auth_time" : 1311280969,
"acr" : "c2id.loa.hisec",
"iat" : 1311280970,
"exp" : 1311281970
}