Search code examples
powershellazure-authenticationazure-rest-apiazure-ad-b2c

Create password reset userflow in powershell: Azure b2c?


I am creating Password reset user flow for my b2c users. From portal, I can create like this:

enter image description here

Is it supported to do the same from powershell or rest api?

I tried checking most of the graph v1.0 docs but I found nothing related to b2c. I want to implement this to avoid doing it manually from the portal.

Can anyone help me out with commands if they exist? If not, is there any other way possible to achieve this?

TIA


Solution

  • I tried to reproduce the same in my environment and got the below results:

    I created an Azure AD B2C application and granted API permissions like below:

    Make sure to grant IdentityUserFlow.ReadWrite.All permission:

    enter image description here

    I generated an access token via Postman by using client_credentials flow by using below Parameters:

    https://login.microsoftonline.com/TenantID/oauth2/v2.0/token
    
    client_id=Your_client_ID
    client_secret=Your_client_Secret
    grant_type=client_credentials
    scope=https://graph.microsoft.com/.default
    

    Response:

    enter image description here

    By using the above generated access token, open a new tab in Postman and include the parameters like below:

    In Authorization tab, select Type as Bearer Token and paste the access token like below:

    enter image description here

    In the Header tab, add Content-type: application/json and In the Body tab add like below:

     {
    "id": "testuserflow",
    "userFlowType": "passwordReset",
    "userFlowTypeVersion": 3
    }
    

    enter image description here

    By using the below Endpoint run the query and user flow will be created successfully like below:

    POST https://graph.microsoft.com/beta/identity/b2cUserFlows
    

    enter image description here

    In the Azure Portal, the testuserflow is successfully created like below:

    enter image description here