OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Password-Based Authentication for the Access Token of the RingCentral login APIs

  • Thread starter Thread starter Awais Ahmad
  • Start date Start date
A

Awais Ahmad

Guest
Please help me with the password-based authentication to get the access token of RingCentral through APIs from which I will download the call recordings of the voice calls.

Please help me with this issue.

I have tried the following code for this purpose but was unable to the access token:

Code:
const https = require('https');
const querystring = require('querystring');

// OAuth settings
const endpoint = '/restapi/oauth/token';
const url = 'platform.ringcentral.com';

// Client ID and secret
const clientId = 'process.env.CLIENT_ID';
const clientSecret = 'process.env.CLIENT_SECRET';

// User credentials
const username = 'process.env.USERNAME';
const password = 'process.env.PASSWORD';

// Basic authorization header
const basicAuth = Buffer.from(`${clientId}:${clientSecret}`).toString('base64');

// Request headers
const headers = {
  'Content-Type': 'application/x-www-form-urlencoded',
  'Authorization': `Basic ${basicAuth}`,
};

// Request body for the resource owner password credentials grant
const body = querystring.stringify({
  grant_type: 'password',
  username: username,
  password: password,
});

const options = {
  host: url,
  path: endpoint,
  method: 'POST',
  headers: headers,
};

// Function to make the POST request
const makeRequest = () => {
  const request = https.request(options, (response) => {
    let data = '';

    response.on('data', (chunk) => {
      data += chunk;
    });

    response.on('end', () => {
      console.log('Response:', data);
    });
  });

  request.on('error', (error) => {
    console.error('Error:', error.message);
  });

  request.write(body);
  request.end();
};

// Call the function to make the request
makeRequest();

But it gives me the following Error:

Code:
Response: {
  "error" : "unauthorized_client",
  "errors" : [ {
    "errorCode" : "OAU-251",
    "message" : "Unauthorized for this grant type"
  } ],
  "error_description" : "Unauthorized for this grant type"
}

<p>Please help me with the password-based authentication to get the access token of RingCentral through APIs from which I will download the call recordings of the voice calls.</p>
<p>Please help me with this issue.</p>
<p>I have tried the following code for this purpose but was unable to the access token:</p>
<pre><code>const https = require('https');
const querystring = require('querystring');

// OAuth settings
const endpoint = '/restapi/oauth/token';
const url = 'platform.ringcentral.com';

// Client ID and secret
const clientId = 'process.env.CLIENT_ID';
const clientSecret = 'process.env.CLIENT_SECRET';

// User credentials
const username = 'process.env.USERNAME';
const password = 'process.env.PASSWORD';

// Basic authorization header
const basicAuth = Buffer.from(`${clientId}:${clientSecret}`).toString('base64');

// Request headers
const headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': `Basic ${basicAuth}`,
};

// Request body for the resource owner password credentials grant
const body = querystring.stringify({
grant_type: 'password',
username: username,
password: password,
});

const options = {
host: url,
path: endpoint,
method: 'POST',
headers: headers,
};

// Function to make the POST request
const makeRequest = () => {
const request = https.request(options, (response) => {
let data = '';

response.on('data', (chunk) => {
data += chunk;
});

response.on('end', () => {
console.log('Response:', data);
});
});

request.on('error', (error) => {
console.error('Error:', error.message);
});

request.write(body);
request.end();
};

// Call the function to make the request
makeRequest();
</code></pre>
<p>But it gives me the following Error:</p>
<pre class="lang-json prettyprint-override"><code>Response: {
"error" : "unauthorized_client",
"errors" : [ {
"errorCode" : "OAU-251",
"message" : "Unauthorized for this grant type"
} ],
"error_description" : "Unauthorized for this grant type"
}
</code></pre>
 

Latest posts

Top