C# Azure函数使用SharePoint Online和CSOM.NET标准更新用户配置文件时拒绝访问

C# Azure函数使用SharePoint Online和CSOM.NET标准更新用户配置文件时拒绝访问,c#,azure-functions,sharepoint-online,csom,.net-standard-2.0,C#,Azure Functions,Sharepoint Online,Csom,.net Standard 2.0,我有Azure Function v3,我想通过使用全局管理员帐户凭据使用CSOM和.NET standard 2.0更新Sharepoint用户配置文件属性。阅读是有效的 var site = new Uri("https://domain-admin.sharepoint.com"); using (var authenticationManager = new AuthenticationManager()) using

我有Azure Function v3,我想通过使用全局管理员帐户凭据使用CSOM和.NET standard 2.0更新Sharepoint用户配置文件属性。阅读是有效的

        var site = new Uri("https://domain-admin.sharepoint.com");
        using (var authenticationManager = new AuthenticationManager())
        using (var context = authenticationManager.GetContext(site, user, password))
        {
            var peopleManager = new PeopleManager(context);

            var personProperties = peopleManager.GetPropertiesFor(accountName);
            context.Load(personProperties, p => p.AccountName, p => p.UserProfileProperties);
            await context.ExecuteQueryAsync();
            Console.WriteLine(personProperties.UserProfileProperties["FirstName"]); //works
            peopleManager.SetSingleValueProfileProperty(personProperties.AccountName, "FirstName", "CSOMvalue");
            await context.ExecuteQueryAsync(); //error, access denied
        }
确切错误消息:System.Private.CoreLib:执行函数:FunctionName时发生异常。Microsoft.SharePoint.Client.Runtime:访问被拒绝。您没有执行此操作或访问此资源的权限

AuthenticationManager类取自的MS文档 Im使用Microsoft.SharePointOnline.CSOM v16.1.20518.12000 nuget软件包


我制作了.NETFramework4.7.2Web应用程序,它使用SharePointOnlineCredentials工作。但我想知道如何让它在.NET标准2.0上运行。

根据我过去的经验和几个小时的研究:

使用Azure AD应用程序时,可以读取用户配置文件,但不能执行CSOM写入操作

context = new AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl, "[Your Client ID]", "[Your Client Secret]")
参考资料:

虽然声明它只适用于使用应用程序,但Azure广告应用程序一般都会观察到这种行为(用户+应用程序也是如此)-因此,您可以阅读但不能写入

如本文所述,您只需访问Sharepoint应用程序上下文并执行读/写操作

context = new AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl, "[Your Client ID]", "[Your Client Secret]")
此处authenticationmanager是SharepointPNPcoreOnline库的一部分

这个细节是一样的

如果在执行相同操作时需要用户上下文(通常不是必需的,因为您是在UPA上执行的)-您可以相应地创建应用程序-但确实不确定SharepointPNPCOreOnline是否支持此操作