Hi,
I have an old C# program connecting to EWS with the old standard method.
Now I have to use the oAuth2 method and I'm struggling. Could someone please be so kind and help me ?
My program uses always the same username/email address with the same password and adds/deletes/updates calendar entries.
I'm using this code here to get the token and after several tries I'm getting no error messages:
var cca = ConfidentialClientApplicationBuilder
.Create(ConfigurationManager.AppSettings["appId"])
.WithClientSecret(ConfigurationManager.AppSettings["clientSecret"])
.WithTenantId(ConfigurationManager.AppSettings["tenantId"])
.Build();
var ewsScopes = new string[] { "https://outlook.office365.com/.default" };
var authResult = await cca.AcquireTokenForClient(ewsScopes)
.ExecuteAsync();
var ewsClient = new ExchangeService();
ewsClient.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
ewsClient.Credentials = new OAuthCredentials(authResult.AccessToken);
ewsClient.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "username@keyman .com");
In the example code I found in the internet they listed the exchange folders of the user. I tried that and an "Unauthorized" error appeared.
I changed my sample code to add an appointment. I still get the "Unauthorized" error.
I found a lot of comments about permissions here https://www.outlook-integration.com/Docs/setupimpersonation#exch13up
Is that what is missing now ?
Also I found examples where someone used oAuth2 and connects still by using username and password ?
It feels like I found already a lot but I have to put the correct items together to make it work.
I hope someone has time to support me.
Thanks a lot in advance
Michael