【发布时间】:2015-04-29 13:43:04
【问题描述】:
我有一个使用 googleapis oauth 的 node.js 应用程序。
我的开发者控制台设置了两个重定向 uri:http://i.imgur.com/qraUa4Y.jpg
我可以使用 redirect_uri 为 /token 或 /update 对 https://accounts.google.com/o/oauth2/auth 进行初始调用
回调成功后,我尝试用以下代码交换令牌代码:
var exchangeToken = function (params) {
var post_data = querystring.stringify({
code: params.code,
client_id: credentials.client_id,
client_secret: credentials.client_secret,
redirect_uri: 'https://www.example.org/token', //this line won't work
grant_type: 'authorization_code'
});
var req = https.request({
host: 'www.googleapis.com',
path: '/oauth2/v3/token',
method: 'POST',
port: 443,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': post_data.length
}
}, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
req.write(post_data);
req.end();
};
如果我将 redirect_uri 设置为 /token 调用失败,返回
BODY: {
"error": "redirect_uri_mismatch",
"error_description": "Bad Request"
}
但是,如果我更改为 /update,它会起作用。初始请求同时接受两个 url,但这个请求 /token 失败。
怎么了?
【问题讨论】:
标签: node.js oauth google-api