【发布时间】:2021-05-22 14:00:51
【问题描述】:
当我们将项目从 .net 4.7 迁移到 .Net core 3.1 时,我必须找到 SharePointOnlineCredentials 类的替代品。
为了生成我的 ClientContext,我现在使用 Pnp.Framework 包中的 AuthenticationManager。
但是,我无法再更新 Sharepoint 用户属性。 我得到了错误:
'访问被拒绝。您无权执行此操作或访问此资源。'
每当我使用 SharePoint 管理员用户(如以前)或具有 Uer.ReadWrite.All 权限的已注册 AAD 应用程序时。
我的测试 SharePoint 管理员用户帐户:
using(var am = PnP.Framework.AuthenticationManager.CreateWithCredentials(clientId, userName, password))
using (var clientContext = am.GetContext(adminSiteUrl))
{
var peopleManager = new PeopleManager(clientContext);
var personProperties = peopleManager.GetPropertiesFor(accountName);
clientContext.Load(personProperties);
clientContext.ExecuteQuery();
peopleManager.SetSingleValueProfileProperty(personProperties.AccountName, "officeKey", "MTR");
clientContext.ExecuteQuery(); //Throws the 'Access Denied' exception here
}
我对注册客户端应用的测试(使用证书)
using (var am = new PnP.Framework.AuthenticationManager(clientId, certificatePath, certificatePassword, tenant))
using (var clientContext = am.GetContext(adminSiteUrl))
{
var peopleManager = new PeopleManager(clientContext);
var personProperties = peopleManager.GetPropertiesFor(accountName);
clientContext.Load(personProperties);
clientContext.ExecuteQuery();
peopleManager.SetSingleValueProfileProperty(personProperties.AccountName, "officeKey", "MTR");
clientContext.ExecuteQuery(); //Throws the 'Access Denied' exception here
}
注意:我在 AAD 中注册的应用程序客户端拥有所有 SharePoint API 权限。
我的项目正在引用包:
- Microsoft.SharePointOnline.CSOM (16.1.20912.12000)
- Pnp.Framework (1.2.0)
【问题讨论】:
标签: c# sharepoint csom