gpt4 book ai didi

azure - "Unsupported app only token"添加证书后仍出现 SharePoint API 错误

转载 作者:行者123 更新时间:2023-12-02 23:40:35 24 4
gpt4 key购买 nike

我正在尝试使用列表 SharePoint API https://xx.sharepoint.com/_api/web/lists 当我尝试访问上述 API 时,收到“仅适用于应用程序的 token 不受支持”错误。我已经引用了this中提到的文档回答。我也在注册的应用程序上添加了证书,但仍然收到相同的错误。我正在将 SharePoint token 获取为

网址“https://login.microsoftonline.com/xx.onmicrosoft.com/oauth2/v2.0/token

正文

  1. “grant_type”->“client_credentials”
  2. “范围”->“https://xx.sharepoint.com/.default
  3. client_id -> 应用的客户端 ID
  4. client_secret -> 应用程序的客户端 key

最佳答案

这不是证书凭证的工作原理。应用程序可用于身份验证的这种形式的凭据是使用应用程序拥有的证书签名的 JSON Web token (JWT) 断言。查看详情here .

因此您无法使用客户端 key 来获取访问 token 。

您需要set up an Azure AD app for app-only access首先。请引用Granting access via Azure AD App-Only中的示例.

using OfficeDevPnP.Core;
using System;

namespace AzureADCertAuth
{
class Program
{
static void Main(string[] args)
{
string siteUrl = "https://contoso.sharepoint.com/sites/demo";
using (var cc = new AuthenticationManager().GetAzureADAppOnlyAuthenticatedContext(siteUrl, "<application id>", "contoso.onmicrosoft.com", @"C:\BertOnlineAzureADAppOnly.pfx", "<password>"))
{
cc.Load(cc.Web, p => p.Title);
cc.ExecuteQuery();
Console.WriteLine(cc.Web.Title);
};
}
}
}

这里是sample projects在 GitHub 中。

关于azure - "Unsupported app only token"添加证书后仍出现 SharePoint API 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62356709/

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