Skip to content

Instantly share code, notes, and snippets.

@tshego3
Last active October 2, 2025 10:22
Show Gist options
  • Select an option

  • Save tshego3/e44fa0ccda509c1bf755578165fb2ac5 to your computer and use it in GitHub Desktop.

Select an option

Save tshego3/e44fa0ccda509c1bf755578165fb2ac5 to your computer and use it in GitHub Desktop.
Here’s a comprehensive guide to obtain a token from Microsoft B2C OAuth 2.0 using Postman with the Implicit Grant Flow. You’ve already shared a lot of the required information, so we’ll build on that.

Microsoft B2C OAuth 2.0 using Postman

1. Prerequisites

Make sure you have the following:

  • A registered application in Azure AD B2C.
  • A Policy defined (like a sign-up/sign-in policy).
  • A Client ID (Application ID) from your B2C app.
  • A Scope related to your Web API.
  • Postman installed.

2. Azure AD B2C Configuration

Ensure that you’ve configured your B2C App with the Implicit Grant Flow in the Azure AD B2C portal. Here's a quick check of what should be configured in Azure AD B2C:

  1. Register the Web App (OAuth 2.0 Client):

    • Go to Azure Portal > Azure Active Directory > App Registrations.

    • Select your B2C app.

    • Under Authentication, configure:

      • Platform: Web.
      • Redirect URI: Enter your app's redirect URI (for testing purposes, this could be https://oauth.pstmn.io/v1/browser-callback or a predefined URI in your B2C app).
      • Implicit Grant: Enable ID Token and Access Token if needed.
    • Under API Permissions, configure the scope related to your Web API, e.g., https://{tenant}.onmicrosoft.com/{web api app id uri}/{scope name}.

    • Note the Client ID and Tenant name, which you will use in Postman.

  2. Scope: This will be the scope you are requesting when obtaining the access token. You can configure it in the Azure portal.


3. Postman Setup

  1. Launch Postman: Open Postman to configure the OAuth 2.0 flow.

  2. Create a New Request:

    • Click New and select Request.

    • Name the request (e.g., OAuth 2.0 Implicit Flow).

    • Enter the Auth URL in the URL field:

      https://{tenant}.b2clogin.com/te/{tenant}.onmicrosoft.com/{policy}/oauth2/v2.0/authorize
      
      • Replace {tenant} with your actual tenant name.
      • Replace {policy} with the name of your B2C policy (e.g., b2c_1_signup_signin or b2c_1a_signup_signin).
  3. Authorization Tab:

    • Go to the Authorization tab in Postman.
    • Set Type to OAuth 2.0.
    • For OAuth 2.0 Flow, select Implicit.
  4. Configure OAuth 2.0 Settings:

    • Client ID: Paste your Application (Client) ID from your B2C app.

    • Client Secret: Leave this empty for Implicit flow (not needed).

    • Auth URL: Enter the URL you obtained earlier:

      https://{tenant}.b2clogin.com/te/{tenant}.onmicrosoft.com/{policy}/oauth2/v2.0/authorize
      
    • Scope: Enter your desired scope:

      https://{tenant}.onmicrosoft.com/{web api app id uri}/{scope name}
      
      • Replace {tenant} with your actual tenant.
      • Replace {web api app id uri} and {scope name} with the details of your API scope.
    • Redirect URL: Enter the redirect URL defined in your B2C app settings, e.g., https://oauth.pstmn.io/v1/browser-callback (or any other valid redirect URI).

    • State: Optional, but can be set to a random string for security purposes.

    • Response Type: Ensure this is set to id_token token (this is the standard response for Implicit flow).

    Example configuration:

    • Auth URL: https://contoso.b2clogin.com/te/contoso.onmicrosoft.com/b2c_1_signup_signin/oauth2/v2.0/authorize
    • Client ID: 12345678-abcd-1234-abcd-1234567890ab
    • Scope: https://contoso.onmicrosoft.com/my-api/scope.read
    • Redirect URI: https://oauth.pstmn.io/v1/browser-callback
  5. Get New Access Token:

    • Once everything is configured, click on the Get New Access Token button in Postman.
    • This will redirect you to the B2C login page (depending on the policy you configured, it may prompt for sign-in or show a custom UI).
    • Log in with your credentials.
    • Postman should automatically capture the Access Token (and optionally an ID Token) after successful authentication.
  6. Use the Token:

    • After you obtain the token, Postman will display the Access Token in a dialog.
    • You can then Use Token for subsequent requests.

4. Making API Requests with the Token

After obtaining the Access Token, you can use it to make API calls that require authentication. Here’s how to do that:

  1. Set Authorization Header:

    • In the Headers section of Postman, add the following:

      • Key: Authorization
      • Value: Bearer {access_token}
    • Replace {access_token} with the actual token you received from the Get New Access Token step.

  2. Make the Request:

    • Set the request URL to the endpoint of the API you want to call.

    • For example:

      https://{api_url}/your-api-endpoint
      
  3. Send the Request:

    • Click Send to make the request. If everything is set up correctly, you should receive a valid response from the API.

5. Troubleshooting

Here are a few things to check if the process isn't working as expected:

  • Redirect URI: Make sure that the redirect URI in Postman matches the one you set in Azure AD B2C. It’s case-sensitive.
  • Scope: Verify that the scope is correctly defined in both your B2C app and Postman.
  • Policy: Ensure the policy (e.g., b2c_1_signup_signin or b2c_1a_signup_signin) is correctly specified in the Auth URL.
  • Browser Popup: Sometimes the authentication page may not load in Postman directly, but it will open in a browser. Ensure that the browser allows pop-ups.

6. Final Thoughts

  • Security: Implicit flow is typically used for client-side applications (e.g., Single Page Apps). Since it exposes the access token to the browser, be cautious about using this in production environments for highly sensitive applications.
  • Access Token Expiry: Tokens obtained using Implicit flow usually have a short expiration time. Be prepared to handle token expiry and refresh tokens (although Implicit flow does not use refresh tokens, so the user would need to authenticate again).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment