【问题标题】:Office 365 Calendar API Using EWS and OAuth 2使用 EWS 和 OAuth 2 的 Office 365 日历 API
【发布时间】:2017-01-26 14:32:51
【问题描述】:

请查看底部的修改。

我正在尝试使用 EWS(不是托管 API)使用 Office 365 API 来创建/删除/更新用户日历上的事件。

到目前为止,我已成功使用基本身份验证来验证我的 SOAP 请求是否有效。我现在正在尝试用 OAuth 2 替换基本身份验证。我需要使用客户端凭据流。

以下是我遵循的步骤:

  • 提供了对应用程序的管理员同意。我在浏览器中启动了以下 URL,并使用管理员帐户提供了同意。

    https://login.microsoftonline.com/common/oauth2/authorize?
        response_type=code+id_token&
        scope=openid&
        client_id=[Client ID]&
        redirect_uri=http://localhost/myapp/permissions&
        resource=https://outlook.office.com&
        prompt=admin_consent&
        response_mode=form_post&
        nonce=1234
    
  • 在同意后,我从响应中检索了id_token,并使用JWT.io 对其进行了解码。从有效载荷中,我记录了tid

  • 接下来我通过发送以下请求检索了访问令牌:

    POST https://login.microsoftonline.com/[TID]/oauth2/token HTTP/1.1
    cache-control: no-cache
    Content-Type: application/x-www-form-urlencoded
    Accept: */*
    Host: login.microsoftonline.com
    accept-encoding: gzip, deflate
    Connection: close
    
    client_id=[CLIENT ID]&
    client_secret=[CLIENT SECRET]&
    grant_type=client_credentials&
    resource=https%3A%2F%2Foutlook.office.com
    
  • 使用访问令牌,我发出了与使用基本身份验证相同的请求,除了我将基本身份验证标头替换为Authorization: Bearer [Access Token]

我收到以下错误 (403 Forbidden): The token contains not enough scope to make this call.

我需要做什么来修复这个错误?

编辑 1:我添加了 Use Exchange Web Services with full access to all mailboxes 应用程序权限,现在发送 SOAP 消息会导致 500 Internal Server Error...

【问题讨论】:

    标签: oauth-2.0 office365 exchangewebservices


    【解决方案1】:

    解决方案涉及以下内容:

    1. 添加 Use Exchange Web Services with full access to all mailboxes 应用程序权限,因为 EWS 不允许使用更精细的权限。

    2. 为目标邮箱添加ExchangeImpersonation SOAP header

    3. 设置X-AnchorMailbox HTTP 标头。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-05
      • 1970-01-01
      • 2018-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多