question

AmeenAhmed-9594 avatar image
0 Votes"
AmeenAhmed-9594 asked AmeenAhmed-9594 commented

Authentication error when integrating Microsoft teams using graph into angular

I have created a sample angular project using the graph tutorial. My requirement is to integrate Microsoft teams into an angular application. Using the sample project I can login using the microsoft credentials. Below code is for the access token retrieval.

async getAccessToken(): Promise<string> {
const result = await this.msalService
.acquireTokenSilent({
scopes: OAuthSettings.scopes
})
.toPromise()
.catch((reason) => {
this.alertsService.addError('Get token failed', JSON.stringify(reason, null, 2));
});

 if (result) {
   return result.accessToken;
 }

 // Couldn't get a token
 this.authenticated = false;
 return '';

}

and this is my Oauth Settings

export const OAuthSettings = {
appId: Application (client) ID from Azure portal,
redirectUri: 'http://localhost:4200',
scopes: [
"user.read",
"mailboxsettings.read",
"calendars.read",
"OnlineMeetings.ReadWrite"
]
};

this is the code using to create the meeting

private graphClient: Client;
constructor(private authService: AuthService) {

// Initialize the Graph client
this.graphClient = Client.init({
authProvider: async (done) => {
// Get the token from the auth service
const token = await this.authService.getAccessToken()
.catch((reason) => {
done(reason, null);
});

   if (token)
   {
     done(null, token);
   } else {
     done("Could not get an access token", null);
   }
 }

});
}
async createCall() {
const onlineMeeting = {
startDateTime: '2021-07-20T07:30:34.2444915-07:00',
endDateTime: '2021-07-20T15:30:34.2444915-07:00',
subject: 'User Token Meeting'
};

 await this.graphClient.api('/me/onlineMeetings').post(onlineMeeting);

}

but when I call the above function createCall(), I get 400 on and below is the response

{
"error": {
"code": "AuthenticationError",
"message": "Error authenticating with resource",
"innerError": {
"date": "2021-07-20T00:37:47",
"request-id": request-id,
"client-request-id": client-request-id
}
}
}

also the token api gets called, Request URL: https://login.microsoftonline.com/common/oauth2/v2.0/token which gives the response

{
"token_type": "Bearer",
"scope": "User.Read MailboxSettings.Read Calendars.Read openid profile",
"expires_in": 3600,
"ext_expires_in": 3600,
"access_token": access_token,
"refresh_token": refresh_token,
"id_token": id_token,
"client_info": client_info
}

so in the above response it is not showing the online meeting scope I have passed in Oauth Settings.

This is the api permission given to the application in Azure portal

  1. OnlineMeetings.ReadWrite Delegated Read and create user's online meetings

  2. OnlineMeetings.ReadWrite.All Application Read and create online meetings

  3. User.Read Delegated Sign in and read user profile

microsoft-graph-cloud-communications
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Could you attach the full error details with request id and timestamp. Also please explain if your app is multitenant as you are using https://login.microsoftonline.com/common/oauth2/v2.0/token instead of https://login.microsoftonline.com/{tenant-id}/oauth2/v2.0/token.

0 Votes 0 ·

Response for calling the api: https://graph.microsoft.com/v1.0/me/onlineMeetings
{

"code": "AuthenticationError",
"message": "Error authenticating with resource",
"innerError": {
"date": "2021-07-22T04:03:49",
"request-id": "b4ef5b72-f066-409d-8bf0-87718afdabd6",
"client-request-id": "c6e27c21-14b4-ec68-9ffb-789bef2217e9"
}

As for using the https://login.microsoftonline.com/common/oauth2/v2.0/token, I have created the project using the angular quickstart guide with the initial code setup downloaded from the documentation. Therefore that api was using. I will check with the alternate api and will report back.

0 Votes 0 ·

Update on using https://login.microsoftonline.com/common/oauth2/v2.0/token, yes our app is multitenant

0 Votes 0 ·

0 Answers