Search code examples
oauth-2.0jwtazure-ad-b2c

How can I manually get an access token using OAuth 2.0 authorization code flow in Azure Active Directory B2C?


For testing purposes I am trying to manually get an access token. The guide Request an access token in Azure Active Directory B2C basically describes two steps:

  1. Get the authorization code - fine, no issue here
  2. Using the authorization code, get an access token

I am having issues on step 2:

According to the instructions one shall make a POST request and specify https://jwt.ms as redirect_uri. I am using Postman to make this POST request, but in this case I have no chance to get the reply that is sent to https://jwt.ms ? So how could that work at all? Am I misunderstanding something? (I am still quite new to OAuth 2)


Solution

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

    I created an Azure AD Application and exposed an API:

    enter image description here

    Now, I added the API permissions like below:

    enter image description here

    I generated the auth-code by using below endpoint:

    https://b2ctenant.b2clogin.com/b2ctenant.onmicrosoft.com/B2C_1_Signinsignup/oauth2/v2.0/authorize?
    &client_id=7969b8c5-e6c6-49ab-b012-xxxxx
    &response_type=code
    &redirect_uri=https://jwt.ms
    &response_mode=query
    &scope=https://b2ctenant.onmicrosoft.com/7969b8c5-e6c6-49ab-b012-d59xxxxx/test.read
    &state=12345
    

    enter image description here

    I generated the access token using below parameters:

    https://b2ctenant.b2clogin.com/b2ctenant.onmicrosoft.com/B2C_1_Signinsignup/oauth2/v2.0/token
    
    client_id:7969b8c5-e6c6-49ab-b012-d598a9d99d17
    grant_type:authorization_code
    scope:https://b2ctenant.onmicrosoft.com/7969b8c5-e6c6-49ab-b012-xxxxxx/test.read
    code:code
    redirect_uri:https://jwt.ms
    client_secret:ClientSecret
    

    enter image description here