sharepoint - SharePoint csom ADAL 令牌 401 未经授权
问题描述
我生成了一个具有以下权限的 AAD 令牌。
AllSites.FullControl AllSites.Manage AllSites.Read
AllSites.Write email Mail.Read Mail.Send MyFiles.Read
MyFiles.Write openid profile Sites.Search.All TermStore.Read.All
TermStore.ReadWrite.All User.Read User.Read.All User.ReadBasic.All User.ReadWrite.All
使用 nuget SharePointPnPCoreOnline 时出现 401 Unauthorized,我也尝试了 TTCUE.NEtCore.SharepointOnline.CSOM。
我创建了一个分配了各种权限的 AAD 应用程序注册。权限适用于 Mail.Read,但不适用于 SharePoint。
using (var context = new ClientContext("URL"))
{
context.AuthenticationMode = ClientAuthenticationMode.Anonymous;
context.FormDigestHandlingEnabled = false;
context.ExecutingWebRequest +=
delegate (object oSender, WebRequestEventArgs webRequestEventArgs)
{
webRequestEventArgs.WebRequest.Headers["Authorization"] =
"Bearer " + token;
};
context.Load(context.Web);
context.ExecuteQueryAsync().GetAwaiter().GetResult();
Console.WriteLine(context.Web.Title);
Console.ReadLine();
}
解决方案
我已经找到答案了。SharePoint CSOM 访问需要 Azure Active Directory V1 令牌。确保您没有尝试使用 V2 令牌进行访问。
推荐阅读
- html - 如果子 div 为空,则使用 css 隐藏父 div
- sql - 使用 cmd 重命名文件
- django - 如何在通用 UpdateView 的选择标记中获取保存的值?
- javascript - 仅获取具有相对路径的图像 | 正则表达式
- java - 视频动态壁纸更新视频源不起作用
- reporting-services - 将报告从 Cognos8 迁移到 SSRS Report Builder 3
- javascript - 如何在其他组件 Reactjs 上使用一些 props
- ruby-on-rails - 包含 STI 的活动记录不起作用
- sql - 更新以组合值并使用 SQL 删除其中一个
- javascript - Jquery click 不适用于通过 PHP 动态添加的表 tr