Hi,
I’m trying to update our node.js app to use Server to server oauth. I have enabled Server-to-server OAuth app in role management. All the settings in in the Server to server oauth app seeem to be ok. The app is published.
This is the error I get: Error: Failed to generate access token: {“reason”:“unsupported grant type”,“error”:“unsupported_grant_type”}
Is the grant type supposed to be “account_credentials”? Can you please review my code. I have double checked that clientid,secret and accountid are correct.
Here is my code:
private generateOauth(): Promise<string> {
const clientID: string = "xxx";
const clientSecret: string = "xxx";
const accountID = "xxx";
const authHeader = Buffer.from(`${clientID}:${clientSecret}`).toString('base64');
const data = JSON.stringify({
grant_type: 'account_credentials',
account_id: accountID,
});
const options = {
hostname: 'zoom.us',
path: '/oauth/token',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Basic ${authHeader}`,
'Content-Length': data.length,
},
};
return new Promise((resolve, reject) => {
const req = https.request(options, res => {
let responseData = '';
res.on('data', chunk => {
responseData += chunk;
});
res.on('end', () => {
if (res.statusCode === 200) {
const response = JSON.parse(responseData);
resolve(response.access_token);
} else {
reject(new Error(`Failed to generate access token: ${responseData}`));
}
});
});
req.on('error', error => {
reject(error);
});
req.write(data);
req.end();
});
}