【问题标题】:How can I use web app with EWS managed API for office 365?如何将 Web 应用程序与适用于 Office 365 的 EWS 托管 API 一起使用?
【发布时间】:2016-04-29 12:31:50
【问题描述】:

用 c#; 我可以使用 native app 生成的 access_token 来请求 Office 365 的 EWS 托管 api。 我正在尝试使用 web app 生成的 access_token。这在 service.AutodiscoverUrl('mailid', delegate(string url){return true}) 失败并出现错误“找不到自动发现服务。”。

我正在使用以下代码使用网络应用程序生成 access_token。

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.

我可以将 Web 应用程序与 Office 365 的 EWS 托管 API 一起使用吗?或者它仅限于原生应用程序?

【问题讨论】:

    标签: c# oauth office365 exchangewebservices


    【解决方案1】:

    EWS 支持 Oauth 身份验证,但自动发现不支持

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

    但是,如果您在 Azure 中正确设置了权限,则任何 EWS 请求都应该可以正常工作。由于 Office365 中只有一个 EWS 端点,您无需使用自动发现,只需使用

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

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

    干杯 格伦

    【讨论】:

    • service.AutodiscoverUrl('mailid', delegate(string url){return true}) 如果我使用本机应用程序,这将有效。
    • 然后启用跟踪并查看正在发送的标头之间的差异,这将立即告诉您发生了什么以及出了什么问题。
    • 谢谢,使用网络应用程序;我仅为“应用程序权限”生成 access_token。现在可以将 access_token 用于 EWS 请求。
    猜你喜欢
    • 2015-01-20
    • 1970-01-01
    • 1970-01-01
    • 2020-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多