SharePoint API:无效的访问令牌资源

时间:2020-09-09 14:00:16

标签: sharepoint postman token sharepoint-api

我正在尝试获取与SharePoint Rest API一起使用的访问令牌。对于我的组织基础站点。我能够获取令牌并使用该令牌成功进行后续请求。

下一步,我遵循相同的过程,并为其他站点创建了更多应用程序权限 {{{tenant removeed}} / sites / testsite 。我最初无法创建令牌请求,因为资源参数无效(请参见下图):

enter image description here

根据URI编码标准,我将站点url中的“ /”替换为“%2f”,并且能够获得令牌(请参见下图):

enter image description here

但是,接下来,对该API使用该令牌的请求将失败:

{
"error_description":
"Exception of type 'Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException' was thrown."
}

在响应标题中:

3000003; reason =“无效的受众Uri '00000003-0000-0ff1-ce00-000000000000 / {{承租人 已删除}} %2fsites%2f {{已删除}} @ {{领域 已移除}}'。“;”; category =“ invalid_client”

我是否对资源进行了错误编码?我想念什么?如何使用这种方法从其他站点获取信息?

1 个答案:

答案 0 :(得分:1)

我可以看到许多开发人员在创建请求时做出相同的假设,因为几乎所有文档都没有指出这种情况。只要资源采用有效的uri格式,您就可以成功获取该站点的令牌,而无需对uri本身进行验证。即使您获得令牌,它也不会对任何请求起作用。

获取子站点的访问令牌时(即{{tenant}}/sites/testsite)。请求正文的资源部分不需要修改。

例如,当您获得test.sharepoint.com/sites/testsite的令牌时,请求正文的resource应该是:

00000003-0000-0ff1-ce00-000000000000/test.sharepoint.com@{{realm}}(无/sites/testsite

但是,当您使用令牌向API发出HTTP请求时,应使用完整的网站名称。示例:

https://test.sharepoint.com/sites/testsite/_api/web/