Ein Azure-Dienst, der eine hybride Multi-Cloud-Verwaltungsplattform für APIs bereitstellt
Hi Johannes,
This is definitely strange behavior for the standard OAuth 2.0 Client Credentials flow. Since Microsoft Entra ID (Azure AD) is quite rigid with its default 1-hour expiration for access tokens, the issue usually isn't that the token isn't expiring—it's usually that the resource (the API) isn't checking the expiration date.
Here is a breakdown of where things might be going sideways and what you should check:
- The "Old Token" Test (The Smoke Test)
Take that 1-week-old token and paste it into jwt.ms.
Look for the exp (expiration) claim.
If the date in the exp claim is in the past (which it should be), then Microsoft Entra ID has done its job correctly.
The Conclusion: If the token is expired according to the payload but your baseUrl service still accepts it, the issue lies entirely within your API’s token validation logic, not Azure’s settings.
- Validation Logic at baseUrl
Most APIs that receive a Bearer token need to perform several checks. It sounds like your service might be validating the Signature (confirming the token was signed by Microsoft) but skipping the Lifetime Validation.
Check your code: If you are using middleware (like Microsoft.Identity.Web for .NET or passport-azure-ad for Node.js), ensure that ValidateLifetime is set to true.
Clock Skew: Most libraries allow for a 5-minute "clock skew" to account for time differences between servers. However, a week is way beyond any drift settings.
- The Audience (aud) Claim Mismatch
You are requesting a token for resource=https://management.azure.com/.
The Risk: If you are sending this token to your own custom API (Service B / baseUrl), your API should technically reject it because the aud (Audience) claim in the token is for Azure Management, not your specific service.
If your API accepts a token meant for a different resource and doesn't check the expiration date, it indicates the validation middleware is likely set to "permissive" or is incorrectly configured.
- Are you using a Proxy or WAF?
Sometimes, an Intermediate layer (like an Azure Application Gateway, an F5, or a specialized WAF) might be caching authorization headers or performing its own validation. If the backend never sees the "fresh" request and simply relies on a cached "200 OK" from a previous session, it might appear as if the token is still valid.
Summary Checklist for your Team:
Decode the token: Verify exp via jwt.ms.
Verify API Middleware: Ensure the service at baseUrl is explicitly configured to validate Lifetime and Audience.
Check for Caching: Ensure there is no local cache (Redis, In-Memory) on the API side that stores the "Validated" status of a token indefinitely.
If the exp claim in the JWT actually shows a date in the future (one week away), please let us know, as that would imply a Token Lifetime Policy has been applied to your Service Principal via PowerShell/Graph API, though even then, a 1-week duration for an access token is highly non-standard.
I hope this helps you narrow it down!
Best regards,