I have Azure Function v3 and I want to update Sharepoint user profile properties with CSOM and .NET standard 2.0 by using global admin account credentials. Reading is working.
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
}
Exact Error message: System.Private.CoreLib: Exception while executing function: FunctionName. Microsoft.SharePoint.Client.Runtime: Access denied. You do not have permission to perform this action or access this resource.
AuthenticationManager class is taken from MS docs from here Im using Microsoft.SharePointOnline.CSOM v16.1.20518.12000 nuget package.
I made .NET Framework 4.7.2 web app and it worked using SharePointOnlineCredentials. But I want to know how to get it working on .NET Standard 2.0.