π How Azure API Management Passes OAuth Tokens to Power Automate Using Managed Identity
A deep‑dive guide for enterprise integration teams
Modern integration patterns increasingly rely on secure, scalable, identity-driven connectivity.Systems such as IOM, ERP, and retailer integrations often speak to each other through Azure API Management (APIM), which then forwards payloads to Power Automate cloud flows APIM acts as the single controlled ingress point, routing traffic to cloud flows configured behind secured endpoints rather than exposing them directly.
One question always comes up:
How does APIM obtain an OAuth token and pass it to a secure Power Automate endpoint?
The answer lies in a powerful Azure feature: Managed Identity.
This article breaks down the complete lifecycle—from token acquisition to validation—along with best practices used internally across our integration landscape.
1. Why Use Managed Identity Instead of Client Secrets?
Traditionally, calling an OAuth‑secured Flow/Logic App required:
- An App Registration
- A Client ID + Client Secret
- Manual secret rotation
- Manual configuration in APIM
Today, Managed Identity eliminates all of this.
Benefits:
- No secrets to rotate or store.
- Identity is bound to the APIM instance.
- Azure handles token issuance automatically.
- Simplifies architecture—lower maintenance effort.
- Strong enterprise security posture.
This aligns with our internal API strategy, which prefers standardized OAuth‑based system-to-system integrations as seen in the API Mgmt Strategy document by David Whyte and . [API Mgmt Stratgey | PowerPoint]
2. The End‑to‑End Token Flow (High‑Level)
Here’s the simplified version of what happens when APIM calls a secured Power Automate Flow:
Client → APIM → Managed Identity → Entra ID → Access Token → Power Automate Flow
More precisely:
Client calls APIM
APIM becomes the authoritative gateway ( all source systems send to APIM before the flow is invoked).APIM uses its Managed Identity
Using the<authentication-managed-identity>policy, APIM asks Entra ID for a token.Entra ID returns an OAuth 2.0 Bearer token
The token is issued for the specific audience (Flow endpoint).APIM injects the token
It adds:Authorization: Bearer <token>APIM forwards the request to Power Automate
Power Automate verifies the token
- Issuer (tenant)
- Signing keys
- Audience
- Identity (APIM’s Managed Identity)
If valid, the flow runs (typically a 202 Accepted pattern is used internally)
3. The Key APIM Policy: authentication-managed-identity
Your screenshot shows the heart of this mechanism:
XML
What this policy does:
- Tells APIM to obtain an OAuth token via its Managed Identity.
- Uses the
resource(a.k.a. audience) to know which token to request. - Inserts the resulting token into the outbound request.
What is the resource?
This must be the Application ID URI that the Power Automate HTTP trigger is configured to accept.
Common values include:
https://logic-apis.<region>.logic.azure.com/- A custom audience such as:
api://my-flow-secured-endpoint
If they don’t match, the Flow will reject the token.
4. What Happens Internally When APIM Requests a Token
Let’s drill deeper.
When APIM processes the <authentication-managed-identity> policy:
Step 1 — APIM identifies its Managed Identity
If it's system‑assigned, the identity is baked into the APIM resource itself.
If user‑assigned, APIM uses the assigned identity’s Client ID.
Step 2 — APIM sends a token request to Azure AD
Behind the scenes, APIM calls:
POST https://login.microsoftonline.com/{tenant-id}/oauth2/v2.0/token
with:
client_id = <APIM managed identity>
scope = <resource>/.default
grant_type= client_credentials
Step 3 — Entra ID issues the access token
The token contains:
- Issuer
- Audience (your Flow)
- Subject (APIM’s managed identity)
- Signature
- Expiry
Step 4 — APIM injects the token
APIM automatically adds:
Authorization: Bearer eyJ0eXAiOiJKV1...
No manual header scripting required.
5. How Power Automate Validates the Token
A Power Automate HTTP Request Trigger can be configured for OAuth 2.0 (Entra ID) authentication.
It validates:
✔ Issuer
Must match the tenant (e.g., https://login.microsoftonline.com/<tenant>/v2.0).
✔ Audience
Must match the Application ID URI you defined.
This is where incorrect configuration typically causes failures.
✔ Identity (APIM)**
The Flow must explicitly allow the APIM managed identity as a caller.
✔ Signature
Signed using Microsoft identity platform keysets.
If all is good → the Flow runs.
6. Architecture Pattern Used in Our Integrations
Source System
↓
APIM ← Identity, Policies, Central Gateway
↓
Power Automate (HTTP Trigger)
↓
Dataverse / ERP / Azure Functions
7. Example: Full APIM Policy for Managed Identity → Flo
XML
Notice:
- Existing authorization removed
- Managed identity token inserted
- Backend is the Flow endpoint
8. Common Pitfalls (and Fixes)
❌ “Invalid audience”
✔ Ensure APIM resource matches Flow’s Allowed Audience exactly.
❌ Flow never triggers
✔ Ensure APIM’s Managed Identity is added as an allowed caller.
❌ 401 Unauthorized
✔ Check issuer URL in Flow matches the tenant and v2.0 endpoint.
❌ Token obtained but rejected
✔ Validate region-specific Logic App gateway audience.
9. Why This Matters for Enterprise Integrations
Using Managed Identity:
- Reduces operational overhead
- Aligns with Zero‑Trust architecture
- Prevents credential leakage
- Minimizes Flow/Function timeouts
- Improves observability via APIM logging
- Centralizes governance at the gateway layer
It also matches the integration approach already used across IOM and other
Comments
Post a Comment