Skip to main content

Using Bearer Authentication with the JS Client API

Using Bearer Authentication is especially useful when you'd like to use the API to perform a task without going through the work of signing in to your account first.

Corellium offers two APIs that can be used to interact with our product, the JS Client API and the Corellium API. This article will show how to use bearer authentication with the JS Client API.

JS Client API Code Example

Save the following code block as a new .js file on your local system.

var CorelliumClient = require('@corellium/client-api');

// Uncomment the line below this if you DO NOT use a unique corellium domain
// var api = new CorelliumClient.CorelliumApi()

// Uncomment the 2 lines below this if you DO use a unique corellium domain
// let myApi = new CorelliumClient.ApiClient('https://yourdomain.corellium.co/api')
// CorelliumClient.CorelliumApi(myApi);

let BearerAuth = myApi.authentications['BearerAuth'];
BearerAuth.accessToken = "Your API Token Here";

let apiInstance = new apiInstance.v1GetProjects().then((data) => {
console.log('API called successfully. First Project ID: ' + data[0].id);
}, (error) => {
console.error(error);
});

apiInstance.v1GetInstances().then((data) => {
console.log('API called successfully. First Instance ID: ' + data[0].id);
}, (error) => {
console.error(error);
});

How to Execute the Example

  1. If applicable, install Node.js and the client-api package.
brew install node
npm install @corellium/client-api --save
npm run build
  1. Save the JS Client API Code Example to a new file on your computer. For our example, we will use ~/Desktop/bearerAPIExample.js.

  2. If you do not use a unique Corellium domain, uncomment the var api = new CorelliumClient.CorelliumApi() line.

  3. If you do use a unique Corellium domain, uncomment these two lines and replace yourdomain with your domain.

let myApi = new
CorelliumClient.ApiClient('https://yourdomain.corellium.co/api')
CorelliumClient.CorelliumApi(myApi);
  1. Now, add your API token inside the double quotes in this line of code. If you do not have one, refer to our Generating an API Token article.
BearerAuth.accessToken = "Your API Token Here"
  1. Execute the example with the following command in your local terminal.
node ~/Desktop/bearerAPIExample.js