I've created an Azure WebJob to update users' profile.
I'd like to do this without providing credentials in the code. I've created a Principal with FullControl permissions to the User Profiles Scope but the job failed because of permissions.
The Code:
string UserAccountName = "i:0#.f|membership|user@tenant.com";
string tenantAdministrationUrl = "https://tenant-admin.sharepoint.com/";
Uri siteUri = new Uri(tenantAdministrationUrl);
string realm = TokenHelper.GetRealmFromTargetUrl(siteUri);
string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken;
using (var clientContext = TokenHelper.GetClientContextWithAccessToken(siteUri.ToString(), accessToken))
{
// Get the people manager instance for tenant context
PeopleManager peopleManager = new PeopleManager(clientContext);
// Update the AboutMe property for the user using account name.
peopleManager.SetSingleValueProfileProperty(UserAccountName, "AboutMe", "Update from CSOM");
clientContext.ExecuteQuery();
}The Error:
Unhandled Exception: Microsoft.SharePoint.Client.ServerUnauthorizedAccessException: Access denied. You do not have permission to perform this action or access this resource.