使用 Sharepoint Online 登录访问 Office Graph api?

Accessing Office Graph apis with Sharepoint Online login?

去年,我们一直是 运行 自定义母版页中的 Angular 应用程序,使用 Sharepoint REST api 从列表中检索用户属性、数据等,一直工作正常。由于该应用程序托管在 Sharepoint Online 上,因此访问该页面需要登录,从而使请求摘要可用,因此不需要进一步的身份验证。

但是现在,我们想开始使用 Microsoft Graph API 中的一些功能。据我所知,这需要针对 Azure Active Directory 进行 OAuth2 身份验证,其中包括重定向到 AAD 登录页面。

这是否意味着我必须:

1) 通过组织(标准 Microsoft)登录页面登录以访问 Sharepoint Online 站点。 2) 重定向到 Azure AD 登录页面并再次返回?

或者我可以利用用户在登录 Sharepoint Online 时已经进行的登录吗?

抱歉,如果问题有点含糊,我们对此还很陌生。

在 Azure AD 上注册您的应用程序时,您将授予该应用程序访问 Files/Sharepoint REST api 和 Microsoft Graph API 的权限。请参阅 this picture 该应用程序可以访问多个 api(Exchange、Graph 和 AD),您必须在您的案例中添加共享点 API。

关于身份验证,恐怕 Sharepoint 模型不提供使您能够在 Office 商店上请求图形 API see this. You will have two authentications, one to access the Sharepoint site, as you said, and the other "within" the sharepoint iframed add-in to log into your AAD's registered app. This will be an OAUTH process through login.microsoft.com. Have a look at my Outlook add-in Keluro Mail Team 的令牌,我认为它类似于你想要达到什么。

您可以使用 graph.microsoft.com 中的相同令牌。我有一个使用 Asp.Net Core 1.0 和 the.Net ADAL 的示例,但在使用 ASP.NET 4.6 时使用相同的身份验证流程。只需在启动时针对 ms graph 发出身份验证请求,然后获取访问令牌以针对 SharePoint 进行身份验证。 https://github.com/edrohler/com.ericrohler

希望对您有所帮助。