-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Confusion with @microsoft/microsoft-graph-client #479
Comments
Hi @tboulis
The idea currently being:
Over time, we'll most likely rename the repositories from I hope this clarifies the current state of things and future plans. |
That's awesome @baywet , thank you clarifying this 🙏 |
@baywet Could you please pin this issue or put the table in the repo README? I'm wasting a lot of time figuring out where I am supposed to get the Client object. When all I want is to call graph API with my user.
the code here imports some The API I am trying to call is |
@1oglop1 where did you get this client initialization code from? You shouldn't need the Also, if you want to call beta endpoints, you need to install the beta SDK instead documentation |
@baywet I tried to view the documentation, but this is my main beef with Microsoft docs, one page with incomplete examples leads to another page with incomplete examples. Example for this case: this documentation ( link from ) msgraph-sdk-typescript/README.md Line 32 in 6c55abb
Shows incomplete an example and delegates the creation of import { FetchRequestAdapter } from "@microsoft/kiota-http-fetchlibrary";
import { createGraphServiceClient } from "@microsoft/msgraph-sdk";
import "@microsoft/msgraph-sdk-users";
const requestAdapter = new FetchRequestAdapter(authProvider);
const graphServiceClient = createGraphServiceClient(requestAdapter);
const jane = await graphServiceClient.users.byUserId("[email protected]").get(); When the user clicks on the link choose a Microsoft Graph authentication provider. // @azure/identity
const credential = new InteractiveBrowserCredential({
tenantId: 'YOUR_TENANT_ID',
clientId: 'YOUR_CLIENT_ID',
redirectUri: 'http://localhost',
});
// @microsoft/microsoft-graph-client/authProviders/azureTokenCredentials
const authProvider = new TokenCredentialAuthenticationProvider(credential, {
scopes: ['User.Read'],
});
const graphClient = Client.initWithMiddleware({ authProvider: authProvider }); As a complete newcomer to AzureSDKs it took me several hours to put the pieces together to authenticate as "me" just by running Working code example (click to unfold)import * as identity from "@azure/identity";
import * as gc from "@microsoft/microsoft-graph-client";
import {
TokenCredentialAuthenticationProvider,
TokenCredentialAuthenticationProviderOptions,
} from "@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials";
(async () => {
const tokenCredential = identity.getDefaultAzureCredential();
const options: TokenCredentialAuthenticationProviderOptions = {
scopes: [
// '.default',
"https://graph.microsoft.com/.default",
],
getTokenOptions: {},
};
const authProvider = new TokenCredentialAuthenticationProvider(tokenCredential, options);
const client = gc.Client.initWithMiddleware({
authProvider: authProvider,
});
const subscriptionId = "1234-uuid"; // azure subscription id
const resourceGroup = "DefaultResourceGroup-WEU";
const partnerTopic = "msGraphGroups2";
const location = "westeurope";
const resp = await client.api('/subscriptions')
.get();
console.log(resp);
})(); When I tried using this SDK, I got just as confused as I was at the start because the Say I overcome the authentication problem, try this (new) SDK. Here's my resolution process:
Now step 3. is also slightly confusing due to API structure. Based on my experience with other SDKs I'd be looking for the SDK named IMO the authors of the docs assumed a higher level of familiarity with Microsoft APIs which is often not the case and I missed several clues which caused me a cognitive overhead. Minor rants:
const requestAdapter = new FetchRequestAdapter(authProvider); // Type mismatch - likely due to legacy @microsoft/microsoft-graph-client
const graphClient = createGraphServiceClient(requestAdapter);
const appRequest = graphClient.applications.byApplicationId("");
const result = await appRequest.get() // why is this undefined instead of error? I hope this write-up shows the missing cognitive links, please let me know if there is anything difficult to understand (English is not my first language). This situation evokes 15 standards (xkcd) feelings and I am a bit frustrated by the inability to do a seemingly simple thing. |
Thank you so much for this amazing feedback! Yes I can see where the confusion comes from here.
This links points at samples for the old SDK, I think we put the link here assuming the samples would get updated upon general availability, but until then it creates more confusion than anything. @jasonjoh do you think it'd be possible to add a set of "TypeScript (Preview)" tabs on this page and link to that instead from here? (or rename the current TypeScript tab to javascript to be consistent with the rest of the documentation and add a new TypeScript tab)
Yes the mix between the two generations of SDKs created more confusion than anything. We changed the approach from the initial previews of this new SDK. And they are now entirely separate products to avoid any further confusion. Sorry the auth docs lead you back to the older SDK.
Yes the operations docs only have a JavaScript tab at this moment, snippets for this new TypeScript preview SDK is still work to be done. microsoftgraph/microsoft-graph-devx-api#1939
I'm not sure I understand why you need applications package for an operation under service principals at this stage?
This is most likely a bug, the SDK should have complained about passing an empty string to begin with. Can you file a separate issue for that please? Note: the error probably comes from a lack of validation here |
I'm concerned that will introduce more confusion by using different SDKs across JS/TS. We've also adopted the policy that our docs will reference GA versions of SDKs only. During preview, it might make sense to remove the link back to our docs using the GA SDK and just put some inline examples of a few of the more common auth providers to help folks get started. |
Thanks for creating the first issue @1oglop1
This is most likely a bug, the SDK should have complained about passing an empty string to begin with. |
Sorry for my late reply, I noticed I did not hit the button 😮💨 🌴
Yes, that is exactly my point, I should not need The endpoint Line 29 in 460cd99
But when you look at the REST API documentation it follows the structure from here:
I would not worry about that, I've never executed the code, only type completion so that I can explore the API via using the client instead of searching docs. @baywet thank you for #628! 🙌 // @azure/identity
const credential = identity.getDefaultAzureCredential();
// @microsoft/kiota-authentication-azure
const authProvider = new AzureIdentityAuthenticationProvider(credential, ["https://graph.microsoft.com/.default"]); |
Thank you for the additional information . |
Your NPM page is
https://www.npmjs.com/package/@microsoft/msgraph-sdk-JAVASCRIPT
Your github page URL is
https://github.com/microsoftgraph/msgraph-sdk-TYPESCRIPT
Your github repo name is
microsoftgraph/msgraph-sdk-TYPESCRIPT
.And your documentation about setting up an Authentication provider points to this Microsoft docs page which references a completely different package, for which the:
NPM page is
https://www.npmjs.com/package/@microsoft/microsoft-graph-client
Github page is
https://github.com/microsoftgraph/msgraph-sdk-JAVASCRIPT
Github repo is
microsoftgraph/msgraph-sdk-JAVASCRIPT
Im trying use to your app with our
msal.ConfidentialClientApplication
but with no luck, the authProviders have different types (callback for@microsoft/microsoft-graph-client
and class for your app)I hope you can see why I am confused 😅
The text was updated successfully, but these errors were encountered: