Authorization_RequestDenied - Insufficient privileges to complete the operation while updating user password using Graph API

Sachin 1 Reputation point
2022-10-07T13:34:47.113+00:00

I have a unique requirement to update the user passwords using Graph API. But, I have been getting Authorization_RequestDenied error.

{"error":{"code":"Authorization_RequestDenied","message":"Insufficient privileges to complete the operation.","innerError":{"date":"2022-10-06T22:45:14","request-id":"","client-request-id":""}}}  

Below is my code:

public async Task UpdatePassword()  
{  
 Microsoft.Identity.Client.IConfidentialClientApplication confidentialClientApplication = Microsoft.Identity.Client.ConfidentialClientApplicationBuilder  
              .Create("ClientId")  
              .WithClientSecret("ClientSecret")  
              .WithTenantId("TenantId")  
              .Build();  
            Microsoft.Graph.Auth.ClientCredentialProvider authProvider = new Microsoft.Graph.Auth.ClientCredentialProvider(confidentialClientApplication);  

            Microsoft.Graph.GraphServiceClient graphClient = new Microsoft.Graph.GraphServiceClient(authProvider);  

            var newPassword = "NewComplexP@ss";  

            var user = new Microsoft.Graph.User  
            {   
                PasswordProfile = new Microsoft.Graph.PasswordProfile  
                {  
                    Password = newPassword,  
                    ForceChangePasswordNextSignIn = false  
                }   
            };  

            await graphClient    
               .Users["a4e3f2ce-054e-43e4-bbfd-547c44582a7"]  
               .Request()  
               .UpdateAsync(user);  
}  

I have permissions added like below in Azure AdB2c.

enter image description here

248520-image.png

My question: despite adding all the permissions and using correct code(I assume) I am getting Authorization_RequestDenied error.

Am I missing anything? I highly appreciate any help.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,555 questions
Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
2,635 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,437 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Vasil Michev 95,081 Reputation points MVP
    2022-10-07T16:13:42.58+00:00

    Are you perhaps trying to change the password of a privileged (admin) user? As noted in the documentation, you need to have specific roles assigned to change password (and some other properties) of admin users:

    For delegated scenarios where an admin is acting on another user, the admin needs one of the following Azure AD roles:

    Global Administrator
    Privileged Authentication Administrator
    Authentication Administrator

    And also:

    Updating another user's sensitive properties like businessPhones, mobilePhone, or otherMails is not allowed on users who are assigned an administrator role or who are members of a role-assignable group, even when the app is granted the User.ReadWrite.All or Directory.ReadWrite.All delegated or application permissions. For more information about who can update sensitive properties or reset passwords, see Authorization and privileges.

    More detail here: https://learn.microsoft.com/en-us/graph/api/resources/users?view=graph-rest-1.0


  2. HarmeetSingh7172 4,811 Reputation points
    2022-10-07T16:29:50.133+00:00

    Hi @Sachin

    ChangePassword Graph API supports Delegated permissions only. As of now, it doesn't work with Application Permissions.

    As per this API, any user can update their password without belonging to any administrator role.

    Refer this documentation.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.


  3. Roman Ianchenko 0 Reputation points
    2023-05-04T07:57:52.5033333+00:00

    To make it work you need your App added to one of these roles

    • Global administrator
    • Privileged authentication administrator
    • Authentication administrator

    Next, modify your permissions. We'll use UserAuthenticationMethod.ReadWrite.All for this tutorial, so make sure it's enabled in Graph Explorer or your app.

    0 comments No comments