Skip to content

fix: route app.get_app_graph + ctx.*_graph to sovereign endpoints via cloud.graph_scope#402

Open
corinagum wants to merge 2 commits intomainfrom
cg/graph-cloud-baseurl
Open

fix: route app.get_app_graph + ctx.*_graph to sovereign endpoints via cloud.graph_scope#402
corinagum wants to merge 2 commits intomainfrom
cg/graph-cloud-baseurl

Conversation

@corinagum
Copy link
Copy Markdown
Contributor

  • App.get_app_graph(), ctx.app_graph, and ctx.user_graph were routing all Microsoft Graph calls to the public-cloud endpoint (https://graph.microsoft.com) regardless of the sovereign cloud configured on the app. Sovereign customers (GCCH, DoD, China) would hit the wrong cloud. This PR derives the Graph base URL from cloud.graph_scope on App and plumbs it through every Graph client the framework constructs.
  • Public cloud (default): graph_scope = "https://graph.microsoft.com/.default" → derived base URL = https://graph.microsoft.com = previous hardcoded default. Zero behavior change.
  • Sovereign clouds: behavior changes from broken (silently public) to correct (per-cloud). This is the fix.

Copilot AI review requested due to automatic review settings April 23, 2026 22:16
Comment thread packages/graph/tests/test_graph.py Fixed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Routes Microsoft Graph client construction in the Teams Apps framework to the correct sovereign cloud endpoint by deriving the Graph base URL from the configured CloudEnvironment.graph_scope and propagating it through App.get_app_graph() and ActivityContext graph properties.

Changes:

  • Add a base_url override path in microsoft-teams-graph’s get_graph_client() and validate behavior via new unit tests.
  • Derive Graph base URL from cloud.graph_scope in microsoft-teams-apps and pass it into all framework-created Graph clients.
  • Plumb cloud through ActivityProcessorActivityContext so ctx.app_graph / ctx.user_graph route correctly.

Reviewed changes

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

Show a summary per file
File Description
packages/graph/src/microsoft_teams/graph/graph.py Adds base_url override support when constructing GraphServiceClient.
packages/graph/tests/test_graph.py Adds coverage ensuring default/public base URL and sovereign base URL routing + normalization.
packages/apps/src/microsoft_teams/apps/utils/graph.py Derives Graph base URL from CloudEnvironment.graph_scope and forwards it to get_graph_client.
packages/apps/src/microsoft_teams/apps/routing/activity_context.py Stores cloud on the context and uses it when creating user_graph/app_graph.
packages/apps/src/microsoft_teams/apps/app_process.py Adds cloud to ActivityProcessor and forwards it when building ActivityContext.
packages/apps/src/microsoft_teams/apps/app.py Passes self.cloud into create_graph_client() for get_app_graph().
packages/apps/tests/test_optional_graph_dependencies.py Adds tests for cloud→Graph base URL derivation and updates mocks for new Graph client signature.
packages/apps/tests/test_app_process.py Updates ActivityProcessor/ActivityContext construction to pass PUBLIC cloud.
packages/apps/tests/test_app_oauth.py Updates ActivityProcessor/ActivityContext construction to pass PUBLIC cloud.
packages/apps/tests/test_activity_context.py Updates ActivityContext construction to pass PUBLIC cloud.

Comment thread packages/apps/src/microsoft_teams/apps/routing/activity_context.py
Comment thread packages/apps/src/microsoft_teams/apps/app_process.py
Comment thread packages/graph/src/microsoft_teams/graph/graph.py Outdated
@corinagum corinagum force-pushed the cg/graph-cloud-baseurl branch from 673a31d to 90fef1a Compare April 24, 2026 23:33
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