Search code examples
azureazure-ad-b2cazure-ad-graph-api

Microsoft Graph API - Update phoneMethods is no longer working


Suddenly my application is no longer able to update phoneAuthenticationMethod when it's created on B2C.

UPDATE STEPS TO REPRODUCE ISSUE:

  1. Enable MFA using Custom Policy starter pack from MS(https://github.com/Azure-Samples/active-directory-b2c-custom-policy-starterpack/tree/main/SocialAndLocalAccountsWithMfa)

  2. Create user in B2C and add MFA(SMS) to it using custom policy above enter image description here

  3. Get User MFA using Graph API to confirm that MFA was created

enter image description here

  1. Try to patch MFA using Graph API, but getting error below enter image description here

Portal: enter image description here


Solution

  • The error occurs if you try to update the phone method when there is no existing mobile number added to that user as authentication method.

    I have one user with phone authentication method added in office phoneType as below:

    enter image description here

    When I tried to update that phone method as mobile phoneType and Id as 3179e48a-750b-4051-897c-87b9720928f7, I too got same error like this:

    PATCH https://graph.microsoft.com/v1.0/users/userId/authentication/phoneMethods/3179e48a-750b-4051-897c-87b9720928f7
    {
      "phoneNumber": "+1 2065555554",
      "phoneType": "mobile"
    }
    

    Response:

    enter image description here

    As mentioned in this MS Document,

    The value of phoneMethodId changes depending on phoneType you want to update:

    • b6332ec1-7057-4abe-9331-3d72feddfe41 to update the alternateMobile phoneType.
    • e37fc753-ff3b-4958-9484-eaa9425c82bc to update the office phoneType.
    • 3179e48a-750b-4051-897c-87b9720928f7 to update the mobile phoneType.

    In your case, initially fetch the list of phone methods added to user with below API call:

    GET https://graph.microsoft.com/v1.0/users/userId/authentication/phoneMethods/
    

    Response:

    enter image description here

    If mobile phoneType is not present in response, make use of POST call to add it as authentication method like below:

    POST https://graph.microsoft.com/v1.0/users/userId/authentication/phoneMethods/
    {
      "phoneNumber": "+1 2065555554",
      "phoneType": "mobile"
    }
    

    Response:

    enter image description here

    You can now update this using PATCH call as phone method of mobile phoneType is existing now:

    PATCH https://graph.microsoft.com/v1.0/users/userId/authentication/phoneMethods/3179e48a-750b-4051-897c-87b9720928f7
    {
      "phoneNumber": "+1 2055555555",
      "phoneType": "mobile"
    }
    

    Response:

    enter image description here

    To confirm that, I checked the same in Portal where phone method of mobile phoneType update successfully:

    enter image description here