【问题标题】:Azure Function Updating user profile using SharePoint Online and CSOM .NET Standard gives access deniedAzure 函数使用 SharePoint Online 和 CSOM .NET Standard 更新用户配置文件会拒绝访问
【发布时间】:2020-10-29 12:17:51
【问题描述】:

我有 Azure Function v3,我想通过使用全局管理员帐户凭据来使用 CSOM 和 .NET 标准 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 类取自 here 的 MS 文档 我正在使用 Microsoft.SharePointOnline.CSOM v16.1.20518.12000 nuget 包。

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

【问题讨论】:

    标签: c# azure-functions sharepoint-online csom .net-standard-2.0


    【解决方案1】:

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

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

    参考:

    虽然article 表示它适用于仅使用应用程序,但在一般情况下已观察到 Azure AD 应用程序(用户 + 应用程序)的这种行为 - 因此您能够阅读但不能写入的原因。

    如文章中所述,您必须在 Sharepoint App only 上下文中执行读/写操作。

    context = new AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl, "[Your Client ID]", "[Your Client Secret]")
    

    这里的 authenticationmanager 属于 SharepointPNPcoreOnline 库。

    article 的详细信息相同。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-21
      • 2021-09-21
      • 2021-12-26
      • 1970-01-01
      • 2015-06-22
      • 2023-04-01
      • 2018-04-06
      • 1970-01-01
      相关资源
      最近更新 更多