【发布时间】:2019-05-15 12:07:05
【问题描述】:
我正在尝试将 Exchange Web 服务 (EWS) 与应用程序和 OAuth2 身份验证一起使用。
我做了什么:
- 在 Azure 门户应用程序上注册,授予所有必需的权限(甚至
full_access_as_app用于 Exchange);作为管理员接受了这些权限; - 准备了正确的 OAuth2 Bearer 令牌(范围为
https://outlook.office365.com/.default); - 使用 SOAP UI 准备 SOAP 请求。作为这个请求的基础,我使用这个:https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/getattachment-operation。此外,我添加了带有承载令牌的 HTTP 授权标头、带有目标邮箱的 X-AnchorMailbox。
结果我得到了这个:“ExchangeImpersonation SOAP header must be present for this type of OAuth token”。我不明白我应该怎么做才能修复它。
即使尝试使用与上述相同邮箱地址的 ExchangeImpersonate 和 SmtpAddress,但这样我得到另一个错误“找不到邮箱”。但邮箱是! (在几个邮箱上测试过)。
我的问题是:我在 EWS 上做错了什么?
请求:
POST https://outlook.office365.com/ews/Exchange.asmx
Authorization: Bearer <token>
X-AnchorMailbox: mailbox@something.onmicrosoft.com
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<t:RequestServerVersion Version="Exchange2016"/>
<t:ExchangeImpersonation>
<t:ConnectingSID>
<t:PrimarySmtpAddress>
mailbox@something.onmicrosoft.com
</t:PrimarySmtpAddress>
</t:ConnectingSID>
</t:ExchangeImpersonation>
</soap:Header>
<soap:Body>
<GetAttachment xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<AttachmentShape/>
<AttachmentIds>
<t:AttachmentId Id="AAMkADAwNzdjNTg3LTc4M2ItNDE0Yi05MTk4LTQxZDBlYTc1NmMxZgBGAAAAAAAiixtLGariQY7rf5pAKRZZBwBVk8babsuEQ4s2Znfj9fB5AAAAAAEMAABVk8babsuEQ4s2Znfj9fB5AADq3B14AAABEgAQAKZOAcjZCBxHpqvY6XmXp5w="/>
</AttachmentIds>
</GetAttachment>
</soap:Body>
</soap:Envelope>
回复:
ErrorNonExistentMailbox The SMTP address has no mailbox associated with it.
【问题讨论】:
-
您是否尝试过使用基本身份验证来验证请求中的所有内容都正常并且您的权限是正确的。这至少可以让您确定是 oAuth 导致了问题还是您的请求。您应该始终将请求或代码示例与您的问题一起发布,以帮助人们查看它
-
是的,我已经尝试了基本身份验证,一切正常
-
接下来是检查您使用的令牌,对于模拟,您应该使用委托授权(而不是应用程序权限)。一种简单的测试方法是使用 EWSEditor github.com/dseph/EwsEditor/releases 它支持使用 oAuth(通过它在应用程序注册)和使用模拟。如果这可行,则应将其范围缩小到应用程序注册或生成令牌的方式。您还可以使用 jwt.io 检查令牌授予
-
问题已解决。客户端使用了错误的 SOAP 格式。
-
@zamazan4ik,您能否详细说明一下您是如何将soap 标头添加到请求中的?我正在尝试做同样的事情并遇到同样的问题。您的回复会很有帮助。
标签: oauth-2.0 exchangewebservices