Skip to content

Make App.token_provider tenant defaults scope-aware - #624

Open
Shivam Sharma (ShivamSharma43) wants to merge 1 commit into
microsoft:mainfrom
ShivamSharma43:fix/534-scope-aware-tenant-defaults
Open

Shivam Sharma (ShivamSharma43) wants to merge 1 commit into
microsoft:mainfrom
ShivamSharma43:fix/534-scope-aware-tenant-defaults

Conversation

@ShivamSharma43

Copy link
Copy Markdown

Fixes #534

TokenManager.get_app_token() fell back to the cloud's Bot Framework login tenant for every scope. On a multi-tenant app, app.token_provider.get_app_token(app.cloud.graph_scope) therefore built its MSAL client against botframework.com, while App._get_graph_token() used common.

Tenant resolution now lives only in TokenManager and depends on the scope:

  • Bot Framework scope: input tenant -> credentials tenant -> cloud.login_tenant
  • Graph scope: input tenant -> credentials tenant -> "common"
  • Any other scope: input tenant -> credentials tenant, otherwise ValueError

App._get_graph_token() no longer applies its own fallback, so the public provider and the internal Graph path can't disagree. The internal default_tenant_id keyword on TokenManager.get_app_token is removed, because the default now comes from the scope.

The tests run the real TokenManager and assert the MSAL authority for each case: the bot and Graph defaults for a multi-tenant app, an explicit or configured tenant for other scopes, and the error when no tenant is available. The app-level test checks that _get_graph_token() and token_provider.get_app_token(graph_scope) resolve the same tenant.

ruff check, ruff format --check and pyright are clean, and pytest packages/apps passes (1086 tests).

Note: for other scopes I chose to require a tenant instead of defining a fallback. That also applies to managed identity credentials, which don't use the tenant. I'm happy to relax that if you'd prefer.

TokenManager.get_app_token now picks the fallback tenant from the
requested scope: the cloud login tenant for the Bot Framework scope,
"common" for Graph, and none for other scopes, which then require an
explicit or configured tenant. App._get_graph_token drops its own
fallback so App.token_provider and the internal Graph path resolve
tenants in one place.

Fixes microsoft#534

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 4, 2026 18:17

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
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.

[Bug]: Make App.token_provider tenant defaults scope-aware

2 participants