Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 11, 2025

Plan: Add OAuth Support for Regional Bots ✅ COMPLETE

This PR implements OAuth support for regional bots in Python, mirroring the TypeScript implementation.

Summary of Changes

API Layer (packages/api)

  • ApiClientSettings: New dataclass for OAuth endpoint configuration
    • Defaults to https://token.botframework.com
    • Supports regional endpoints (e.g., https://europe.token.botframework.com)
    • Reads from OAUTH_URL environment variable
  • BaseClient: Now handles api_client_settings for all subclasses
    • Added api_client_settings parameter to constructor
    • Calls merge_api_client_settings internally
    • All client subclasses inherit this functionality
  • Client updates: All API clients now inherit settings handling from BaseClient
  • Endpoint constants: Added for maintainability
  • Docstrings: Updated to "Optional API client settings." for consistency

Apps Layer (packages/apps)

  • AppOptions.default_connection_name: OAuth connection name (defaults to "graph")
  • AppOptions.api_client_settings: Top-level field for API client configuration
  • Removed OAuthSettings: Simplified API by keeping all config in AppOptions
  • Updated references: Changed from options.oauth.default_connection_name to options.default_connection_name

Example Usage

from microsoft.teams.api import ApiClientSettings
from microsoft.teams.apps import App

# Configure for Europe region
app = App(
    default_connection_name='graph',
    api_client_settings=ApiClientSettings(
        oauth_url="https://europe.token.botframework.com"
    )
)

Testing

  • All 109 API unit tests passing
  • Linting passed (ruff)
  • Type checking passed (pyright)

Latest Changes

  • ✅ Moved api_client_settings handling to BaseClient for inheritance
  • ✅ All client subclasses now pass settings to BaseClient constructor
  • ✅ Removed duplicate merge_api_client_settings calls from subclasses
  • ✅ Simplified imports by removing unused merge_api_client_settings imports
Original prompt

in the Python repository, apply similar changes to this Typescript PR [apps/api] feat: allow oauth for regional bots by lilyydu · Pull Request #386 · microsoft/teams.ts


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits November 11, 2025 18:31
Co-authored-by: lilyydu <54044854+lilyydu@users.noreply.github.com>
Co-authored-by: lilyydu <54044854+lilyydu@users.noreply.github.com>
Copilot AI changed the title [WIP] Apply OAuth functionality for regional bots in Python feat: add OAuth support for regional bots Nov 11, 2025
Copilot AI requested a review from lilyydu November 11, 2025 18:45
Copilot finished work on behalf of lilyydu November 11, 2025 18:45
@lilyydu
Copy link
Collaborator

lilyydu commented Nov 11, 2025

@copilot A series of updates were made here. Complete the same changes
microsoft/teams.ts#394

Co-authored-by: lilyydu <54044854+lilyydu@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 11, 2025

@copilot A series of updates were made here. Complete the same changes
microsoft/teams.ts#394

Completed the refactoring from PR #394. Changes applied in commit 9982511:

  • Removed client_settings from OAuthSettings
  • Added api_client_settings as a top-level field in AppOptions
  • Updated App and ActivityProcessor to use options.api_client_settings instead of options.oauth.client_settings
  • Updated documentation and examples

The API is now simpler with ApiClientSettings at the top level rather than nested in OAuthSettings.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • login.microsoftonline.com
    • Triggering command: /home/REDACTED/work/teams.py/teams.py/.venv/bin/python /home/REDACTED/work/teams.py/teams.py/.venv/bin/pytest packages -x -q --tb=short (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of lilyydu November 11, 2025 19:34
Co-authored-by: lilyydu <54044854+lilyydu@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 11, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • login.microsoftonline.com
    • Triggering command: /home/REDACTED/work/teams.py/teams.py/.venv/bin/python /home/REDACTED/work/teams.py/teams.py/.venv/bin/pytest packages -x -q --tb=short (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of lilyydu November 11, 2025 20:10
Copilot AI requested a review from lilyydu November 11, 2025 20:10
@lilyydu lilyydu marked this pull request as ready for review November 11, 2025 21:06
Copilot AI review requested due to automatic review settings November 11, 2025 21:06
Copilot finished reviewing on behalf of lilyydu November 11, 2025 21:09
Copy link
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

This PR implements configurable OAuth endpoints to support regional bot deployments in the Microsoft Teams SDK for Python, mirroring the functionality from teams.ts PRs #386 and #394. It enables bots deployed in specific regions (e.g., Europe, Asia) to use regional token endpoints instead of the global endpoint.

Key changes:

  • Introduces ApiClientSettings dataclass for OAuth endpoint configuration with environment variable support
  • Updates all API clients to accept and use configurable OAuth URLs
  • Adds api_client_settings field to AppOptions for easy configuration at the application level

Reviewed Changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/api/src/microsoft/teams/api/clients/api_client_settings.py New dataclass and utility function for OAuth endpoint configuration
packages/api/src/microsoft/teams/api/clients/init.py Exports new API client settings classes
packages/api/src/microsoft/teams/api/clients/api_client.py Accepts and propagates API client settings to all sub-clients
packages/api/src/microsoft/teams/api/clients/bot/client.py Passes settings to token and sign-in clients
packages/api/src/microsoft/teams/api/clients/bot/sign_in_client.py Uses configurable OAuth URL with endpoint constants
packages/api/src/microsoft/teams/api/clients/bot/token_client.py Accepts and stores API client settings
packages/api/src/microsoft/teams/api/clients/user/client.py Passes settings to token client
packages/api/src/microsoft/teams/api/clients/user/token_client.py Uses configurable OAuth URL with endpoint constants
packages/api/src/microsoft/teams/api/clients/conversation/client.py Propagates settings to activity and member clients
packages/api/src/microsoft/teams/api/clients/conversation/activity.py Accepts API client settings parameter
packages/api/src/microsoft/teams/api/clients/conversation/member.py Accepts API client settings parameter
packages/api/src/microsoft/teams/api/clients/team/client.py Accepts and stores API client settings
packages/api/src/microsoft/teams/api/clients/meeting/client.py Accepts and stores API client settings
packages/apps/src/microsoft/teams/apps/options.py Adds api_client_settings field to app options
packages/apps/src/microsoft/teams/apps/app.py Passes settings to API client and activity processor
packages/apps/src/microsoft/teams/apps/app_process.py Accepts and uses settings when building API clients
packages/apps/tests/test_app_process.py Updates test to pass None for new parameter
packages/api/tests/unit/test_user_client.py Adds 7 new tests for regional endpoint functionality
packages/api/tests/unit/test_bot_client.py Adds 2 new tests for bot regional endpoints
tests/graph/src/main.py Adds example usage in comments
tests/graph/README.md Adds regional bot configuration documentation
packages/mcpplugin/src/microsoft/teams/mcpplugin/server_plugin.py Formatting change to decorator

Co-authored-by: lilyydu <54044854+lilyydu@users.noreply.github.com>
Copilot AI requested a review from lilyydu November 14, 2025 00:18
Copilot finished work on behalf of lilyydu November 14, 2025 00:18
Co-authored-by: lilyydu <54044854+lilyydu@users.noreply.github.com>
Copilot finished work on behalf of lilyydu November 14, 2025 00:28
Copilot finished work on behalf of lilyydu November 14, 2025 00:31
@lilyydu lilyydu merged commit 3da24e5 into main Nov 14, 2025
7 checks passed
@lilyydu lilyydu deleted the copilot/feat-allow-oauth-for-regional-bots branch November 14, 2025 22:28
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.

3 participants