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
OnlineMeetings.ReadWrite Delegated Read and create user's online meetings
OnlineMeetings.ReadWrite.All Application Read and create online meetings
User.Read Delegated Sign in and read user profile