【问题标题】:node-ews returning 401 Unauthorized where as using the valid access tokennode-ews 返回 401 Unauthorized where as using the valid access token
【发布时间】:2022-11-17 23:06:18
【问题描述】:

我正在使用 node-ews 从 Microsoft Exchange 服务器获取电子邮件。 基本身份验证工作正常。

但是,由于 Microsoft 禁用了基本身份验证。 我们目前正在使用来自 Graph Explorer 的 OAuth 令牌(访问令牌)进行测试。

但它返回 401 Unauthorized 错误。

这是我们用来连接到交换服务器的示例代码。

const ewsConfig = {
            username: item.mail_username,
            password: item.user_pass,
            host: item.ews_host,
            token: 'xxxxxxxxxxx',
            auth: 'bearer'
          };

          // initialize node-ews
          const options = {
            rejectUnauthorized: false,
            strictSSL: false
          };
          // initialize node-ews
          const ews = new EWS(ewsConfig, options);

【问题讨论】:

    标签: node.js exchangewebservices node-ews


    【解决方案1】:
    . We are currently using the OAuth token (access token) from Graph Explorer to test.
    

    Graph Explorer 令牌将没有 EWS only Graph 的权限,如果使用客户端凭据流,EWS 中唯一有效的两个权限是 EWS.AccessAsUser.All 或 full_access_as_app。 https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-authenticate-an-ews-application-by-using-oauth Mail.Read 等权限在 EWS 中不起作用,因为它不支持 Graph 支持的更具限制性的身份验证方案(这是在 EWS 上使用 Graph 的原因)

    如果您想访问令牌以使用 EWSEditor https://github.com/dseph/EwsEditor/releases 进行测试并获取其令牌

    【讨论】:

      【解决方案2】:

      请找到我们用于解决相同问题的解决方案。

      该解决方案由 3 个部分组成:

      1. 在 AZURE 中设置应用程序,允许为 EWS 生成 MSAL 访问令牌。
      2. 添加获取accessToken的代码。
      3. 对旧代码进行了更改以使用之前收到的 accessToken。我正在使用 ews-javascript-api。但我认为前面两个步骤将帮助您获得 EWS 的 accessToken,您可以将它与节点 EWS 一起使用。

      【讨论】:

        猜你喜欢
        • 2021-07-13
        • 2020-08-15
        • 1970-01-01
        • 2015-07-11
        • 1970-01-01
        • 1970-01-01
        • 2022-11-09
        • 2015-03-13
        • 2021-09-02
        相关资源
        最近更新 更多