【问题标题】:Google Auth Exchange Code , Referesh Token and Access TokenGoogle Oauth 交换码、刷新令牌和访问令牌
【发布时间】:2019-03-16 11:57:40
【问题描述】:

我正在尝试使用 Google Auth Exchange 代码获取 refereh_token, access_token,查看文档但它不起作用,我正在使用 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..

【问题讨论】:

    标签: node.js reactjs google-authentication refresh-token


    【解决方案1】:

    要使用 referesh 令牌获取 ACCESS 令牌,您必须调用一个 api,它会为您提供一个新的访问令牌 调用 POST APi https://www.googleapis.com/oauth2/v4/token

    将正文作为 x-www-form-urlencoded 传递,即

    标题为 内容类型:application/x-www-form-urlencoded

    身体

    client_secret : 'xxxxxxxxxxxxdxxxxxxSSd'<YourClientSecret>

    grant_type : refresh_token'

    refresh_token : '1/DDPkddk514451xxxxxxxx' <YourRefreshToken>

    client_id : 'xxxxxxxxxxxxxxx' <YourClientID>

    更多参考你可以阅读这个https://developers.google.com/identity/protocols/OAuth2WebServer

    【讨论】:

      猜你喜欢
      • 2017-06-09
      • 2015-04-01
      • 2014-05-12
      • 2013-08-17
      • 1970-01-01
      • 2021-09-13
      • 1970-01-01
      • 2015-02-24
      • 2021-11-21
      相关资源
      最近更新 更多