Error when using app to update user profile properties in SharePoint Online

Symptoms

You use a Microsoft Entra app to update user profile properties in SharePoint Online by using app-only authentication. In this scenario, you receive System.UnauthorizedAccessException and the following error message:

Access denied. You do not have permission to perform this action or access this resource.

Cause

This issue occurs because the app doesn't have the required permissions to make the updates.

Resolution

To fix this issue, grant the User.ReadWrite.All permission to the app in the Azure portal. If you have to update taxonomic properties, also grant the TermStore.Readwrite.All permission.