如何使用OAuth进行身份验证以访问EWS API [英] How to authenticate with OAuth to access EWS APIs
问题描述
我的Web服务当前正在执行基本的用户名/密码身份验证,以便订阅交换用户以接收事件(例如新邮件事件等),如下所示:
My web service is currently doing basic username/password authentication in order to subscribe the exchange user for receiving the events (like new mail event etc) like below:
var service = new ExchangeService(exchangeVersion)
{
KeepAlive = true,
Url = new Uri("some autodiscovery url"),
Credentials = new NetworkCredential(username, password)
};
var subscription = service.SubscribeToPushNotifications(
new[] { inboxFolderFoldeID },
new Uri("some post back url"),
15,
null,
EventType.NewMail,
EventType.Created,
EventType.Deleted,
EventType.Modified,
EventType.Moved,
EventType.Copied);
现在,我应该替换身份验证机制以使用OAuth协议.我看到了一些示例,但所有示例似乎都在谈论对客户端进行身份验证( https://msdn.microsoft.com/zh-CN/library/office/dn903761%28v=exchg.150%29.aspx?f= 255& MSPPError = -2147217396 ),但我无处找不到如何使用OAuth协议对交换用户进行身份验证的示例.任何代码示例都会有很大帮助.谢谢.
Now, I am supposed to replace the authentication mechanism to use OAuth protocol. I saw some examples but all of them seem to be talking about authenticating the client (https://msdn.microsoft.com/en-us/library/office/dn903761%28v=exchg.150%29.aspx?f=255&MSPPError=-2147217396) but nowhere I was able to find an example of how to authenticate an exchange user with OAuth protocol. Any code sample will help a lot. Thanks.
推荐答案
以防有人仍在努力使其正常工作.我们需要在Azure门户上为该应用程序上载证书清单,然后使用相同的证书对客户端进行身份验证以获取访问令牌.有关更多详细信息,请参阅: https://blogs.msdn.microsoft.com/exchangedev/2015/01/21/building-daemon-or-service -apps-with-office-365-mail-calendar-and-contacts-apis-oauth2-client-credential-flow/
In case someone is still struggling to get it to work. We need to upload a certificate manifest on azure portal for the application and then use the same certificate to authenticate the client for getting the access token. For more details please see: https://blogs.msdn.microsoft.com/exchangedev/2015/01/21/building-daemon-or-service-apps-with-office-365-mail-calendar-and-contacts-apis-oauth2-client-credential-flow/
这篇关于如何使用OAuth进行身份验证以访问EWS API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!