这是有关通过刷新令牌获取访问令牌的完整示例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();
如有任何进一步的疑虑,请随时告诉我。