Actually I have some issues related run a code for get a token from Microsoft graph API. Kindly guide me that how can I create a user flow with ROPC authentication and then how can we run it on postman or in Laravel controller to get a token. I tried it, but got some error. Image is attached for more clarity. Refer the image

1

There are 1 best solutions below

4
kavyaS On BEST ANSWER

You can follow this Set up a resource owner password credentials flow - Azure AD B2C | Microsoft Docs

Create user flow in azuread b2c tenant. enter image description here

Give some name and check the claims that need to be returned.

enter image description here

  • Create an app using app registration blade for the user to access, which then has user.read and offline_access scopes.
  • Also copy application id or client id to use in scopes .

enter image description here

  • Then you can go to the created userflow and run user flow to get the endpoints and complete metadata to use.
  • In postman , you need to mention following parameters (username , password,grant_type as password,scope as openid application-id offline_access ,client_id as application-id, response_type) in the body. Highlighted are required ones as stated in document test-the-ropc-flow

I tested and got accesstoken and id token successfully in postman. Where i gave POST request to https://xxx.b2clogin.com/xx.onmicrosoft.com/oauth2/v2.0/token?p=b2c_1_ropcsignin (b2c_1_ropcsignin is the userflow policy name).

enter image description here - You can copy the accessToken and decode in https://jwt.io or https://jwt.ms to see the user details and claims. I got the selected claims in my userflow.

enter image description here

EDIT:

You can select the required claims under "Application claims" in step2

enter image description here

then if you decode the access token that you get after updating the selection, you can see the email of the user in token claims. enter image description here