Closed LaGuillotine closed 3 years ago
I'm having the same issue and can't seem to understand it either. Were you able to figure it out?
As far as I remember if Impersonation
is enabled on server side then all EWS requests should contain ExchangeImpersonation
in SOAP header.
Thanks Pavel, that was exactly it for me as well.
I've have the same error switching to OAuth using Application Permissions when doing tasks not specific to a mailbox.
e.g. if I use ResolveName
on ExchangeService. At this point I don't require access to a specific mailbox, I just need to resolve a name to get a folder ID. I also get the same with ConvertIds
which I'm using for a simple lightweight call for a connectivity check (call something basic to hit the server, tests credentials are okay to access Exchange and gets server version).
Once I want to access a mailbox (calendar in my case) I can set the Impersonation ID to that mailbox which is fine.
However for basic lookups I need an ID also otherwise this error occurs. I assume because I'm no longer logged in as a specific user when I was using basic auth and a service account,
So this means having a dedicated service account to specify as Impersonation ID. One of the benefits of OAuth and Application Permission if granted full access, is no need for a service account any more, but at the moment it looks like I still need one.
Update - it seems I can use any mailbox for ResolveName
, so it doesn't have to be a service account, just a room mailbox will do (no licence required). However this is annoying for configuration for the end user as they'll be asked to specify a valid email address along with App ID, Tenant ID & Client Secret. Just so the ExchangeImpersonation header gets set to something valid for those kinds of calls.
For service account without a mailbox license, for OAuth to work, Try constructing ImpersonatedUserId with idType as PrincipalName instead of SmtpAddress
It seems that I got confused about which mail address to use when specifying the user I want to impersonate. Our company uses two different domains and I was using the wrong one. 🤦♂️
@stokuri, I got it to work with idType SmtpAddress. Thanks for the suggestion. @tjmoore, I think you're right, since I was getting a 'No Mailbox' error message when using a wrong mail address.
Also, the guide I followed has been updated since I last checked.
Apparently you have to set the X-AnchorMailbox HTTP header when using App-only authentication:
ewsClient.HttpHeaders.Add("X-AnchorMailbox", "impersonated@user.com");
Hi,
I am trying to implement OAuth authentication for our exchange mail daemon. I followed this step by step guide in order to grant
full_access_as_app
. Authentication and impersonation with the exchange server works fine. However, once I try to subscribe to streaming notifications, find a folder or to create one, this exception is thrown:Microsoft.Exchange.WebServices.Data.ServiceResponseException : ExchangeImpersonation SOAP header must be present for this type of OAuth token.
The only similar issue I have found so far is #212. Even though it sounds almost identical (weren't it for the negation), all proposed solutions did not work/were not applicable for me.
This is roughly how my code looks:
These are the HTTP requests and responses that I logged:
Request
Response