SathishBonifash-7332 avatar image
0 Votes"
SathishBonifash-7332 asked JamesHamil-MSFT commented

Create event in outlook calendar using Azure AD, getting 401 unauthorized while impersonate to access others calendar.

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.

// Make the interactive token request
result = await app.AcquireTokenForClient(ewsScopes)

             // Configure the ExchangeService with the access token
             var ewsClient = new ExchangeService();
             ewsClient.Url = new Uri("");
             ewsClient.Credentials = new OAuthCredentials(result.AccessToken);

             //Impersonate the mailbox you'd like to access.
             //ewsClient.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "");
             ewsClient.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "");

             //Include x-anchormailbox header
             ewsClient.HttpHeaders.Add("X-AnchorMailbox", "");

             // 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.

image.png (448.9 KiB)
· 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.

Thank you for the post! Are you following any documentation to enable the creation of events in Outlook using AzureAD?

0 Votes 0 ·

No documentation but i cannot connect Azure AD service to ceare/update event? do you have any idea

0 Votes 0 ·

Hi, are there any updates with this case? If not, please select the appropriate response as "Answered." Otherwise please let us know how we can assist you.

0 Votes 0 ·

1 Answer

soumi-MSFT avatar image
1 Vote"
soumi-MSFT answered JamesTran-MSFT commented

@SathishBonifash-7332, I guess, here you need to use the Microsoft Graph API to create the User's outlook calendar. You can use the following doc to get more understanding on the API,

Also, would like to state that when you use this API, you would have to fetch a token from AAD as a user, and only that user can use that token to create a calendar for himself/herself.

In the case of shared calendars only, someone else can create a calendar event for someone else.

Hope this helps.

Do let us know if this helps and if there are any more queries around this, please do let us know so that we can help you further. Also, please do not forget to accept the response as Answer; if the above response helped in answering your query.

· 1
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.

I just wanted to check in and see if you had a chance to review Soumi's answer, please let us know if you require additional assistance or if you were able to resolve this issue.

0 Votes 0 ·