Skip to content

refactor(apps): add transport seam at HttpServerAdapter layer - #590

Open
Lily Du (lilyydu) wants to merge 3 commits into
mainfrom
lilyydu/port-pr-720
Open

refactor(apps): add transport seam at HttpServerAdapter layer#590
Lily Du (lilyydu) wants to merge 3 commits into
mainfrom
lilyydu/port-pr-720

Conversation

@lilyydu

@lilyydu Lily Du (lilyydu) commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Port of microsoft/teams.ts#720.

Adds a transport-agnostic inbound seam so non-HTTP transports (e.g. a future Socket Mode adapter) can plug into HttpServer.

  • HttpRequest.token: transports that authenticate at the connection level (e.g. Socket Mode) can deliver a pre-resolved token; HttpServer trusts it and skips per-request JWT validation. HTTP adapters never set it, so HTTP behavior is unchanged.
  • HttpServerInitializeDeps + optional adapter.initialize(deps) hook: HttpServer.initialize() forwards credentials/cloud to the adapter via getattr(), so it isn't a required Protocol member (avoids breaking existing/external adapters that don't implement it.
  • Kept HttpServer.initialize() sync (TS's is async) since the actual Socket Mode adapter.initialize() does no awaiting.

Pure refactor: no behavior change for existing HTTP adapters.

Port of microsoft/teams.ts#720. Adds a transport-agnostic inbound seam so
non-HTTP transports (e.g. a future Socket Mode adapter) can plug into
HttpServer.

- HttpRequest.token: transports that authenticate at the connection level
  (e.g. Socket Mode) can deliver a pre-resolved token; HttpServer trusts it
  and skips per-request JWT validation. HTTP adapters never set it, so HTTP
  behavior is unchanged.
- HttpServerInitializeDeps + optional adapter.initialize(deps) hook:
  HttpServer.initialize() forwards credentials/cloud to the adapter via
  getattr(), so it isn't a required Protocol member (avoids breaking
  existing/external adapters that don't implement it.
- Kept HttpServer.initialize() sync (TS's is async) since the actual
  Socket Mode adapter.initialize() does no awaiting.

Pure refactor: no behavior change for existing HTTP adapters.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
EOF
)
@lilyydu
Lily Du (lilyydu) marked this pull request as ready for review September 8, 2026 22:36
Copilot AI lite review requested due to automatic review settings September 8, 2026 22: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.

🟡 Changes recommended

The new pre-authenticated token bypass currently lacks basic runtime validation/expiry handling and the adapter initialize() contract documentation does not match actual synchronous invocation behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds a transport-agnostic inbound seam at the HttpServerAdapter boundary so future non-HTTP transports (e.g., Socket Mode) can integrate with HttpServer without changing existing HTTP adapter behavior.

Changes:

  • Introduces HttpServerInitializeDeps and forwards app-level deps (credentials, cloud) to an optional adapter initialize(...) hook.
  • Extends HttpRequest with an optional pre-authenticated token that bypasses per-request JWT validation.
  • Adds/updates unit tests covering adapter dep forwarding and the pre-authenticated token bypass.
File summaries
File Description
packages/apps/src/microsoft_teams/apps/http/http_server.py Forwards init deps to adapter hook; adds request["token"] pre-auth seam in handle_request().
packages/apps/src/microsoft_teams/apps/http/adapter.py Adds HttpServerInitializeDeps; extends HttpRequest with optional token; updates adapter protocol docs.
packages/apps/src/microsoft_teams/apps/http/init.py Re-exports HttpServerInitializeDeps.
packages/apps/src/microsoft_teams/apps/init.py Re-exports HttpServerInitializeDeps at the microsoft_teams.apps package level.
packages/apps/tests/test_http_server.py Adds tests for dep forwarding and pre-auth token bypass.
Review details

Suppressed comments (1)

packages/apps/tests/test_http_server.py:296

  • The pre-authenticated token stub in this test is missing several TokenProtocol attributes (e.g., app_display_name, tenant_id, expiration). If HttpServer adds a TokenProtocol runtime check (recommended), this test will fail and the stub won't reflect the actual contract adapters must provide.
        pre_authenticated_token = SimpleNamespace(
            app_id="socket-app",
            from_="azure",
            from_id="",
            service_url="https://smba.trafficmanager.net/teams",
  • Files reviewed: 5/5 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +140 to +146
pre_authenticated_token = request.get("token")
if pre_authenticated_token is not None:
# A transport that authenticates at the connection level (e.g. Socket
# Mode) already resolved the caller's identity; trust it and skip the
# per-request JWT validation below.
token: TokenProtocol = pre_authenticated_token
elif self._dangerously_allow_unauthenticated_requests:
Comment thread packages/apps/src/microsoft_teams/apps/http/adapter.py Outdated
Comment thread packages/apps/tests/test_http_server.py
Lily Du (lilyydu) and others added 2 commits September 8, 2026 16:00
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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