Skip to content

Support Entra inbound Agent ID tokens#462

Merged
heyitsaamir merged 6 commits into
feature_agent365_supportfrom
add_inbound_token_validation
Jun 22, 2026
Merged

Support Entra inbound Agent ID tokens#462
heyitsaamir merged 6 commits into
feature_agent365_supportfrom
add_inbound_token_validation

Conversation

@heyitsaamir

@heyitsaamir heyitsaamir commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Adds inbound validation for Agent ID activities using Entra tokens.

Why:
Agent 365 inbound activities can arrive with Entra access tokens whose audience is the agent identity blueprint app ID. Classic Bot Framework validation looks at the wrong JWKS for those tokens, so the request is rejected before handlers run.

Interesting bits:

  • TokenValidator now owns the inbound activity token branching.
  • We do one untrusted JWT parse up front to choose the validation path. This is only routing info (iss / tid), not authentication. The token is accepted only after the chosen validator does full signature, issuer, audience, and scope validation.
  • Entra issuers validate with tenant Entra JWKS and blueprint audience.
  • Classic Bot Framework tokens keep the existing service token validation path.
  • The per-tenant Entra validator cache is bounded so random tenant IDs can’t grow it forever.

Testing:

  • uv run pytest packages/apps/tests/test_token_validator.py::TestInboundActivityTokenValidator::test_validate_token_uses_service_validator_for_bot_framework_tokens packages/apps/tests/test_token_validator.py::TestInboundActivityTokenValidator::test_get_entra_validator_caches_by_tenant packages/apps/tests/test_token_validator.py::TestInboundActivityTokenValidator::test_get_entra_validator_cache_is_bounded
  • uv run ruff check packages/apps/src/microsoft_teams/apps/auth/token_validator.py packages/apps/tests/test_token_validator.py

@heyitsaamir

Copy link
Copy Markdown
Collaborator Author

Closing duplicate manual PR. GitSpice-created replacement is #463.

@heyitsaamir

heyitsaamir commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator Author

Base automatically changed from add_agent365_token_support to feature_agent365_support June 18, 2026 23:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for validating inbound Agent ID activities authenticated with Entra access tokens, while preserving the existing Bot Framework connector token validation path. This updates the HTTP server to use a new inbound validator that branches validation based on the token issuer.

Changes:

  • Introduces InboundActivityTokenValidator to route inbound validation between Bot Framework service tokens and Entra tokens (per-tenant JWKS).
  • Updates HttpServer to use the new inbound validator for activity authentication.
  • Adds unit tests covering issuer-based routing and tenant validator caching.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
packages/apps/src/microsoft_teams/apps/auth/token_validator.py Adds inbound activity token branching logic and Entra-per-tenant validator caching.
packages/apps/src/microsoft_teams/apps/http/http_server.py Switches inbound auth from TokenValidator.for_service(...) to InboundActivityTokenValidator.
packages/apps/src/microsoft_teams/apps/auth/init.py Re-exports InboundActivityTokenValidator from the auth package.
packages/apps/tests/test_token_validator.py Adds tests for inbound token branching and tenant validator caching behavior.

Comment thread packages/apps/src/microsoft_teams/apps/auth/token_validator.py
Comment thread packages/apps/src/microsoft_teams/apps/auth/token_validator.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread packages/apps/src/microsoft_teams/apps/auth/token_validator.py
Comment thread packages/apps/src/microsoft_teams/apps/auth/token_validator.py Outdated
@heyitsaamir heyitsaamir merged commit 2958451 into feature_agent365_support Jun 22, 2026
9 checks passed
@heyitsaamir heyitsaamir deleted the add_inbound_token_validation branch June 22, 2026 19:21
@heyitsaamir heyitsaamir restored the add_inbound_token_validation branch June 22, 2026 19:27
heyitsaamir added a commit that referenced this pull request Jun 24, 2026
Adds inbound validation for Agent ID activities using Entra tokens.

Why:
Agent 365 inbound activities can arrive with *Entra access tokens* whose
audience is the agent identity blueprint app ID. Classic Bot Framework
validation looks at the wrong JWKS for those tokens, so the request is
rejected before handlers run.

Interesting bits:
- TokenValidator now owns the inbound activity token branching.
- We do one untrusted JWT parse up front to choose the validation path.
This is only routing info (`iss` / `tid`), not authentication. The token
is accepted only after the chosen validator does full signature, issuer,
audience, and scope validation.
- Entra issuers validate with tenant Entra JWKS and blueprint audience.
- Classic Bot Framework tokens keep the existing service token
validation path.
- The per-tenant Entra validator cache is bounded so random tenant IDs
can’t grow it forever.

Testing:
- uv run pytest
packages/apps/tests/test_token_validator.py::TestInboundActivityTokenValidator::test_validate_token_uses_service_validator_for_bot_framework_tokens
packages/apps/tests/test_token_validator.py::TestInboundActivityTokenValidator::test_get_entra_validator_caches_by_tenant
packages/apps/tests/test_token_validator.py::TestInboundActivityTokenValidator::test_get_entra_validator_cache_is_bounded
- uv run ruff check
packages/apps/src/microsoft_teams/apps/auth/token_validator.py
packages/apps/tests/test_token_validator.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants