Dear Experts,
We have scheduler application to create/update calendar events, now we are migrating Modern Authentication. we have registered in Azure and validate token. after token validated, we are impersonate to create/update calendar event, but it shown 401 Unauthorized errors while use the Findfolders method.
try
{
// Make the interactive token request
result = await app.AcquireTokenForClient(ewsScopes)
.ExecuteAsync();
// Configure the ExchangeService with the access token
var ewsClient = new ExchangeService();
ewsClient.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
ewsClient.Credentials = new OAuthCredentials(result.AccessToken);
//Impersonate the mailbox you'd like to access.
//ewsClient.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "admin@xxxx.onmicrosoft.com");
ewsClient.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "admin@xxxx.onmicrosoft.com");
//Include x-anchormailbox header
ewsClient.HttpHeaders.Add("X-AnchorMailbox", "admin@toyotaap.onmicrosoft.com");
// Make an EWS call
**var folders = ewsClient.FindFolders(WellKnownFolderName.MsgFolderRoot, new FolderView(10));**
foreach (var folder in folders)
{
Console.WriteLine($"Folder: {folder.DisplayName}");
}
}
From above code the given line got 401 error.
var folders = ewsClient.FindFolders(WellKnownFolderName.MsgFolderRoot, new FolderView(10));
Azure Permission for reference.
Please help to give me idea to resolve this issue.