function getToken()

in scp-odata-proxy-api/odataproxyapi/start.js [202:235]


function getToken(url, clientid, clientsecret) {
  return new Promise((resolve, reject) => {
    try {
      const post_options = {
        url: url + '/oauth/token',
        method: 'POST',
        headers: {
          'Authorization': 'Basic ' + Buffer.from(clientid + ':' + clientsecret).toString('base64'),
          'Content-type': 'application/x-www-form-urlencoded'
        },
        form: {
          'client_id': clientid,
          'grant_type': 'client_credentials'
        }
      }

      request(post_options, (err, res, data) => {
        if (res.statusCode === 200) {
          resolve(JSON.parse(data).access_token)
        } else {
          if (err) {
            reject(err)
          } else {
            reject(data)
          }
        }
      })

    } catch (e) {
      reject(e)
    }

  })
}