Trying to use node-fetch and it comes back with an empty response: {"size": 0, "timeout": 0}. This is supposed to be an OAUTH2 Access Token (basically a JWT). What did I do wrong?
async function getAccessToken() {
if (argumentParserResult.authenticationScheme == 'OAUTH2') {
const fetch = require('node-fetch');
const url = argumentParserResult.resourceUrl;
let body = {
'grant_type': 'client_credentials',
'client_id': argumentParserResult.clientId,
'scope': argumentParserResult.clientScope,
'client_secret': argumentParserResult.clientSecret
}
console.log('POST ' + argumentParserResult.authorizationUrl);
console.log(JSON.stringify(body));
let response = await fetch(argumentParserResult.authorizationUrl, {
method: 'POST',
body: JSON.stringify(body)
});
console.log('Access token request repsonse: ' + JSON.stringify(response));
process.exit(1);
}
}
If I hit this with a REST client, it comes back successfully using
POST <some-url>
:
Form-encode
grant_type: client_credentials
client_id: some-client-id
scope: some-long-scope-string
client_secret: client-secret
I'm using node-fetch 2.6.6.