msgraph-sdk-typescript icon indicating copy to clipboard operation
msgraph-sdk-typescript copied to clipboard

Getting started instructions are missing auth provider setup

Open waldekmastykarz opened this issue 1 year ago • 7 comments

Currently, getting started instructions are missing the steps to configure the auth provider. We're referencing our live documentation, which unfortunately isn't working, because it's incompatible with this SDK. To help developers try this SDK, we should include a fully working sample, for example:

import { ClientSecretCredential } from '@azure/identity';
import { AzureIdentityAuthenticationProvider } from '@microsoft/kiota-authentication-azure';
import { FetchRequestAdapter } from "@microsoft/kiota-http-fetchlibrary";
import { createGraphServiceClient } from "@microsoft/msgraph-sdk";
import "@microsoft/msgraph-sdk-users";
import 'dotenv/config';

(async () => {
  const credential = new ClientSecretCredential(
    process.env.TENANT_ID,
    process.env.CLIENT_ID,
    process.env.CLIENT_SECRET
  );
  const authProvider = new AzureIdentityAuthenticationProvider(credential, ['https://graph.microsoft.com/.default']);
  const requestAdapter = new FetchRequestAdapter(authProvider);
  const graphServiceClient = createGraphServiceClient(requestAdapter);

  try {
    const users = await graphServiceClient.users.get();
    console.log(JSON.stringify(users));
  }
  catch (error) {
    console.error(error);
  }
})();

waldekmastykarz avatar Feb 23 '24 11:02 waldekmastykarz

Currently, getting started instructions are missing the steps to configure the auth provider. We're referencing our live documentation, which unfortunately isn't working, because it's incompatible with this SDK. To help developers try this SDK, we should include a fully working sample, for example:

import { ClientSecretCredential } from '@azure/identity';
import { AzureIdentityAuthenticationProvider } from '@microsoft/kiota-authentication-azure';
import { FetchRequestAdapter } from "@microsoft/kiota-http-fetchlibrary";
import { createGraphServiceClient } from "@microsoft/msgraph-sdk";
import "@microsoft/msgraph-sdk-users";
import 'dotenv/config';

(async () => {
  const credential = new ClientSecretCredential(
    process.env.TENANT_ID,
    process.env.CLIENT_ID,
    process.env.CLIENT_SECRET
  );
  const authProvider = new AzureIdentityAuthenticationProvider(credential, ['https://graph.microsoft.com/.default']);
  const requestAdapter = new FetchRequestAdapter(authProvider);
  const graphServiceClient = createGraphServiceClient(requestAdapter);

  try {
    const users = await graphServiceClient.users.get();
    console.log(JSON.stringify(users));
  }
  catch (error) {
    console.error(error);
  }
})();

Hello, but even when I copy paste your version I'm getting:

TypeError: requestAdapter.send is not a function any suggestions?

drloloto avatar Mar 18 '24 16:03 drloloto

@drloloto can you report which versions of the kiota dependencies are installed in your project please? It looks like you might be using older versions.

baywet avatar Mar 18 '24 16:03 baywet

@baywet Thanks you were right! Have a nice day 👍

drloloto avatar Mar 18 '24 17:03 drloloto

i tried using this example but got an error in runtime : /Users/eyal/.nvm/versions/node/v20.13.1/bin/node ./dist/apps/integrator/src/entra-index.js Uncaught SyntaxError /Users/eyal/Projects/integrations-new/integrations/node_modules/@microsoft/kiota-authentication-azure/dist/es/src/index.js:7 export * from "./azureIdentityAuthenticationProvider"; ^^^^^^

SyntaxError: Unexpected token 'export' at wrapSafe (internal/modules/cjs/loader:1281:20) at Module._compile (internal/modules/cjs/loader:1321:27) at Module._extensions..js (internal/modules/cjs/loader:1416:10) at Module.load (internal/modules/cjs/loader:1208:32) at Module._load (internal/modules/cjs/loader:1024:12) at Module.require (internal/modules/cjs/loader:1233:19) at require (internal/modules/helpers:179:18) at (/Users/eyal/Projects/integrations-new/integrations/apps/integrator/src/entra/getClient.ts:6:1) at Module._compile (internal/modules/cjs/loader:1358:14) at Module._extensions..js (internal/modules/cjs/loader:1416:10) at Module.load (internal/modules/cjs/loader:1208:32) at Module._load (internal/modules/cjs/loader:1024:12) at Module.require (internal/modules/cjs/loader:1233:19) at require (internal/modules/helpers:179:18) at (/Users/eyal/Projects/integrations-new/integrations/apps/integrator/src/entra/getUsers.ts:3:1) at Module._compile (internal/modules/cjs/loader:1358:14) at Module._extensions..js (internal/modules/cjs/loader:1416:10) at Module.load (internal/modules/cjs/loader:1208:32) at Module._load (internal/modules/cjs/loader:1024:12) at Module.require (internal/modules/cjs/loader:1233:19) at require (internal/modules/helpers:179:18) at (/Users/eyal/Projects/integrations-new/integrations/apps/integrator/src/entra/index.ts:1:1) at Module._compile (internal/modules/cjs/loader:1358:14) at Module._extensions..js (internal/modules/cjs/loader:1416:10) at Module.load (internal/modules/cjs/loader:1208:32) at Module._load (internal/modules/cjs/loader:1024:12) at Module.require (internal/modules/cjs/loader:1233:19) at require (internal/modules/helpers:179:18) at (/Users/eyal/Projects/integrations-new/integrations/apps/integrator/src/entra-index.ts:1:1) at Module._compile (internal/modules/cjs/loader:1358:14) at Module._extensions..js (internal/modules/cjs/loader:1416:10) at Module.load (internal/modules/cjs/loader:1208:32) at Module._load (internal/modules/cjs/loader:1024:12) at executeUserEntryPoint (internal/modules/run_main:174:12) at (internal/main/run_main_module:28:49) No debugger available, can not send 'variables' Process exited with code 1

any idea why ? i am using : "@microsoft/kiota-authentication-azure": "^1.0.0-preview.48" (from package.json)

eyal-ringwald-orchid avatar Jun 03 '24 07:06 eyal-ringwald-orchid

@eyal-ringwald-orchid this is getting addressed with that PR https://github.com/microsoft/kiota-typescript/pull/1225 Can you try to upgrade your kiota dependencies to the latest version (today) and see if you still run into the issue? (we might need to roll out new version of graph core and this library here)

baywet avatar Jun 11 '24 12:06 baywet

now the new api has changed so there is no such thing as graphServiceClient.user , so i am leaving this try aside.

eyal-ringwald-orchid avatar Jun 26 '24 09:06 eyal-ringwald-orchid

@eyal-ringwald-orchid did you install and import the @microsoft/msgraph-sdk-users package? Also it should be users (plural)

baywet avatar Jun 26 '24 12:06 baywet