I am able to get a token fine but when I go to Login I'm getting this error:
Rebex.Net.EwsException: 'Internal server error. ExchangeImpersonation SOAP header must be present for this type of OAuth token.
Doing some googling it seems I need to add the "X-AnchorMailbox" header.
But when I try to use ews.ProvisionHeaders I'm not sure what format I'm supposed to put the string in to achieve adding this header to the login request.
I've tried var headers = new List() { "X-AnchorMailbox, yyy@example.com" };
But the login fails with Rebex.Net.EwsException: 'Authentication required.' when I do that.
Any idea how to get this to work? What am I doing wrong?
Here is my sample code:
app = ConfidentialClientApplicationBuilder.Create(clientId)
.WithClientSecret(secret)
.WithAuthority(new Uri("https://login.microsoftonline.com/<tenentidgoeshere>"))
.Build();
var result = app.AcquireTokenForClient(scopes)
.ExecuteAsync().Result;
var ews = new Rebex.Net.Ews();
ews.Connect("outlook.office365.com");
var headers = new List<string>() { "X-AnchorMailbox, yyy@example.com" };
ews.ProvisionHeaders(headers.ToArray());
ews.Login(result.AccessToken, EwsAuthentication.OAuth20);