fix: use identifier_uri as audience for Azure token validation#3787
fix: use identifier_uri as audience for Azure token validation#3787
Conversation
Test Failure AnalysisSummary: Two tests in Root Cause: The PR correctly updates
Suggested Solution: Update
# Before
assert verifier.audience == "my-client-id"
# After
assert verifier.audience == "api://my-client-id"
# Before
token = key_pair.create_token(
subject="test-user",
issuer="https://login.microsoftonline.com/my-tenant-id/v2.0",
audience="my-client-id",
...
)
# After
token = key_pair.create_token(
subject="test-user",
issuer="https://login.microsoftonline.com/my-tenant-id/v2.0",
audience="api://my-client-id",
...
)Detailed AnalysisFailing tests: Implementation change ( # AzureJWTVerifier.__init__
self._identifier_uri = identifier_uri or f"api://{client_id}"
# ...
audience=self._identifier_uri, # was: audience=client_idThe token in Related Files
🤖 Generated with Claude Code |
Both
AzureProviderandAzureJWTVerifierhardcodedaudience=client_id(the raw application GUID) for JWT validation. This works when the Entra v2.0 token'saudclaim matches the GUID, but fails when the Application ID URI is a custom value likeapi://my-app-nameinstead ofapi://<guid>. This is common in Azure Bicep deployments whereidentifierUriscan't self-reference the app's ownappId.The fix uses
identifier_uri(which already defaults toapi://{client_id}) as the audience instead. Whenidentifier_uriisn't explicitly set, behavior is unchanged since Azure resolvesapi://<guid>to the GUID. When it is set to a custom value, the audience now matches what Entra actually puts in the token.Closes #3729