SPFx React- MSGraphClientV3 call not working correctly

38 Views Asked by At

We are using MSGraphClientV3 to make graph API calls and get user properties. Below is the code.

return await this.context.msGraphClientFactory
    .getClient('3')
    .then((client: MSGraphClientV3) => {
        return client
            .api(`/users/${email}/`)
            .select(",,,properties,,,")
            .get()
            .then((response: any) => {
                console.log("User details fetched", response);
                return new User({
                    // Properties assigned to User object
                    // ...
                });
            })
            .catch((error: any) => {
                this.LogError("", error.toString(), "Error");
                console.log(error);
                return null;
            });
    });

This was working well until recently, then all of sudden we are facing issues. First 2 times there is no response and for the third call onwards there is response successfully.

The permissions requested are

{
  "webApiPermissionRequests": [
    {
      "resource": "Microsoft Graph",
      "scope": "User.Read"
    },
    {
      "resource": "Microsoft Graph",
      "scope": "User.Read.All"
    }
  ]
}

The User.Read.All is admin consented and approved.

In the console we observe these errors

POST https://login.microsoftonline.com/<>/oauth2/v2.0/token 400 (Bad Request)

GET <..site..>/_api/Microsoft.SharePoint.Internal.ClientSideComponent.Token.AcquireOBOToken?resource=%27https://graph.microsoft.com%27&clientId=%27<..id..>%27 400 (Bad Request)

We tried to update the manifest file for SharePoint Online Client Extensibility Web Application Principal "preAuthorizedApplications": [] by adding the

{
    "appId": "00000003-0000-0ff1-ce00-000000000000",
    "permissionIds": [
    "**id from oauth2Permissions**"
    ]
}

This fails and gives the error- Property preauthorizedapplications.permissionIds has a permission id that cannot be found in the AppPermissions set

The call was working fine, but suddenly started to face this issue.

0

There are 0 best solutions below