【发布时间】:2022-02-06 20:17:12
【问题描述】:
我在前端使用 ReactJS:我成功地从 Google 的 Oauth 服务检索到访问令牌,但它没有为我提供“当前用户”的任何个人资料信息。
我尝试使用 /userInfo 端点、?access_token={my_access_token} 查询字符串和其他一些解决方案,但我不断收到奇怪的错误。
目前我有:
const { access_token, refresh_token } = res.data; // now I have valid access_token
let userInfo = await axios.get("https://www.googleapis.com/oauth2/v3/userinfo",
{
headers: {
Authorization: `Bearer ${access_token}`
}
}); // ERROR WHEN MAKING THIS CALL.
我的具体401错误如下:
如果有更好的方法来获取用户信息(例如名字/姓氏、电子邮件等,某种唯一 ID),请告诉我。
【问题讨论】:
标签: reactjs django oauth-2.0 oauth google-oauth