feat: add multi-connection OAuth registry and flow APIs - #561
Merged
Conversation
Lily Du (lilyydu)
force-pushed
the
lilyydu/03-oauth-registry
branch
from
August 13, 2026 21:07
d6c9e38 to
7f73326
Compare
Lily Du (lilyydu)
force-pushed
the
lilyydu/03-oauth-registry
branch
from
August 13, 2026 21:23
7f73326 to
3cb3dac
Compare
Lily Du (lilyydu)
force-pushed
the
lilyydu/03-oauth-registry
branch
from
August 24, 2026 21:53
3cb3dac to
21647b6
Compare
Lily Du (lilyydu)
marked this pull request as ready for review
August 24, 2026 21:59
Contributor
There was a problem hiding this comment.
Pull request overview
Adds first-class multi-connection OAuth support to the Teams Python SDK by introducing a named OAuth flow registry and connection-bound OAuth helpers/events, while keeping the existing default-connection behavior intact.
Changes:
- Added
OAuthFlowand a case-insensitive, insertion-orderedOAuthFlowRegistry, plusApp.add_oauth_flow(...)/App.get_oauth_flow(...). - Added connection-bound
ActivityContextOAuth helpers:sign_out(connection_name=...),get_user_token(connection_name=...), andget_token_status(). - Added a structured
SignInFailureEventand wired it into the existing sign-in failure handling (while preserving the legacyErrorEvent).
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/apps/tests/test_oauth_flow.py | Adds coverage for OAuthFlow handler registration, flow operations, registry behavior, and App integration. |
| packages/apps/tests/test_app_oauth.py | Updates tests to assert both legacy error emission and new sign_in_failure event emission. |
| packages/apps/tests/test_activity_context.py | Adds tests for per-connection token helpers, 404 vs non-404 behavior, and token status retrieval. |
| packages/apps/src/microsoft_teams/apps/routing/activity_context.py | Implements per-connection sign_out, get_user_token, and get_token_status on the turn context. |
| packages/apps/src/microsoft_teams/apps/routing/init.py | Re-exports SignInOptions for external flow APIs/tests. |
| packages/apps/src/microsoft_teams/apps/oauth_flow.py | Introduces OAuthFlow and OAuthFlowRegistry types and flow-level operations/handlers. |
| packages/apps/src/microsoft_teams/apps/events/types.py | Adds SignInFailureEvent dataclass to the event type set. |
| packages/apps/src/microsoft_teams/apps/events/registry.py | Registers sign_in_failure as a core event type and maps it to SignInFailureEvent. |
| packages/apps/src/microsoft_teams/apps/events/init.py | Exports SignInFailureEvent from the events package. |
| packages/apps/src/microsoft_teams/apps/app.py | Adds an internal OAuth flow registry and public App-level add/get flow APIs. |
| packages/apps/src/microsoft_teams/apps/app_oauth.py | Emits the new sign_in_failure structured event alongside the existing error event on failure. |
| packages/apps/src/microsoft_teams/apps/init.py | Exposes OAuthFlow and OAuthFlowRegistry from microsoft_teams.apps. |
| packages/api/src/microsoft_teams/api/clients/user/params.py | Makes include_filter optional so token status can be requested for all connections in one call. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Corina (corinagum)
approved these changes
Aug 25, 2026
Corina (corinagum)
left a comment
Contributor
There was a problem hiding this comment.
app_oauth.py:64-69 says "Token verification will likely fail" With registered non-default connections now being supported, SSO will send a false alarm. Maybe update to check whether a flow is registered for that connection?
Lily Du (lilyydu)
force-pushed
the
lilyydu/03-oauth-registry
branch
2 times, most recently
from
August 25, 2026 18:40
7d2f225 to
88844f0
Compare
Co-authored-by: Lily Du <lilyyduu@gmail.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Lily Du (lilyydu)
force-pushed
the
lilyydu/03-oauth-registry
branch
from
August 25, 2026 21:25
ef6796f to
ef363be
Compare
Corina (corinagum)
approved these changes
Aug 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds the public registry and flow APIs for using multiple named OAuth connections in
teams.py.It is stacked on #554 and is intentionally limited to the registration and connection-bound API layer. Callback routing, pending sign-in attribution, and state-backed deduplication are deferred to follow-up PRs.
The API follows the C# SDK's
OAuthFlow/AddOAuthFlow(...)model while remaining additive and backward-compatible with the existing app-level default OAuth connection.What changed
Register named OAuth flows
Added
OAuthFlowand a case-insensitive, insertion-orderedOAuthFlowRegistry.App.add_oauth_flow(...)registers and returns anOAuthFlow.App.get_oauth_flow(...)retrieves a registered flow case-insensitively.ValueErrorcase-insensitively.ValueErrorwith the registered connection names.OAuthFlowandOAuthFlowRegistryare exported frommicrosoft_teams.apps.Add connection-bound flow operations
Each
OAuthFlowdelegates OAuth operations to its own connection:OAuthFlow.sign_in(...)preserves caller-provided card text and button text but always forces the flow's connection name, preventing options for one connection from being used through another flow.Flows also expose
on_signin(...)andon_signin_failure(...)handler registration. Invocation of those per-flow handlers will be wired by the callback-routing layer in a follow-up PR.Add per-connection
ActivityContexthelpersctx.sign_out(connection_name=...)signs out a specific connection.ctx.get_user_token(connection_name=...)retrieves the token for a specific connection.connection_namepreserves the existing default-connection behavior.get_user_token(...)returnsNoneonly when Token Service returns404.ctx.get_token_status()makes one request and returns status for all bot OAuth connections.Add a structured sign-in failure event
Added
SignInFailureEvent, containing:The existing OAuth failure handler emits both the existing
ErrorEventfor backward compatibility and the newsign_in_failureevent for structured handling.Backward compatibility
Existing single-connection OAuth APIs continue to use the app-level default connection when no connection name is provided. Registering flows is optional, so existing applications do not need to change.
Deferred to follow-up PRs
This PR does not yet: