Google OAuth2:缺less必需的参数:grant_type
我已经尝试了一切,阅读每个StackOverflowpost在这个问题上,但我仍然无法得到它的工作。 有趣的是,通过DHC REST API客户端(Google Chrome应用程序)发送POST请求时,我能够获得200 OK响应。
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); });
由于@BenFortune已经提到,我正在发送GET
参数作为POST
请求。 试图找出一个小时以后,这样一件小事已经被忽视了,真是太神奇了。
现在,我将这个问题归咎于OAuth提供商的不一致之处。 在同一个应用程序中,我正在对Facebook进行GET
请求以获取access_token
: https : //graph.facebook.com/oauth/access_token 。 但Google希望通过POST
请求获取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); });
检查请求编码。
在我的情况下,我发送.json和.url
使用Alamofire 3.0
- 在callback函数中,Passport-Facebook访问req对象
- REST API和移动应用程序的身份validation策略
- 我如何使用node.js来刮取需要validation的网站?
- 将Node.JS代码片段转换为Javascript(Google Apps脚本)
- 在处理POST请求时确定谁在Node上使用basicAuth进行了身份validation
- API将不会使用MSAL通过SPA传递的令牌对AAD进行身份validation
- 使用Passport无法使用Facebook进行身份validation
- API授权策略
- 为什么http-auth不能和express.static中间件一起工作?