如何从 id token google 登录中获取名字和头像
How to get first name and profile picture from id token google sign in
所以我正在与 google 从网站登录进行集成,所以基本上这里的流程是:
google 登录 -> 获取令牌 ID 并发送给身份验证 rest api -> rest api 获取用户名、个人资料图片和电子邮件,然后注册用户。
我的问题是我无法发现如何获取用户名和个人资料图片。即使在 userinfo.email 和 userinfo.profile 范围内,令牌 ID 也只在负载中存储 UserId 和电子邮件。这是我的令牌 ID 有效载荷现在看到的内容:
{
"iss": "accounts.google.com",
"azp": "######",
"aud": "######",
"sub": "######",
"email": "gsalomaoc@gmail.com",
"email_verified": true,
"iat": 1639009337,
"exp": 1639012937,
"jti": "######"
}
我期待在负载中发送个人资料图片和名字和姓氏。谁能帮我弄清楚如何获得这些字段?
感谢任何帮助。
你可以使用这个:
www.googleapis.com/oauth2/v1/userinfo
而不是:
oauth2.googleapis.com/tokeninfo
试试看:https://developers.google.com/oauthplayground/
来源:How to get user profile picture from Google Chat Bot using Google App Script?
所以我正在与 google 从网站登录进行集成,所以基本上这里的流程是: google 登录 -> 获取令牌 ID 并发送给身份验证 rest api -> rest api 获取用户名、个人资料图片和电子邮件,然后注册用户。 我的问题是我无法发现如何获取用户名和个人资料图片。即使在 userinfo.email 和 userinfo.profile 范围内,令牌 ID 也只在负载中存储 UserId 和电子邮件。这是我的令牌 ID 有效载荷现在看到的内容:
{
"iss": "accounts.google.com",
"azp": "######",
"aud": "######",
"sub": "######",
"email": "gsalomaoc@gmail.com",
"email_verified": true,
"iat": 1639009337,
"exp": 1639012937,
"jti": "######"
}
我期待在负载中发送个人资料图片和名字和姓氏。谁能帮我弄清楚如何获得这些字段?
感谢任何帮助。
你可以使用这个: www.googleapis.com/oauth2/v1/userinfo
而不是: oauth2.googleapis.com/tokeninfo
试试看:https://developers.google.com/oauthplayground/
来源:How to get user profile picture from Google Chat Bot using Google App Script?