Outlook加载项Rest Api令牌以获取SharePoint Rest Api令牌 [英] Outlook add-in Rest Api token to get the SharePoint Rest Api Token

查看:189
本文介绍了Outlook加载项Rest Api令牌以获取SharePoint Rest Api令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Node JS构建Outlook加载项,并且它需要使用SharePoint Rest Api从SharePoint Online获取信息,因为Graph无法选择获取所需信息.

I am building a Outlook Add-in using Node JS and it needs get information from SharePoint Online using SharePoint Rest Api because Graph does`t have an option to get the required information.

问题? 我需要一个SharePoint在线身份验证令牌来调用SP Rest Api,在用户输入凭据后,我将使用OAuth流(隐式流)来获取它.

Question? I need a SharePoint online auth token to call SP Rest Api which I am getting using OAuth flow (implicit flow) after user enters credentials.

是否有一种方法可以使用 getCallbackTokenAsync() getUserIdentityTokenAsync()或"getAccessTokenAsync()"方法返回的Outlook Rest Api获取SharePoint联机身份验证令牌? /p>

Is there a way to get the SharePoint online auth token using Outlook Rest Api returned by getCallbackTokenAsync() or getUserIdentityTokenAsync() or "getAccessTokenAsync()" method?

推荐答案

如果您只需要SharePoint REST API令牌(我假设您的意思是URL以_api/[...]开头的令牌),那么最好的选择是从站点的/_api/contextinfo端点获取该令牌.如果我正确理解了该问题,则不需要Outlook REST API来执行此操作.因此,您需要制定POST请求以:

if you only need the SharePoint REST API Token (I assume you mean the one with URLs starting with _api/[...]) then your best bet is to get that token from the /_api/contextinfo endpoint for your site. You do not need the Outlook REST API to do so if I understand the question correctly. So you need to craft a POST request to:

http://yourspsite/_api/contextinfo
Headers:
accept: application/json
content-type: application/json

从返回的JSON获取令牌值:例如jsonResponse.FormDigestValue FormDigestValue字段包含所需的值.

Get the token value from the returned JSON: e.g. jsonResponse.FormDigestValue The FormDigestValue field contains the value you want.

可以,希望对您有所帮助. 干杯, 拉兹万

There ya go, hope this helps. Cheers, Razvan

正如您正确指出的那样,我没有从令牌本身中获取令牌的要求.目前仅在SSO插件(预览)中可以做到这一点.请参阅以下链接,了解如何实现它并使用getAccessTokenAsync获取Azure AD V2令牌:

As you correctly pointed out I left out the requirement that the token be obtained from within the Addin itself. This is currently only possible from within SSO addins (preview). See the following link for how to implement it and use getAccessTokenAsync to get an Azure AD V2 token: https://docs.microsoft.com/de-de/office/dev/add-ins/develop/sso-in-office-add-ins

确保事先使用 https://apps.dev.microsoft.com

为应用提供必要的操作权限,例如Sites.Read.All,用于读取所有网站集中的项目.

Give the app the necessary permissions for the operation e.g. Sites.Read.All for reading items in all site collections.

令牌的资源应类似于:

 https://[yourtenant].sharepointonline.com/

注意事项:要创建SSO外接程序,您当前需要成为Office Insider计划的一部分,网址为:

Caveat: To create an SSO Addin you currently need to be part of the Office Insider Program at: https://products.office.com/de-DE/office-insider - signup required.

最后:使用令牌来调用常规的SharePoint REST API,如果您坚持在上述Azure应用中设置的权限内进行操作,它应该接受该令牌.

Finally: Use the token to call the regular SharePoint REST API, it should accept it if you stick to operations within the permissions you set in the Azure App above.

这篇关于Outlook加载项Rest Api令牌以获取SharePoint Rest Api令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆