0

With c#; I am able to use access_token generated with native app to request EWS managed api for office 365. I am trying to use access_token generated with web app. This is failing at service.AutodiscoverUrl('mailid', delegate(string url){return true}) and getting error 'The Autodiscover service couldn't be located.'.

I am using following code to generate access_token using web app.

string authority = "https://login.windows.net/common/oauth2/authorize";
string serverName = "https://outlook.office365.com";
AuthenticationContext authenticationContext = new AuthenticationContext(authority, false);
ClientCredential credential = new ClientCredential("Web app client id", "Web app secret key");
AuthenticationResult authenticationResult = authenticationContext.AcquireToken(serverName, credential);
authenticationResult.AccessToken; // read access_token here.

Can I use Web App with EWS managed API for office 365 or it is limited t native app?

Mahesh Mankar
  • 231
  • 3
  • 16

1 Answers1

1

EWS supports Oauth Authentcation but Autodiscover doesn't so

service.AutodiscoverUrl('mailid', delegate(string url){return true})

Wont work however if you have set the permission correctly in Azure any EWS request should work okay. Because there is only one EWS endpoint in Office365 you don't need to use Auto-discover just use

service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");

eg http://www.jeremythake.com/2014/08/using-the-exchange-online-ews-api-with-office-365-api-via-azure-ad/

Cheers Glen

Glen Scales
  • 20,495
  • 1
  • 20
  • 23
  • `service.AutodiscoverUrl('mailid', delegate(string url){return true})` this works if I use native app. – Mahesh Mankar Apr 29 '16 at 05:41
  • Enable tracing then and look at the difference between the headers that are being sent that will tell you straight away whats happening and what is going wrong. – Glen Scales Apr 30 '16 at 01:29
  • Thanks, with web app; I was generating access_token only for 'Application permissions'. Now able to use access_token for EWS requests. – Mahesh Mankar May 03 '16 at 10:51