Skip to main content
Solved

find the authority when I use javascript SDK?


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.

View original
Did this topic help you find an answer to your question?

2 replies

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

Hi ​@Richard Lai 

Please refer to the sample code here.


Mithila Jayalath
Seasoned Practitioner
Forum|alt.badge.img

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


Reply


Cookie Policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings