question

SathishBonifash-7332 avatar image
0 Votes"
SathishBonifash-7332 asked ·

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.

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.
22681-image.png


Please help to give me idea to resolve this issue.


azure-ad-app-registrationazure-ad-application-proxyazure-ad-passwordless-authentication
image.png (448.9 KiB)
· 3
10 |1000 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.

@SathishBonifash-7332
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 ·

@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, https://docs.microsoft.com/en-us/graph/api/calendar-post-events?view=graph-rest-1.0&tabs=http

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 ·
10 |1000 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.

@SathishBonifash-7332
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 ·