繁体   English   中英

如何查询 Sharepoint REST api (不是图形 api) 使用 Z3A580F1422038F1422038673F1 注册应用程序?

[英]How to query the Sharepoint REST api (not the Graph api) using an Azure AD registered application?

我在 Azure AD 中注册了一个 web 应用程序,并让它与图形 API 一起使用。 但我希望能够改为查询 Sharepoint REST API。

I have added the sharepoint delegated permission scope "AllSites.Read" to my application (in addition to the Graph API scopes that I was using before) and request this scope (in addition to the other delagated msgraph scopes) when I get the oauth token来自用户。 我成功获取了令牌,使用https://login.microsoftonline.com/common/oauth2/v2.0进行授权/令牌调用,但无法成功查询:

我的查询看起来像client.get(f"https://{tenant}.sharepoint.com/_api/web/lists")其中tenant是我正在使用的令牌的特定用户的租户。

我得到的错误看起来像{'error_description': 'Invalid issuer or signature.'} with reason="Token contains invalid signature.";category="invalid_client"'在响应的 header 中。

I am able to query the Graph api, but would like to also be able to query the Sharepoint REST api, because the Graph api is is insufficient for my actual use case, which will be to get Sharepoint groups (Graph api does not give sharepoint当我要求组时,只有 Office 365 和 Azure AD 组)。

更新:我在应用程序上设置的权限: 在应用程序上设置的权限范围

我没有在Expose API中添加任何范围,不知道是否需要。 我不需要这部分来让它与 Graph API 一起使用。

在此处输入图像描述

最后我会提到,在 Postman 中,受控环境纯粹以此作为请求,OAuth 2.0:

我成功获得了具有所有角色的令牌,尽管它仍然无法让我访问https://<tenant>.sharepoint.com/_api/web/lists 我收到以下错误:

    "error": {
        "code": "-2147024891, System.UnauthorizedAccessException",
        "message": {
            "lang": "en-US",
            "value": "Access denied. You do not have permission to perform this action or access this resource."
        }
    }
}

诚然,这可能是我之前遇到的无效客户端错误向前迈出的一步,但仍然非常卡住。

我能够让它在 Postman 中工作:

我取回的令牌具有我在应用程序上设置的所有权限,包括 Graph API 和 Sharepoint 范围,我没有在请求的 Z5D113F2038D289F3916Z14C39043629 Eau 中请求:

"scp": "AllSites.FullControl AllSites.Read Directory.Read.All Files.Read.All Group.Read.All MyFiles.Read Sites.Read.All Sites.Search.All User.Read User.Read.All",其中有点意外。

一个关键点是在 scope 中设置租户 url 以便为正确的租户返回令牌中的aud参数。 它在为与 Graph 权限 ( 00000003-0000-0000-c000-000000000000 ) 而不是 Sharepoint 权限关联的resourceAppId配置之前回来了。 This way, aud got set to https://<tenant>.sharepoint.com and I was able to access https://<tenant>.sharepoint.com/_api/web/lists .

您可以尝试获取 PostMan 中的访问令牌用于测试目的。

Callback URL:        https://www.getpostman.com/oauth2/callback
Auth URL :           https://login.microsoftonline.com/common/oauth2/authorize?resource=https://<tenant_name>.sharepoint.com  
Access Token URL :   https://login.microsoftonline.com/common/oauth2/token  
Client ID :          <Application_ID>  
Client Secret :      <KEY>  
Grant Type :         Authorization Code 

会弹出登录 window 进行登录然后生成访问令牌并获取 SharePoint 组:

在此处输入图像描述

参考:

使用 Postman 和 Azure AD 发送 REST 请求到 Z97F02F6993B937632B0DZ39DFE0 Online

暂无
暂无

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

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