var cca = ConfidentialClientApplicationBuilder
.Create("eXXXXXXX-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
.WithClientSecret("xxxxx~xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
.WithTenantId("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx^)
.Build();
var appScopes = new string[] { "https://outlook.office365.com/.default" };
//get token with App Auth
var authResult = await cca.AcquireTokenForClient(appScopes).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(authResult.AccessToken);
ewsClient.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "max.mustermann@xxxxxxxxxxxxxxx.de");
But when I try to use the Aspose EWSClient I run into this error, as soon as I call “GetEWSClient” →
ExchangeImpersonation SOAP header must be present for this type of OAuth token
Here the part that doesn´t work
var cca = ConfidentialClientApplicationBuilder
.Create("eXXXXXXX-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
.WithClientSecret("xxxxx~xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
.WithTenantId("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx^)
.Build();
var appScopes = new string[] { "https://outlook.office365.com/.default" };
var authResult = cca.AcquireTokenForClient(appScopes).ExecuteAsync().GetAwaiter().GetResult();
NetworkCredential cred = new OAuthNetworkCredential(authResult.AccessToken);
var ewsClient = EWSClient.GetEWSClient("https://outlook.office365.com/EWS/Exchange.asmx", cred);
Where do I have do call the ImpersonateUser method?
Aspose.Email 23.7.0 is used.
Language: C#