Authenticating your Token

Before you start

Before you can start authenticating your token you must first be able to acquire a token. If you haven't done so you can look through this guide.


Getting Started

To authenticate your token you will be creating a NodeJS application. Verify that you have the latest version of NodeJS installed on your workstation.


You will also need to download the most current version of python.



for this guide you can either create a new project file or use the one created from:


To create a new project file enter the following in terminal The set-up will walk you through the creation steps.

npm init

This will generate a package.json file, open the file then add the following to the scripts section:

"start": "node index.js",

In your project, create a file named index.js if one doesn't already exist.

Next you will be installing the following dependencies:

  • Axios
  • Crypto
  • Cors
  • Express
  • Express Generator

To do so enter the following commands in your terminal:

npm i axios
npm i Crypto
npm i cors
npm i -g express-generator
npm i express --save
This image has an empty alt attribute; its file name is image-4.png

Creating your Server

In your index.js add the following dependencies:

var express = require("express");
const axios = require('axios');
const { debug } = require('console');
const crypto = require('crypto');
const cors = require('cors')

We will now begin building our NodeJS server for authentication.

First we will be adding the cors Options

var corsOptions = {    origin: '*',    optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204  }  

We will now add the following to create the Express methods

var app = express();

app.listen(3000, () => {
 console.log("Server running on port 3000");

Now we will create the method that will listen for authentication requests, this is done through app.get

app.get('/request', cors(corsOptions), async (req, res) => {


Inside the app.get method we will first add the following to generate the token

const d = new Date();

      const customerId = "[]";
    const appKey = "[]";
    const endUserId = "[]";
    const nonce = d.getTime();
    const secret = "[]";

    const dataToEncrypt = "customerId=" + customerId + "&appKey=" + appKey + "&endUserId=" + endUserId + "&nonce=" + nonce;

    const hash = crypto.createHmac('sha256', secret).update(dataToEncrypt).digest('base64');

    let url = "https://api.prod-mirror.gocircle.ai/api/token?" + dataToEncrypt + "&signature=" + hash;

Replace [] with your account information.

Further details on how to gather your account information can be found here.


Finally still inside the app.get method we will add the following code to return any requests made to the server.

let json = "";

    const response = await axios.get(url);
        json = JSON.parse(response.data.toString().replace(/\r\n/g, ""));


Once complete your script should look something like this.

Testing the Server

To test that the server is running open the Terminal and enter npm start

If the server is working you will see the following:

To test that the request method is functioning correctly you can use a tool like Postman.


From the home tab click on the "Create New" link

Select HTTP Request

in the url bar enter the the following and click send.

If the request was successful you will see the following

Authenticating on the Front End

Now that you have created a express request you can now authenticate it with the front end.

In a separate folder create a new file and name it index.html

To start building your webpage enter the following:

<!DOCTYPE html>








In the <head> </head> section add the following dependencies:

    <script src="https://internal.prod-mirror.gocircle.ai/api/demo/lib/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://internal.prod-mirror.gocircle.ai/api/demo/lib/bootstrap/bootstrap.bundle.min.js"></script>
        var timestamp = new Date().getTime();
        document.write(`\x3Cscript src="https://internal.prod-mirror.gocircle.ai/api/prod-mirror.gocircle.ai-bundle.js?t=${timestamp}">\x3C/script>`);
        document.write(`\x3Cscript src="https://internal.prod-mirror.gocircle.ai/api/prod-mirror.gocircle.ai.js?t=${timestamp}">\x3C/script>`);


    <link rel="stylesheet" href="https://internal.prod-mirror.gocircle.ai/api/demo/lib/bootstrap/bootstrap.min.css">

lastly in the <script> </script> section we will add the following code to send the request to the server.

async function getCircleToken() {
    let result = await fetch("http://localhost:3000/request");
    let json = await result.json();

return JSON.stringify(json.Token).replaceAll('"',"");


$(document).ready(async function(){

    const token = await getCircleToken();

    // all code and circles go in here


    let appKey = "[]"

let iniResult = await Circle.initialize(appKey, token);

if (iniResult && iniResult.Status.Result) {
  // CircleService is running and token is authorized


Replace [] with your current AppKey

let appKey = "[]"


To verify your webpage is working launch Command prompt (Terminal on Mac) and navigate to the folder your index.html is located in.

start the python service by entering the following command.

python -m http.server [<portNo>]

Replace [<portNo>] with the port you are using. Default 8000

finally open your Index.html file in a web browser. Right click on the page and click inspect element. Click on the console tab and you should see your token listed.