how to reset and change password using microsoft graph api of Azure AD B2C users?

SRI 26 Reputation points
2021-06-22T05:41:30.063+00:00

108001-changpassword.png107889-resetpassword.pngPOST /users/{id | userPrincipalName}/authentication/passwordMethods/{id}/resetPassword

POST https://graph.microsoft.com/beta/me/changePassword
POST https://graph.microsoft.com/v1.0/me/changePassword

tried above apis. but all the apis are giving below error

Microsoft Security | Microsoft Entra | Microsoft Entra External ID
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. AmanpreetSingh-MSFT 56,951 Reputation points Moderator
    2021-06-22T06:16:08.697+00:00

    Hi @SRI · Thank you for reaching out.

    In the changePassword call, you need to update the call to either /beta/users/object_id_or_upn_of_user or /beta/me. Reason why you are getting error resource not found is, because you are passing /beta/object_id_of_the_user.

    1. Make sure the token that you are passing in the Authorization Header is acquired under user context and NOT under application context (using client credentials flow).
    2. The token that you are passing in the Authorization Header must be of the same user whose password you are trying to change. You cannot use User1's token to change password of User2.
    3. These calls can only be used for local accounts and NOT for social accounts in B2C tenant, as the passwords for social accounts are stored in their respective IDPs.
    4. Make sure you have provided consent for below delegated permissions:
      • Directory.AccessAsUser.All - Required for changePassword
      • UserAuthenticationMethod.ReadWrite.All - Required for resetPassword

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


  2. Kim 1 Reputation point
    2021-12-03T14:17:33.493+00:00

    Hi

    I have an Azure AD B2C App registration and I want to be able to change passwords for users under that App with the Graph Api.

    But I keep getting an exception that the 'Access to change password operation is denied' - I have tried to give the App different roles in the AD (Password and Helpdesk Admin) - but nothing seems to help.

    I can not find this permission 'Directory.AccessAsUser.All' - under Graph API and Delegated Permissions I only have "openid" and "offline_access" and I can not find it under Delegated Permissions.

    Any clue and help will be much appreciated. :)

    Thanks in advance.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.