问题
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?
回答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
来源:https://stackoverflow.com/questions/36915657/how-can-i-use-web-app-with-ews-managed-api-for-office-365