简体   繁体   English

如何使用 EWS 令牌通过后端 API 从 Microsoft Graph API 获取附件?

[英]How can I use an EWS token to fetch attachments from the Microsoft Graph API using a backend API?

I have an EWS token and attachment details as payload sent from an Outlook add-in.我有一个 EWS 令牌和附件详细信息作为从 Outlook 加载项发送的有效负载。 I am trying to use the Microsoft Graph API to fetch the content of the attachment in base64 format and save it in an AWS S3 Bucket.我正在尝试使用 Microsoft Graph API 以 base64 格式获取附件的内容并将其保存在 AWS S3 存储桶中。

My plan is to use the following API endpoint:我的计划是使用以下 API 端点:

https://graph.microsoft.com/v1.0/me/messages/${itemId}/attachments` (/${attachmentId})

However, when I try to use the EWS token as the access token for this request, I get an "Access token validation failure. Invalid audience."但是,当我尝试使用 EWS 令牌作为此请求的访问令牌时,我收到“访问令牌验证失败。无效的受众”。 error.错误。 How can I obtain a valid access token for this request and successfully fetch the attachments?如何获得此请求的有效访问令牌并成功获取附件?

I tried using npm packages like node-ews and ews-javascript-api.我尝试使用 npm 包,如 node-ews 和 ews-javascript-api。

I tried using the above endpoint and token-exchange grant type too. 

Alternate (better) methods are also welcomed.也欢迎使用替代(更好)方法。

EWS and Graph API are different technologies. EWS 和 Graph API 是不同的技术。 You can't use EWS token for accessing Graph API. To access data through Microsoft Graph, your application will need to acquire an OAuth 2.0 access token, and present it to Microsoft Graph in either of the following options:您不能使用 EWS 令牌访问 Graph API。要通过 Microsoft Graph 访问数据,您的应用程序需要获取 OAuth 2.0 访问令牌,并通过以下任一选项将其提供给 Microsoft Graph:

  1. The HTTP Authorization request header, as a Bearer token HTTP 授权请求 header,作为 Bearer token
  2. The graph client constructor, when using a Microsoft Graph client library Use the Microsoft Authentication Library API, MSAL to acquire the access token to Microsoft Graph.图客户端构造函数,当使用 Microsoft Graph 客户端库时使用 Microsoft 身份验证库 API, MSAL获取 Microsoft Graph 的访问令牌。

Read more about that in the Best practices for working with Microsoft Graph article.使用 Microsoft Graph 的最佳实践一文中阅读更多相关信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM