I have validated that my user is in the directory associated with this tenant id, as well as added as a user to the registered application associated with this clientid and I still get the following error:
'AuthenticationRequiredError: invalid_request: 700056 - [2023-12-10 22:03:29Z]: AADSTS700056: User account does not exist in organization.
import {UsernamePasswordCredential} from '@azure/identity';
import {TokenCredentialAuthenticationProvider} from '@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials/index.js';
import { Client } from '@microsoft/microsoft-graph-client';
const credential = new UsernamePasswordCredential(
'9d1d3c46-2270-4b75-9647-04a2e0f4995e',
'9fbaff4b-0387-4695-ae25-2da4bbceed76',
'[email protected]',
'*******'
);
// @microsoft/microsoft-graph-client/authProviders/azureTokenCredentials
const authProvider = new TokenCredentialAuthenticationProvider(credential, {
scopes: ['User.Read'],
});
const graphClient = Client.initWithMiddleware({ authProvider: authProvider });
const calendar = {
name: 'test'
};
await graphClient.api('/me/calendars').post(calendar);
I generated access token via ROPC via Postman:
To resolve the issue, either make use of work/school account or switch the authentication flow and make use of Authorization code flow.
To fetch the calendar details, create an Azure AD application and grant
Calendars.Read
API permission:Generate auth-code by using below endpoint:
Now generate access token by using below parameters:
I am able to fetch the calendar details successfully:
You can make use of below c# code:
Reference:
Get calendar - Microsoft Graph v1.0 | Microsoft