Green
Green

Reputation: 486

MS graph API: 400 AuthenticationError with "/me/onlineMeetings" request

I am trying to create an online meeting and recover its URL like explained here in the docs, but when the request is run I get this error:

{ 
    "statusCode": 400,
    "code": "AuthenticationError",
    "message": "Error authenticating with resource",
    "requestId": "652ea3be-6a97-47e8-bfc6-3d7d1d51d425",
    "date": "2020-09-01T12:53:41.000Z",
    "body": "{
        "code":"AuthenticationError",
        "message":"Error authenticating with resource",
        "innerError":{
            "date":"2020-09-01T13:53:41",
            "request-id":"652ea3be-6a97-47e8-bfc6-3d7d1d51d425"
        }
    }"
}

I tried also the get started projet for JS and it's working fine so I can't spot the problem.

here is what I used:

const msalConfig = {
  auth: {
    clientId: 'my_app_id',
    redirectUri: 'http://localhost:8080'
  },
  cache: {
    cacheLocation: "sessionStorage",
    storeAuthStateInCookie: false,
    forceRefresh: false
  }
};

const loginRequest = { scopes: [
    'openid',
    'profile',
    'user.read',
    'calendars.read',
    'User.Read.All',
    'User.Export.All'
  ]
}
const options = new MicrosoftGraph.MSALAuthenticationProviderOptions([
    'user.read',
    'calendars.read',
    'OnlineMeetings.ReadWrite'
  ]);

const onlineMeeting = {
  startDateTime:"2020-09-01T16:00:34.2444915-07:00",
  endDateTime:"2020-09-01T16:30:34.2464912-07:00",
  subject:"test meeting"
};
const authProvider = new MicrosoftGraph.ImplicitMSALAuthenticationProvider(msalClient, options);
// Initialize the Graph client
const graphClient = MicrosoftGraph.Client.initWithMiddleware({authProvider});

// then I call this inside an async function
let events = await graphClient.api('/users/my_UserPrincipalName/onlineMeetings').post(onlineMeeting);
//let events = await graphClient.api('/me/onlineMeetings').post(onlineMeeting);
// I tried with both calls and none of them worked

and here are the permissions on azure active directory: enter image description here

So any ideas on how to solve this ? thanks

Upvotes: 0

Views: 739

Answers (2)

Green
Green

Reputation: 486

I figured out how to make it work in my code: let's call my user, which I used all this time, user "A", all I did is that I simply created another user "B" in Azure Active Directory and then logging in with this new user "B" in the login screen instead of the admin user "A" that I used before..... and now it's working.enter image description here

But this does not explain the issue, so if anyone can explain the difference or why it didn't work with the first account, that would be very helpful.

Upvotes: 0

Allen Wu
Allen Wu

Reputation: 16498

You didn't provide a correct access token.

Since Create onlineMeeting only supports Delegated (work or school account) permission type, you need to get the access token with Auth code flow or Implicit flow.

The started project for JS is using Implicit flow. So you can use Implicit flow to get the access token.

Here is the example in Postman:

enter image description here

The Auth URL above is https://login.microsoftonline.com/{your tenant}/oauth2/v2.0/authorize.

enter image description here

Upvotes: 2

Related Questions