谷歌的OAuth2:所需参数丢失:grant_type [英] Google OAuth2: Required parameter is missing: grant_type

查看:2370
本文介绍了谷歌的OAuth2:所需参数丢失:grant_type的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了刚才的一切,看在这个问题上StackOverflow的每一个岗位,但我仍然不能得到它的工作。有趣的是,我能够通过发送DHC REST API客户端(谷歌浏览器应用程序)POS​​T请求时,得到的 200 OK 响应。

I have tried just about everything, read every StackOverflow post on this issue but I still can't get it to work. Interestingly enough, I am able to get 200 OK response when sending a POST request via DHC REST API Client (Google Chrome app).

  var url = 'https://accounts.google.com/o/oauth2/token';
  var params = querystring.stringify({
    grant_type: 'authorization_code',
    code: req.body.code,
    client_id: req.body.clientId,
    client_secret: 'HIDDEN',
    redirect_uri: req.body.redirectUri
  });
  params = querystring.unescape(params); // doesn't work with or without string escaping

  request.post(url + '?' + params, function(error, response, body) {
    console.log(body);
  });

推荐答案

POST 请求。这是惊人的这样一件小事一直想了一个多小时的数字出来后,为被忽视。

As @BenFortune has already mentioned, I was sending GET parameters as a POST request. It's amazing such a trivial thing has gone unnoticed after trying to figure it out for over an hour.

现在,我责怪不一致跨越的OAuth提供者这一点。在同一个应用程序,我做了 GET 要求的Facebook 以获得的access_token :<一个href=\"https://graph.facebook.com/oauth/access_token\">https://graph.facebook.com/oauth/access_token.但谷歌需要一个 POST ,以获取的access_token https://accounts.google.com/o/oauth2/token

Now, I blame inconsistencies across OAuth providers for this. In the same application I am doing a GET request to Facebook to obtain access_token: https://graph.facebook.com/oauth/access_token. But Google expects a POST request to obtain access_token: https://accounts.google.com/o/oauth2/token

  var url = 'https://accounts.google.com/o/oauth2/token';
  var payload = {
    grant_type: 'authorization_code',
    code: req.body.code,
    client_id: req.body.clientId,
    client_secret: 'HIDDEN',
    redirect_uri: req.body.redirectUri
  };

  request.post(url, { form: payload }, function(error, response, body) {
    console.log(body);
  });

这篇关于谷歌的OAuth2:所需参数丢失:grant_type的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆