fix: accept api://botid-{app_id} audience format in token validation#314
Open
heyitsaamir wants to merge 2 commits intomainfrom
Open
fix: accept api://botid-{app_id} audience format in token validation#314heyitsaamir wants to merge 2 commits intomainfrom
heyitsaamir wants to merge 2 commits intomainfrom
Conversation
Bot Framework tokens issued for bots registered with Entra ID can carry
aud=api://botid-{app_id}, which was being rejected with a 401. Add this
audience format to both for_service() and for_entra() factory methods,
matching the TypeScript SDK behavior.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Python Teams Apps SDK token validation to accept the aud=api://botid-{app_id} audience format (in addition to the existing app_id and api://{app_id} formats), aligning behavior with Bot Framework/Entra-issued tokens and the TypeScript SDK.
Changes:
- Extend
TokenValidator.for_service()andTokenValidator.for_entra()to includeapi://botid-{app_id}invalid_audiences. - Update initialization tests to expect the additional audience.
- Add a parametrized test intended to cover acceptance of all three audience formats.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/apps/src/microsoft_teams/apps/auth/token_validator.py | Adds api://botid-{app_id} to the accepted audiences passed to jwt.decode for both service and Entra validators. |
| packages/apps/tests/test_token_validator.py | Updates expected audience lists and adds a parametrized test for audience-format acceptance. |
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+173
to
+175
| with ( | ||
| patch("jwt.PyJWKClient", return_value=mock_signing_key), | ||
| patch("jwt.decode", return_value=payload), |
Port applicationIdUri from teams.ts PR #469: adds application_id_uri to AppOptions, wires it through to TokenValidator.for_entra() so custom audience values (matching webApplicationInfo.resource in the app manifest) are accepted during Entra token validation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
lilyydu
approved these changes
Mar 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
api://botid-{app_id}to the valid audiences list inTokenValidator.for_service()andTokenValidator.for_entra(), matching the TypeScript SDK behavior (teams.ts#469)application_id_urioption toAppOptions— matcheswebApplicationInfo.resourcein the Teams app manifest — for custom audience values in Entra token validationapplication_id_uriTest plan
aud=api://botid-{app_id}are acceptedapplication_id_uriaudiences are accepted🤖 Generated with Claude Code