在 Azure OAuth 中获取新令牌(使用 refresh_token)从 NodejS 得到 404,在 cURL 中工作正常
Getting new token (with refresh_token) in Azure OAuth gives 404 from NodejS, works fine from cURL
我正在尝试从 Azure 获取新令牌,但出现 404 错误。当我转储请求正文和参数,然后将其转换为 cURL 请求时,一切正常。有什么想法吗?
{ host: 'login.microsoftonline.com',
method: 'POST',
port: 443,
path: '/common/oauth2/token',
headers:
{ 'Content-Type': 'application/x-www-form-urlencoded'
}
}
请求正文:
refresh_token=SNIP&client_id=SNIP&client_secret=SNIP&grant_type=refresh_token
我知道令牌和客户端信息是正确的,因为它在 curl 中工作..
我正在使用 Node 的 https.request
库进行调用。有什么想法吗?
这是通过 https.request
通过刷新令牌获取访问令牌的完整示例:
var https = require('https');
var querystring = require('querystring');
var postData = querystring.stringify({
refresh_token: "<refresh_token>",
client_id: "<client_id>",
client_secret:"<client_secret>",
grant_type:"refresh_token"
});
var options = {
hostname: 'login.microsoftonline.com',
port: 443,
path: '/<tenant_id>/oauth2/token',
method: 'POST',
headers:
{
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': postData.length
}
};
var req = https.request(options, function (res) {
var result = '';
res.on('data', function (chunk) {
result += chunk;
});
res.on('end', function () {
console.log(result);
});
res.on('error', function (err) {
console.log(err);
})
});
// req error
req.on('error', function (err) {
console.log(err);
});
//send request witht the postData form
req.write(postData);
req.end();
如有任何疑问,请随时告诉我。
我正在尝试从 Azure 获取新令牌,但出现 404 错误。当我转储请求正文和参数,然后将其转换为 cURL 请求时,一切正常。有什么想法吗?
{ host: 'login.microsoftonline.com',
method: 'POST',
port: 443,
path: '/common/oauth2/token',
headers:
{ 'Content-Type': 'application/x-www-form-urlencoded'
}
}
请求正文:
refresh_token=SNIP&client_id=SNIP&client_secret=SNIP&grant_type=refresh_token
我知道令牌和客户端信息是正确的,因为它在 curl 中工作..
我正在使用 Node 的 https.request
库进行调用。有什么想法吗?
这是通过 https.request
通过刷新令牌获取访问令牌的完整示例:
var https = require('https');
var querystring = require('querystring');
var postData = querystring.stringify({
refresh_token: "<refresh_token>",
client_id: "<client_id>",
client_secret:"<client_secret>",
grant_type:"refresh_token"
});
var options = {
hostname: 'login.microsoftonline.com',
port: 443,
path: '/<tenant_id>/oauth2/token',
method: 'POST',
headers:
{
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': postData.length
}
};
var req = https.request(options, function (res) {
var result = '';
res.on('data', function (chunk) {
result += chunk;
});
res.on('end', function () {
console.log(result);
});
res.on('error', function (err) {
console.log(err);
})
});
// req error
req.on('error', function (err) {
console.log(err);
});
//send request witht the postData form
req.write(postData);
req.end();
如有任何疑问,请随时告诉我。