azure - 如何使用 Azure AD 注册的应用程序查询 Sharepoint REST api(不是 Graph api)?

标签 azure sharepoint oauth-2.0

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

我已将共享点委托(delegate)权限范围“AllSites.Read”添加到我的应用程序中(除了我之前使用的 Graph API 范围之外),并在获得时请求此范围(除了其他延迟的 msgraph 范围之外)来自用户的 oauth token 。我使用 https://login.microsoftonline.com/common/oauth2/v2.0 成功获取了 token 用于授权/ token 调用,但无法成功查询:

我的查询类似于 client.get(f"https://{tenant}.sharepoint.com/_api/web/lists")哪里tenant是我正在使用的 token 的特定用户的租户。

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

我能够查询 Graph api,但也希望能够查询 Sharepoint REST api,因为 Graph api 不足以满足我的实际用例,即获取 Sharepoint 组(Graph api 确实当我请求组时不提供共享点组,仅提供 Office 365 和 Azure AD 组)。

更新: 我在应用程序上设置的权限: Permission scopes set on the app

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

enter image description here

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

我成功获得了具有所有角色的 token ,尽管它仍然无法让我访问 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 中工作:

我取回的 token 具有我在应用程序上设置的所有权限,包括 Graph API 权限和我在身份验证请求的 Scope 参数中未请求的 Sharepoint 范围:

"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",这有点令人惊讶。

一个关键点是在范围内设置租户 URL,以便 aud token 中的参数返回给正确的租户。它在配置为 resourceAppId 之前返回与 Graph 权限 ( 00000003-0000-0000-c000-000000000000 ) 关联,而不是与 Sharepoint 权限关联。这样,aud设置为https://<tenant>.sharepoint.com我能够访问 https://<tenant>.sharepoint.com/_api/web/lists .

关于azure - 如何使用 Azure AD 注册的应用程序查询 Sharepoint REST api(不是 Graph api)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66481828/

相关文章:

visual-studio - 有什么方法可以使用 Visual Studio 运行 Azure PowerShell cmdlet?

c# - SPGridView 中日期/时间的 ObjectDataSource 过滤

c# - 验证 JWT 出现奇怪的 “Unable to match key kid” 错误

Azure APIM - 协商客户端证书设置

php - 适用于 PHP 客户端的 Azure 服务总线队列 ReceiveBatch

sharepoint - 将多个参数从自定义 WebPart 传递到 Reporting Services 报表查看器 Web 部件

node.js - 如何通过 Twitter REST API 撤销 Twitter 授予应用程序的用户访问 token

java - Google 云端点(应用程序引擎)+ oauth2 与 android 集成

c# - Azure AD : Property 'mail' is read-only and cannot be set

sharepoint - 在(服务总线))没有端点监听共享点应用程序 = 无法在 Microsoft Azure 服务总线 : 上注册 AppEventReceiver.svc