/me request is only valid with delegated authentication flow

Info Omniwish 20 Reputation points
2023-06-30T12:04:01.2033333+00:00

Hello,

In my nodejs application I would like to integrate Microsoft Graph Cloud Communication Api for creating online meeting. But getting error like /me request is only valid with delegated authentication flow. Please check my code spinets.

for Generating access token:-

const msal = require('@azure/msal-node');

const config = {
  auth: {
    clientId: 'clientId',
    clientSecret: 'clientSecret',
    authority: 'https://login.microsoftonline.com/TENANT_ID/'
  }
};

const cca = new msal.ConfidentialClientApplication(config);

async function getAccessToken() {
  const authResult = await cca.acquireTokenByClientCredential({
    scopes: ['https://graph.microsoft.com/.default']
  });

  return authResult.accessToken;
}

For Creating Online Meeting

const createMeeting = async () => {
  const token = await getAccessToken();

  const client = Client.init({
    authProvider: (done) => {
      done(null, token);
    },
  });
  
  const meeting = {
    startDateTime: '2023-06-08T14:00:00',
    endDateTime: '2023-06-08T15:00:00',
    subject: 'Example Meeting',
    isOnlineMeeting: true
  };

  try {
    const response = await client.api('/me/onlineMeetings').post(meeting);
    console.log('Meeting created:', response);
  } catch (error) {
    console.log('Error creating meeting:', error);
  }
};

Please Help me I am in trouble.

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vasil Michev 119.7K Reputation points MVP Volunteer Moderator
    2023-06-30T17:06:16.15+00:00

    You are generating an access token via the client credentials flow (via client secret or certificate), which runs in the context of an application (service principal). Thus, there is no "user" in your scenario and no "me" endpoint.
    Either change your code to obtain a token in the context of a user (i.e. use the auth code flow), or use the /user/{userId}/onlineMeetings endpoint instead.

    If you need additional details, I strongly suggest you go over the official documentation.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.