node.js - Google Auth Exchange 代码、Refresh Token 和 Access Token
问题描述
我正在尝试refereh_token, access_token
使用 Google Auth Exchange 代码,查看文档但它不起作用,我正在使用 react-google-login 进行身份验证并获得code
响应,并且我正在传递code
https://accounts。 google.com/o/oauth2/token但它给出错误
{
"error": "invalid_grant",
"error_description": "Bad Request"
}
我尝试了很多方法
code=4%2FKxoYTS-jeq5-d6Lv7YvSz9ZrK0pJ_5lZsMExzNC1M0o&redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&client_id=407408718192.apps.googleusercontent.com&client_secret=************&scope=&grant_type=authorization_code
前端是 reactjs,后端是 nodejs..
解决方案
要使用referesh令牌获取访问令牌,您必须调用一个api,这将为您提供一个新的访问令牌调用POST APi https://www.googleapis.com/oauth2/v4/token
将正文作为 x-www-form-urlencoded 传递,即
标头作为 Content-Type : application/x-www-form-urlencoded
身体
client_secret:'xxxxxxxxxxxxdxxxxxxSSd'<YourClientSecret>
授予类型:刷新令牌'
refresh_token : '1/DDPkddk514451xxxxxxxx'<YourRefreshToken>
client_id : 'xxxxxxxxxxxxxxx' <YourClientID>
如需更多参考,您可以阅读此https://developers.google.com/identity/protocols/OAuth2WebServer
推荐阅读
- android - LiveData(MutableLiveData) 和数据绑定上升错误(调用观察者方法失败)
- sql - 如何在查询中显示以下数据?
- javascript - 在其他视图 mvc 中绑定来自 Partial 视图的按钮事件
- c - 共享库内部程序集全局变量的更改未从外部反映在 linux 中的 C 程序中
- javascript - Javascript TypeError: $.ajax 不是函数问题
- c# - 如何确保在子类中定义静态成员
- java - mysql-connector 8.0 中是否需要通过 `Class.forName()` 注册驱动程序?
- sql - 选择列中具有相同数据的行
- ruby-on-rails - rails puma nginx 111:连接被拒绝
- c - 如果二进制文件的内容出现在另一个二进制文件中,如何在 C 中搜索?