gpt4 book ai didi

azure - 如何使用 v1 Azure AD 应用程序和客户端凭据访问 Sharepoint Online API

转载 作者:行者123 更新时间:2023-12-05 03:58:22 26 4
gpt4 key购买 nike

我无法使用 Postman 对 Sharepoint Online 进行 API 调用。我已成功对 Graph API 进行 API 调用,因此我熟悉我认为这应该如何工作。

我已按照以下说明进行设置:

第一篇文章说它不会接受使用客户端 key 生成的访问 token ,但我已经生成了带有 key 和证书的 token ,并且没有发现任何差异。

当调用任何东西时,例如:

https://<tenant>.sharepoint.com/_api/web

我收到错误:

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

这是我使用 v1/token 端点生成的访问 token 的示例:

{
"aud": "https://microsoft.sharepoint-df.com/",
"iss": "https://sts.windows.net/462c0b***********c3708/",
"iat": 1569243291,
"nbf": 1569243291,
"exp": 1569247191,
"aio": "42FgYDiXt***********==",
"app_displayname": "T***********n",
"appid": "00c***********2b",
"appidacr": "2",
"idp": "https://sts.windows.net/46***********708/",
"oid": "2f8a5***********684",
"roles": [
"User.ReadWrite.All",
"TermStore.Read.All",
"Sites.FullControl.All"
],
"sid": "5ab8d57***********0bc",
"sub": "2f8a5***********684",
"tid": "462c0***********708",
"uti": "aHt8d***********9AA",
"ver": "1.0"
}

最佳答案

该错误消息似乎暗示我在/token 端点调用中的资源参数设置不正确。我相信微软文档中省略了这一点,因为文档是如此划分。 V1 应用程序调用 SharePoint Online 的正确 token 端点调用如下所示:

网络服务

POST https://login.microsoftonline.com/<TARGET-TENANT-ID OR NAME>/oauth2/token

参数

client_id= <Application ID from Azure Portal>
grant_type=client_credentials
resource= https://<TARGET-TENANT-NAME>.sharepoint.com
client_assertion_type= urn:ietf:params:oauth:client-assertion-type:jwt-bearer
client_assertion= <See Link Above to create assertion>

上面的链接省略了如何计算证书 JWT 的 x5t 值。您可以使用这个:

echo $(openssl x509 -in certificate.pem -fingerprint -noout) | sed 's/SHA1 Fingerprint=//g' | sed 's/://g' | xxd -r -ps | base64

我从这里得到的:How to obtain value of "x5t" using Certificate credentials for application authentication

如果您尝试使用客户端 key 而不是客户端断言,您将收到一个 token ,但 SharePoint Online REST API 将返回:

Unsupported app only token.

关于azure - 如何使用 v1 Azure AD 应用程序和客户端凭据访问 Sharepoint Online API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58063585/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com