How to Set Up OAuth 2.0 in Azure Entra for Azure API Management Authentication

OAuth 2.0 authentication with Azure API Management

Written by Jan Daris

Jan Daris is a hands-on Integration Architect and Developer who enjoys solving complex integration puzzles with Azure, Boomi, APIs, and event-driven architecture. Through this blog, he shares practical knowledge, lessons learned, and real-world solutions to help other architects, developers, and IT teams build better integration platforms.

June 9, 2026

Introduction

In this article, I will walk through how to configure OAuth 2.0 authentication using Microsoft Entra ID and Azure API Management (APIM), and how to validate the access token before forwarding requests to your backend API.

This setup uses:

  • Microsoft Entra ID as the Identity Provider (IdP)
  • Azure API Management as the API Gateway
  • Postman as the OAuth 2.0 test client
  • An Azure backend API (or mock API) protected by APIM

The complete setup is demonstrated in my YouTube video, which is embedded below.


Architecture Overview

The following diagram illustrates the complete OAuth 2.0 flow used throughout this tutorial.

4

The process consists of five main steps:

  1. Create and configure an API Application Registration in Microsoft Entra ID.
  2. Create a Client Application Registration that will request tokens.
  3. Configure Azure API Management with the Entra ID endpoints and application details.
  4. Protect the API using a JWT validation policy.
  5. Use Postman to obtain an access token and call the protected API.

Video Walkthrough

In the video below, I demonstrate the complete setup from start to finish.


Step 1 – Create the API Application Registration

The first application registration represents the API that Azure API Management will protect.

Navigate to:

Microsoft Entra ID → App registrations → New registration

Give the application a meaningful name, for example:

apim-demo-api

After creating the application:

Copy the Application (Client) ID

You will need this value later when configuring APIM.

Example:

8c5e3a9c-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Expose an API

Open:

Expose an API

Click:

Set Application ID URI

Example:

api://8c5e3a9c-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Create a scope.

Example:

access_as_user

The resulting scope becomes:

api://8c5e3a9c-xxxx-xxxx-xxxx-xxxxxxxxxxxx/access_as_user

This scope defines what clients are allowed to request.


Step 2 – Create the Client Application Registration

Next, create another App Registration.

This application represents Postman, a mobile application, web application, or any external consumer of your API.

Example name:

postman-client

After creation:

Create a Client Secret

Navigate to:

Certificates & secrets

Create a new secret and save it immediately.

Example:

N8gxxxxxxxxxxxxxxxxxxxxxxxxxx

You won’t be able to retrieve it again later.


Grant API Permissions

Open:

API Permissions

Add permission:

My APIs

Select:

apim-demo-api

Choose the scope:

access_as_user

Grant admin consent if required.


Step 3 – Configure Azure API Management

Now that Entra ID is configured, we can connect APIM to it.

Navigate to your APIM instance.


Create Named Values

I recommend storing all OAuth-related values as Named Values instead of hardcoding them.

Create:

NameValue
tenant-idYour Entra Tenant ID
client-idAPI Application Client ID
audienceApplication ID URI

Example:

tenant-id
fd4ab97b-c42d-4de1-9863-01955ba45151
client-id
8c5e3a9c-xxxx-xxxx-xxxx-xxxxxxxxxxxx
audience
api://8c5e3a9c-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Using Named Values makes promotion across environments significantly easier.


Configure an OAuth 2.0 Authorization Server

Navigate to:

APIM
→ OAuth 2.0 + OpenID Connect
→ Add

Configure:

Authorization Endpoint

https://login.microsoftonline.com/{tenant-id}/oauth2/v2.0/authorize

Token Endpoint

https://login.microsoftonline.com/{tenant-id}/oauth2/v2.0/token

Client ID

<Client Application Client ID>

Client Secret

<Client Secret>

Default Scope

api://<api-client-id>/access_as_user

Save the configuration.

This allows APIM Developer Portal users to authenticate through Microsoft Entra ID.


Step 4 – Protect the API with JWT Validation

Now configure your API policy.

Inbound Policy:

<!--
    - Policies are applied in the order they appear.
    - Position <base/> inside a section to inherit policies from the outer scope.
    - Comments within policies are not preserved.
-->
<!-- Add policies as children to the <inbound>, <outbound>, <backend>, and <on-error> elements -->
<policies>
    <!-- Throttle, authorize, validate, cache, or transform the requests -->
    <inbound>
        <validate-jwt header-name="Authorization"
            require-scheme="Bearer"
            failed-validation-httpcode="401"
            failed-validation-error-message="Unauthorized. Access token is missing or invalid.">
            <openid-config
                url="https://login.microsoftonline.com/{{tenantid}}/v2.0/.well-known/openid-configuration"
                validate-connectivity="false" />
            <audiences>
                <audience>api://{{clientid}}</audience>
                <audience>{{clientid}}</audience>
            </audiences>
            <issuers>
                <issuer>https://login.microsoftonline.com/{{tenantid}}/v2.0</issuer>
                <issuer>https://sts.windows.net/{{tenantid}}/</issuer>
            </issuers>
        </validate-jwt>
        <base />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
        <set-header name="Content-Type" exists-action="override">
            <value>application/json</value>
        </set-header>
        <set-body template="none">{"status":"SUCCESS"}</set-body>
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

The policy performs:

  • Signature validation
  • Issuer validation
  • Audience validation
  • Token expiration validation

If the token is invalid, APIM immediately returns:

401 Unauthorized

If the token is valid, the request continues to the backend.


Example Mock Backend

For testing purposes, I often configure a simple APIM mock response:

<return-response>
<set-status code="200" reason="OK" />
<set-body>{"status":"SUCCESS"}</set-body>
</return-response>

This allows you to verify OAuth independently from the backend implementation.


Step 5 – Configure Postman

Open Postman.

Navigate to:

Authorization
→ OAuth 2.0

Select:

Client Credentials

Configure:

Token URL

https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token

Client ID

<Client Application Client ID>

Client Secret

<Client Secret>

Scope

api://<api-client-id>/access_as_user

Grant Type

Client Credentials

Click:

Get New Access Token

Postman will request a JWT token from Microsoft Entra ID.


Call the Protected API

Postman automatically adds:

Authorization: Bearer eyJ0eXAiOiJKV1Qi...

Send the request to APIM.

Flow:

Postman
↓
Microsoft Entra ID
↓
Access Token
↓
Azure API Management
↓
validate-jwt
↓
Backend API

If everything is configured correctly, the API responds:

{
"status": "SUCCESS"
}

Common Issues

Invalid Audience

Error:

JWT Validation Failed: Audience is invalid

Cause:

The audience configured in APIM does not match the audience inside the JWT token.


Invalid Scope

Error:

AADSTS70011

Cause:

The requested scope does not exist or has not been exposed by the API application registration.


Unable to Obtain OpenID Configuration

Error:

Unable to obtain configuration from:
https://login.microsoftonline.com/{tenant}/v2.0/.well-known/openid-configuration

Common causes:

  • Incorrect Tenant ID
  • Firewall restrictions
  • APIM running inside a locked-down VNET without internet access
  • Typographical errors in the OpenID URL

Conclusion

Using Microsoft Entra ID together with Azure API Management provides a secure and scalable way to protect APIs using OAuth 2.0 and JWT tokens. By separating the API application registration from the client application registration, validating tokens in APIM, and testing with Postman, you create a standards-based security model that can be reused across your entire integration landscape.

The approach shown here is suitable for Azure Functions, Logic Apps, Container Apps, App Services, and virtually any backend hosted behind Azure API Management.

You May Also Like…

0 Comments