microsoftgraph / msgraph-sdk-typescript

MIT License
17 stars 3 forks source link

Getting started instructions are missing auth provider setup #507

Open waldekmastykarz opened 4 months ago

waldekmastykarz commented 4 months ago

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);
  }
})();
drloloto commented 3 months ago

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?

baywet commented 3 months ago

@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.

drloloto commented 3 months ago

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

eyal-ringwald-orchid commented 1 month ago

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)

baywet commented 1 month ago

@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)

eyal-ringwald-orchid commented 2 weeks ago

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

baywet commented 2 weeks ago

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