同调用Azure AD v1令牌端点,为何测试环境返回v2令牌?
Great question—this inconsistency can be confusing, but it almost always boils down to a configuration difference in the target resource or your tenant settings. Let’s walk through the most likely causes and how to check them:
Your test environment’s target API has
accessTokenAcceptedVersionset to 2
This is by far the most common reason. Azure AD doesn’t just rely on which endpoint you call to decide token version—it looks at the resource API’s application manifest settingaccessTokenAcceptedVersion. If your Azure AD B2C API app in test has this property set to2(instead of1ornull, which default to V1), Azure AD will automatically return a V2 token even when you hit the V1 endpoint.
To confirm this:- Head to the Azure Portal, find your test environment’s target API (the B2C app registration).
- Click Manifest under the Manage tab.
- Search for
accessTokenAcceptedVersion—if it’s set to2, that’s exactly why you’re seeing V2 tokens.
Subtle differences in your
resourceparameter
Even if you think your request bodies are identical, double-check theresourcevalue in test. If you’re using the API’s client ID instead of a V1-style resource URI (likehttps://yourtenant.onmicrosoft.com/yourapi), Azure AD might treat this as a request for a V2 token. Small tweaks here can change the token format returned.Tenant or B2C policy variations
If your test environment uses a separate Azure AD B2C tenant or has updated user flows/policies that enforce V2 tokens, that could also trigger this shift. B2C has some default behaviors that vary based on policy configuration, so it’s worth verifying your test policies match dev.
If you need V1 tokens in test, simply update the accessTokenAcceptedVersion in the API’s manifest to 1 or remove the property (setting it to null will revert to V1 for older apps). If V2 tokens are okay, just make sure your client can handle the V2 format—note that V2 tokens have slight claim differences, like aud sometimes being the API’s client ID instead of a resource URI.
内容的提问来源于stack exchange,提问作者nboettcher

