Skip to content

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

Merged
corinagum merged 6 commits into
mainfrom
cg/graph-cloud-baseurl
Apr 30, 2026
Merged

fix: route app.get_app_graph + ctx.*_graph to sovereign endpoints via cloud.graph_scope#402
corinagum merged 6 commits into
mainfrom
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

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

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 2 times, most recently from 90fef1a to b31472e Compare April 27, 2026 22:56
Comment thread packages/graph/src/microsoft_teams/graph/graph.py
Comment thread packages/graph/src/microsoft_teams/graph/graph.py
corinagum added a commit that referenced this pull request Apr 29, 2026
- get_graph_client: make base_url keyword-only
- test_graph: switch startswith to exact equality on default URL
  (resolves CodeQL py/incomplete-url-substring-sanitization)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
corinagum added a commit that referenced this pull request Apr 29, 2026
- get_graph_client: make base_url keyword-only
- test_graph: switch startswith to exact equality on default URL
  (resolves CodeQL py/incomplete-url-substring-sanitization)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@corinagum
corinagum force-pushed the cg/graph-cloud-baseurl branch from 119c7c7 to 44f932f Compare April 29, 2026 23:52
corinagum and others added 5 commits April 30, 2026 12:41
- get_graph_client: make base_url keyword-only
- test_graph: switch startswith to exact equality on default URL
  (resolves CodeQL py/incomplete-url-substring-sanitization)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
12 tests added in PR-area files (graph package and routing/activity_context):
- TokenValidator JWT missing 'exp' claim fallback path
- get_graph_client unexpected exception wrapping
- ActivityContext.user_graph success + caching + ImportError re-raise
- ActivityContext.sign_in OAuth card flow (1:1, group chat, options override)
- ActivityContext.sign_out success debug path

Lifts coverage on touched files:
- graph/graph.py: 92.86% -> 100%
- graph/auth_provider.py: 92.00% -> 100%
- routing/activity_context.py: 84.52% -> 98.71%

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
5 new tests covering closures and error branches:
- Plugin route closure invokes plugin.on_activity for qualified plugins
- updated_send wrapper emits on_activity_sent event
- Stream chunk/close handlers emit on_activity_sent
- StreamCancelledError caught with status 200 response
- ValueError raised when event_manager is missing
- _build_context marks is_signed_in when token API succeeds

Lifts app_process.py: 77.52% -> 96.12%

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@corinagum
corinagum force-pushed the cg/graph-cloud-baseurl branch from c4a693e to b9089c5 Compare April 30, 2026 19:41

@heyitsaamir heyitsaamir left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Won't block, but I would encourage a second think on

Comment thread packages/apps/src/microsoft_teams/apps/utils/graph.py Outdated
Comment thread packages/apps/src/microsoft_teams/apps/utils/graph.py Outdated
Comment thread packages/apps/src/microsoft_teams/apps/routing/activity_context.py
CloudEnvironment.graph_scope is typed as `str` (not Optional), so the
fallback is dead defense. Addresses Aamir review feedback.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@corinagum
corinagum merged commit a02e6b2 into main Apr 30, 2026
7 checks passed
@corinagum
corinagum deleted the cg/graph-cloud-baseurl branch April 30, 2026 20:42
corinagum added a commit that referenced this pull request May 27, 2026
## Summary

Brings `origin/main` into `release` for the **2.0.12** release. **No
carve-outs this time** — Quoted Replies (PR #321) is included.

`version.json`: `2.0.11` → `2.0.12`.

Aligns with teams.ts/teams.net cadence.

## What's in this release (delta from 2.0.11)

**Features**
- Quoted Replies & new quotes features (#321) — previously held back
- SuggestedActionSubmitActivity for `suggestedAction/submit` invoke
(#434)
- Default targeted replies for targeted inbound messages (#439)
- Reactions API marked GA (#427) — already shipped in 2.0.11 actually,
ignore if duplicate
- Prompt Preview support (#397)
- Sample: opt targeted-messages into slash commands (#430)
- Sample: a2a-in-teams (#401)
- Sample: proactive message update (#405)
- Allow custom HTTP client via `AppOptions` (#416)

**Security & fixes**
- Lock JsonWebToken trust-boundary contract (#432)
- Bump starlette 1.0.0 -> 1.1.0 for PYSEC-2026-161 / BadHost (#441)
- warn when bot starts without credentials (#435)
- fix(apps): support AAD v1 issuers in Entra token validation (#422)
- fix(apps): log inbound activities at info, warn on missing
Authorization (#425)
- fix(http-stream): wait for in-flight flush before sending final close
(#419)
- Mark reactions API as GA and fix sample remove flow (#427)
- Revert serviceUrl allowlist (ADO 5310460) (#415)
- Route `app.get_app_graph` + `ctx.*_graph` to sovereign endpoints via
`cloud.graph_scope` (#402)

**Deprecations / package changes**
- Remove ai, openai, mcpplugin, a2a, and devtools packages (#413)
- Restore and deprecate devtools package (#410)
- Deprecate ai, openai, mcpplugin, a2a packages (#406)
- Add agent framework example, remove chatprompt/mcp client samples
(#386)

**Dependency bumps**
- urllib3 2.6.3 → 2.7.0 (#426)
- python-multipart 0.0.26 → 0.0.27 (#424)
- microsoft-kiota-http 1.9.7 → 1.9.9 (#423)
- idna 3.11 → 3.15 (#431)
- starlette 1.0.0 → 1.1.0 (#441, security)
- /examples/tab/Web: qs, postcss, uuid, follow-redirects bumps

## Quoted Replies inclusion notes

- Teams client rendering is in-sync with the wire format as of
2026-05-06.
- APX QR rollout completed: Public 2026-04-10, GCCH/DoD/Gallatin
2026-04-14.
- Builder methods (`prepend_quote()`, `add_quote()`), `ctx.quote()`, and
the quote-aware `ctx.reply()` behavior are all present in this release.
- `examples/quoting` is included.

## Conflict resolution

The 2.0.11 release branch had the QR-removed shape for four files; took
`main`'s (QR-included) version for all of them:
- `examples/targeted-messages/src/main.py`
- `packages/api/src/microsoft_teams/api/activities/message/message.py`
- `packages/apps/src/microsoft_teams/apps/routing/activity_context.py`
- `packages/apps/tests/test_activity_context.py`

`version.json` conflict resolved to `2.0.12`.

## Test plan

- [x] `uv sync` clean
- [x] `poe check` (ruff format + lint) — clean
- [x] `poe test` — 609 passed
- [x] `pyright` — 0 errors, 0 warnings
- [ ] Pipeline build + test stages green on `release` after merge
- [ ] Publish pipeline run with **Public** → ESRP approval → PyPI
- [ ] `pip install microsoft-teams-apps==2.0.12` smoke install

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Aamir Jawaid <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Co-authored-by: Shanmathi Mayuram Krithivasan <[email protected]>
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.

5 participants