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:
- Create and configure an API Application Registration in Microsoft Entra ID.
- Create a Client Application Registration that will request tokens.
- Configure Azure API Management with the Entra ID endpoints and application details.
- Protect the API using a JWT validation policy.
- 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-apiAfter creating the application:
Copy the Application (Client) ID
You will need this value later when configuring APIM.
Example:
8c5e3a9c-xxxx-xxxx-xxxx-xxxxxxxxxxxxExpose an API
Open:
Expose an APIClick:
Set Application ID URIExample:
api://8c5e3a9c-xxxx-xxxx-xxxx-xxxxxxxxxxxxCreate a scope.
Example:
access_as_userThe resulting scope becomes:
api://8c5e3a9c-xxxx-xxxx-xxxx-xxxxxxxxxxxx/access_as_userThis 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-clientAfter creation:
Create a Client Secret
Navigate to:
Certificates & secretsCreate a new secret and save it immediately.
Example:
N8gxxxxxxxxxxxxxxxxxxxxxxxxxxYou won’t be able to retrieve it again later.
Grant API Permissions
Open:
API PermissionsAdd permission:
My APIsSelect:
apim-demo-apiChoose the scope:
access_as_userGrant 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:
| Name | Value |
|---|---|
| tenant-id | Your Entra Tenant ID |
| client-id | API Application Client ID |
| audience | Application ID URI |
Example:
tenant-id
fd4ab97b-c42d-4de1-9863-01955ba45151client-id
8c5e3a9c-xxxx-xxxx-xxxx-xxxxxxxxxxxxaudience
api://8c5e3a9c-xxxx-xxxx-xxxx-xxxxxxxxxxxxUsing Named Values makes promotion across environments significantly easier.
Configure an OAuth 2.0 Authorization Server
Navigate to:
APIM
→ OAuth 2.0 + OpenID Connect
→ AddConfigure:
Authorization Endpoint
https://login.microsoftonline.com/{tenant-id}/oauth2/v2.0/authorizeToken Endpoint
https://login.microsoftonline.com/{tenant-id}/oauth2/v2.0/tokenClient ID
<Client Application Client ID>Client Secret
<Client Secret>Default Scope
api://<api-client-id>/access_as_userSave 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 UnauthorizedIf 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.0Select:
Client CredentialsConfigure:
Token URL
https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/tokenClient ID
<Client Application Client ID>Client Secret
<Client Secret>Scope
api://<api-client-id>/access_as_userGrant Type
Client CredentialsClick:
Get New Access TokenPostman 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 APIIf everything is configured correctly, the API responds:
{
"status": "SUCCESS"
}Common Issues
Invalid Audience
Error:
JWT Validation Failed: Audience is invalidCause:
The audience configured in APIM does not match the audience inside the JWT token.
Invalid Scope
Error:
AADSTS70011Cause:
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-configurationCommon 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.





0 Comments