【问题标题】:(Nodejs) Google oAuth2: Required parameter is missing: grant_type(Nodejs)Google oAuth2:缺少必需的参数:grant_type
【发布时间】:2014-06-29 19:47:06
【问题描述】:

使用 Nodejs 和 Mikeal 的 Request 进行此调用。执行文档所说的所有操作here,包括 grant_type=authorization_code,但我仍然遇到同样的错误。有关我传递的确切变量和方法,请参阅屏幕截图。

这是首先明确设置 grant_type 的路径

/o/oauth2/token?grant_type=authorization_code&code=4%2F42sz3xxq4wGF9k9joYxRVop9mHi6.UpFaIUqZ_UQaaDn_6y0ZQNh869DgiwI&client_id=199079322117.apps.googleusercontent.com&client_secret=...&redirect_uri=...

【问题讨论】:

  • 你有redirect_uri的URL编码吗?
  • 我使用的是 Nodejs Request 库的 oauth 选项,它对其进行编码。我最终使用 Nodejs googleapi 的库走了一条不同的路线

标签: node.js oauth-2.0 request google-api


【解决方案1】:

事实证明,需要在初始 oauth 请求中发送重定向 uri,以便在交换令牌时有匹配的内容。

在此处发布了我的答案,解释了我如何最终不得不使用弹出窗口构建自己的 oauth 用户流(而不是在主应用程序中重定向用户)Node Google OAuth2 redirect_uri_mismatch

【讨论】:

    【解决方案2】:
    Yeah I know its a very old question but I faced the same problem today.
    and resolved the  issue as follow. 
    if you use form option it will automatically set content type
    appticationx-ww-orm-urtencoded
    
    
    
      var request = require('request');
      request.post('https://accounts.google.com/o/oauth2/token',
          {
              form: {
                  code: authorization code, // which you get from google 
                  client_secret: 'client secret',// its your app secret
                  client_id: 'client id', //app client id
                  grant_type: 'authorization_code',
                  redirect_uri: 'https://developers.google.com/oauthplayground' //this should match the redirect uri which you give while creating the client id
              }
         },function(err,res,body){
             console.log(body);
             if(err) console.log(err);
             //console.log(res);
         });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-27
      • 2014-09-04
      • 2019-12-11
      • 2012-01-02
      • 1970-01-01
      • 2019-09-14
      相关资源
      最近更新 更多