Skip to content

Support Entra inbound Agent ID tokens#629

Open
heyitsaamir wants to merge 1 commit into
agent365-token-supportfrom
agent365-inbound-entra-tokens
Open

Support Entra inbound Agent ID tokens#629
heyitsaamir wants to merge 1 commit into
agent365-token-supportfrom
agent365-inbound-entra-tokens

Conversation

@heyitsaamir

@heyitsaamir heyitsaamir commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Adds support for validating inbound Entra ID tokens (used by Agent 365) alongside existing BotFramework tokens:

  • ServiceTokenValidator now routes tokens based on issuer — Entra vs BotFramework
  • Decodes unverified JWT payload to inspect iss and tid claims
  • Per-tenant Entra JwtValidator instances with bounded LRU cache (max 100)
  • Entra tokens validated against tenant-specific OIDC metadata
  • Exports decodeJwtPayload from jwt-validator for pre-validation inspection

Note: Does not currently do service url validation (not present in Token)

@heyitsaamir

Copy link
Copy Markdown
Collaborator Author

Comment thread packages/apps/src/middleware/auth/service-token-validator.spec.ts Outdated
Comment thread packages/apps/src/middleware/auth/service-token-validator.spec.ts Outdated
Comment thread packages/apps/src/middleware/auth/service-token-validator.spec.ts
@heyitsaamir heyitsaamir force-pushed the agent365-inbound-entra-tokens branch from 2c70876 to 4ca9f2f Compare June 26, 2026 19:41
@heyitsaamir

Copy link
Copy Markdown
Collaborator Author

Addressed all review comments:

"kind of a weird thing to test for JwtValidator construction times" — Agreed, removed. Now testing behavior (correct args to validateAccessToken) rather than constructor call counts.

"No need for this" / "But wait why is it called twice?" — It was called twice because once in the constructor (BotFramework validator) and once for the Entra validator. Removed those assertions — they were testing implementation details. Cache test now checks cache.size directly.

"Do we really need to mock JwtValidator? Can't we just call it?" — We need the mock because the real JwtValidator makes HTTP calls to JWKS endpoints (e.g. login.botframework.com/v1/.well-known/keys) to fetch signing keys for signature verification. Can't do that with synthetic test tokens. Added a comment explaining this.

@heyitsaamir heyitsaamir marked this pull request as ready for review June 26, 2026 19:54
@heyitsaamir heyitsaamir force-pushed the agent365-token-support branch from 66a1dec to 96485b1 Compare June 26, 2026 20:19
@heyitsaamir heyitsaamir force-pushed the agent365-inbound-entra-tokens branch from 4ca9f2f to 16d77d7 Compare June 26, 2026 20:19
@heyitsaamir heyitsaamir requested a review from Copilot June 26, 2026 20:29

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 Microsoft Entra ID JWTs (Agent 365) in addition to existing Bot Framework service tokens, by routing validation based on the token issuer and using tenant-specific Entra validation configuration.

Changes:

  • Route tokens by unverified iss claim (Entra vs Bot Framework) and validate Entra tokens with per-tenant JwtValidator instances cached by tid.
  • Add decodeJwtPayload export to enable pre-validation inspection of JWT payload claims.
  • Extend unit tests to cover issuer routing, Entra tid requirements, and validator caching behavior.

Reviewed changes

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

File Description
packages/apps/src/middleware/auth/service-token-validator.ts Adds issuer-based routing and per-tenant Entra validator cache.
packages/apps/src/middleware/auth/service-token-validator.spec.ts Updates mocks and adds tests for Entra/Bot Framework routing and cache bounding.
packages/apps/src/middleware/auth/jwt-validator.ts Exposes a helper to decode JWT payloads without verification for routing/inspection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/apps/src/middleware/auth/service-token-validator.ts
Comment thread packages/apps/src/middleware/auth/service-token-validator.ts
Comment thread packages/apps/src/middleware/auth/jwt-validator.ts Outdated

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 3 out of 3 changed files in this pull request and generated 3 comments.

Comment on lines +84 to +86
private decodePayload(rawToken: string): Record<string, any> | null {
return decodeJwtPayload(rawToken);
}
);
}

private async validateEntraToken(rawToken: string, unverifiedPayload: Record<string, any> | null) {
Comment on lines +114 to +118
tenantId,
loginEndpoint: this.cloud.loginEndpoint,
validateIssuer: { allowedTenantIds: [tenantId] },
jwksUriOptions: { type: 'tenantId' },
});
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.

2 participants