Skip to main content
Answer

find the authority when I use javascript SDK?

  • February 7, 2025
  • 2 replies
  • 85 views

Forum|alt.badge.img

I want to use node JS express as my back server to get data from cognite refer to their
https://developer.cognite.com/sdks/js/

for the backend:
import { ConfidentialClientApplication } from "@azure/msal-node";
import { CogniteClient } from "@cognite/sdk";

async function quickstart() {
  const pca = new ConfidentialClientApplication({
    auth: {
        clientId: 'YOUR CLIENT ID',
        clientSecret: 'YOUR CLIENT SECRET',
        authority: 'INSERT AUTHORITY HERE'
    }
  });

  async function getToken() {
    var response = await pca.acquireTokenByClientCredential({
        scopes: ['INSERT SCOPE HERE'],
        skipCache: true,
      });
      return response.accessToken;
  }

  const client = new CogniteClient({
    appId: 'Cognite SDK samples',
    baseUrl: 'YOUR BASE URL',
    project: 'YOUR CDF PROJECT NAME',
    getToken: getToken
  });

  const assets = await client.assets.list();
  console.log(assets);
}

quickstart();

What is the authority and how can I find my authority?

Best answer by Mithila Jayalath

Hi ​@Richard Lai 

Please refer to the sample code here.

2 replies

Mithila Jayalath
Seasoned Practitioner
Forum|alt.badge.img+8
  • Seasoned Practitioner
  • Answer
  • February 7, 2025

Hi ​@Richard Lai 

Please refer to the sample code here.


Mithila Jayalath
Seasoned Practitioner
Forum|alt.badge.img+8
  • Seasoned Practitioner
  • February 10, 2025

@Richard Lai I marked this question as answered. Let us know if you come across any issues.