Skip to content

Refactoring Connections configuration - #642

Merged
Rodrigo Brandão (rodrigobr-msft) merged 17 commits into
mainfrom
users/robrandao/connection-config
Nov 4, 2026
Merged

Rodrigo Brandão (rodrigobr-msft) merged 17 commits into
mainfrom
users/robrandao/connection-config

Conversation

@rodrigobr-msft

@rodrigobr-msft Rodrigo Brandão (rodrigobr-msft) commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Refactor connection and authentication configuration around a shared Configuration instance, reducing dictionary unpacking and separating provider-specific settings from legacy authentication configuration.

Changes

  • Add Configuration-based initialization to connection managers and authorization.
  • Introduce MsalConnectionSettings and migrate Sidecar settings to the shared ConnectionSettingsBase.
  • Consolidate shared connection APIs under authorization.connections.
  • Support typed audience/service-URL routing maps using lists or named mappings.
  • Update environment loading to return Configuration, accept defaults, and preserve custom sections.
  • Preserve issuer and audience settings during legacy conversion, normalize scope inputs, and improve configuration logging/redaction.
  • Use application-scoped JWT validator caching in FastAPI.
  • Migrate samples to pass configuration directly through authentication and hosting, using typed getters instead of raw dictionary access.
  • Expand regression coverage and narrowly filter expected legacy deprecation warnings while retaining warnings-as-errors.

Compatibility and migration

  • Retain deprecated AgentAuthConfiguration inputs, legacy connection-manager constructor inputs, and existing public import paths.
  • Prefer config=configuration and provider .config over deprecated configuration accessors.
  • Environment loading no longer synthesizes missing standard sections.

Validation

  • 60 targeted sample, middleware, and OTel sampler tests passed.
  • Syntax validation passed for all 59 changed sample modules.
  • No new flake8 diagnostics compared with the baseline.
  • Live authentication and external services were not exercised.

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

Directly constructing SidecarConnectionSettings with the string "false" can disable network restrictions and allow public hosts, while legacy API compatibility and configuration-validation regressions also remain unresolved.

6 open issues
What changed in this PR

This PR refactors connection configuration across the Microsoft 365 Agents SDK for Python, introducing typed provider settings and shared configuration binding for authentication, routing, and samples.

Changes:

  • Consolidates connection APIs under authorization.connections and adds typed MSAL and Entra sidecar settings.
  • Updates environment loading, OAuth configuration binding, and FastAPI validator caching.
  • Migrates samples and expands tests for configuration aliases, routing, credential redaction, and legacy compatibility.
File Description
tests/​hosting_fastapi/​test_jwt_authorization_middleware.py Verifies application-scoped validator caching.
tests/​hosting_core/​test_rest_channel_service_client_factory.py Uses typed settings in agentic routing tests.
tests/​hosting_core/​test_log_config.py Tests configuration binding and credential redaction.
tests/​hosting_core/​test_connection_settings_base.py Updates shared settings binding tests.
tests/​hosting_core/​test_connection_manager.py Covers modern configuration and legacy compatibility.
tests/​hosting_core/​authorization/​test_token_validation_configuration.py Updates scope and validation expectations.
tests/​hosting_core/​authorization/​test_jwt_connection_settings.py Tests legacy issuer preservation.
tests/​hosting_core/​authorization/​test_connections_map.py Adds routing-map binding tests.
tests/​hosting_core/​app/​_oauth/​test_auth_handler.py Tests indexed environment scopes.
tests/​copilotstudio_client/​test_console_sample.py Constructs sample settings through Configuration.
tests/​authentication_msal/​test_msal_connection_manager.py Uses the compatibility configuration property.
tests/​authentication_msal/​test_msal_auth.py Uses typed settings in helper tests.
tests/​authentication_msal/​test_connection_settings.py Adds typed MSAL settings coverage.
tests/​authentication_entra_auth_sidecar/​test_sidecar_auth.py Tests bound settings and credential reuse.
tests/​authentication_entra_auth_sidecar/​test_settings.py Updates binding and scalar-validation tests.
tests/​activity/​config/​test_load_configuration.py Tests defaults and custom-section preservation.
tests/​activity/​config/​test_configuration.py Tests comma-separated scope normalization.
test_samples/​tethered-agent/​src/​start_server.py Accepts shared configuration for hosting.
test_samples/​tethered-agent/​src/​main.py Passes shared configuration to startup.
test_samples/​tethered-agent/​src/​agent.py Migrates connection and authorization setup.
test_samples/​testing/​src/​start_server.py Reads hosting settings from Configuration.
test_samples/​testing/​src/​app.py Passes configuration to manager and application.
test_samples/​teams_extension/​task_modules_agent.py Migrates authentication and URL settings.
test_samples/​teams_extension/​shared/​start_server.py Uses Configuration for authentication and hosting.
test_samples/​teams_extension/​message_extensions_agent.py Migrates connection and authorization setup.
test_samples/​teams_extension/​meeting_events_agent.py Migrates connection and authorization setup.
test_samples/​proactive/​proactive_agent.py Uses shared authentication and hosting configuration.
test_samples/​otel/​zero-code/​src/​start_server.py Accepts shared hosting configuration.
test_samples/​otel/​zero-code/​src/​main.py Passes shared configuration to startup.
test_samples/​otel/​zero-code/​src/​agent.py Migrates connection and authorization setup.
test_samples/​otel/​quickstart/​src/​start_server.py Accepts shared hosting configuration.
test_samples/​otel/​quickstart/​src/​main.py Passes shared configuration to startup.
test_samples/​otel/​quickstart/​src/​agent.py Migrates connection and authorization setup.
test_samples/​hosting_msteams/​task-modules/​src/​start_server.py Uses shared authentication and port settings.
test_samples/​hosting_msteams/​task-modules/​src/​main.py Passes shared configuration to startup.
test_samples/​hosting_msteams/​task-modules/​src/​agent.py Migrates authentication and dialog URL settings.
test_samples/​hosting_msteams/​message-extensions/​src/​start_server.py Uses shared authentication and port settings.
test_samples/​hosting_msteams/​message-extensions/​src/​main.py Passes shared configuration to startup.
test_samples/​hosting_msteams/​message-extensions/​src/​agent.py Migrates authentication and settings URL binding.
test_samples/​hosting_msteams/​graph-clients/​src/​start_server.py Uses shared authentication and port settings.
test_samples/​hosting_msteams/​graph-clients/​src/​main.py Passes shared configuration to startup.
test_samples/​hosting_msteams/​graph-clients/​src/​agent.py Migrates connection and authorization setup.
test_samples/​hosting_msteams/​conversation-agent/​src/​start_server.py Uses shared authentication and port settings.
test_samples/​hosting_msteams/​conversation-agent/​src/​main.py Passes shared configuration to startup.
test_samples/​hosting_msteams/​conversation-agent/​src/​agent.py Migrates connection and authorization setup.
test_samples/​handling_attachments/​src/​main.py Supplies Configuration to FastAPI authentication.
test_samples/​handling_attachments/​src/​agent.py Migrates connection and authorization setup.
test_samples/​fastapi/​empty_agent.py Uses shared authentication and port configuration.
test_samples/​fastapi/​authorization_agent.py Uses shared authentication and port configuration.
test_samples/​extensions/​slack-agent/​src/​start_server.py Accepts shared hosting configuration.
test_samples/​extensions/​slack-agent/​src/​main.py Passes shared configuration to startup.
test_samples/​extensions/​slack-agent/​src/​app.py Migrates connection and authorization setup.
test_samples/​extensions/​extension-starter/​src/​sample/​start_server.py Accepts shared hosting configuration.
test_samples/​extensions/​extension-starter/​src/​sample/​main.py Passes shared configuration to startup.
test_samples/​extensions/​extension-starter/​src/​sample/​app.py Migrates connection and authorization setup.
test_samples/​entra_sidecar/​agent.py Uses Configuration for sidecar authentication and hosting.
test_samples/​copilot_studio_connector/​app.py Migrates authentication and hosting configuration.
test_samples/​copilot_studio_client_sample/​config.py Binds client settings through Configuration.
test_samples/​copilot_studio_client_sample/​app.py Loads and passes shared client configuration.
test_samples/​compat/​teams_agent/​app.py Migrates connection setup and middleware configuration.
test_samples/​compat/​dialogs/​user_auth/​src/​main.py Migrates manager and middleware configuration.
test_samples/​compat/​dialogs/​oauth_prompt/​src/​main.py Migrates manager and middleware configuration.
test_samples/​compat/​dialogs/​multi_turn/​src/​main.py Uses explicit manager configuration.
test_samples/​compat/​dialogs/​custom_dialogs/​src/​main.py Uses explicit manager configuration.
test_samples/​compat/​dialogs/​complex_dialog/​src/​main.py Uses explicit manager configuration.
test_samples/​cards/​start_server.py Accepts shared hosting configuration.
test_samples/​cards/​agent.py Migrates authentication setup and startup configuration.
test_samples/​app_style/​streaming_agent.py Migrates authentication setup and startup configuration.
test_samples/​app_style/​shared/​start_server.py Accepts shared hosting configuration.
test_samples/​app_style/​mcs_agent.py Binds Copilot Studio settings through Configuration.
test_samples/​app_style/​empty_agent.py Migrates authentication setup and startup configuration.
test_samples/​app_style/​echo_proactive_agent.py Uses shared authentication and hosting configuration.
test_samples/​app_style/​authorization_agent.py Migrates authentication setup and startup configuration.
test_samples/​agentic-test/​src/​start_server.py Accepts shared hosting configuration.
test_samples/​agentic-test/​src/​main.py Passes shared configuration to startup.
test_samples/​agentic-test/​src/​agent.py Migrates connection and authorization setup.
pytest.ini Filters legacy authentication deprecation warnings.
libraries/​microsoft-agents-hosting-fastapi/​microsoft_agents/​hosting/​fastapi/​jwt_authorization_middleware.py Supplies the application as validator cache key.
libraries/​microsoft-agents-hosting-core/​readme.md Documents connection configuration APIs.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​rest_channel_service_client_factory.py Reads alternate blueprint from typed settings.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​authorization/​jwt/​token_validation_configuration.py Updates connection binding for JWT policy.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​authorization/​jwt/​jwt_token_validator.py Uses relocated legacy configuration and conversion helpers.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​authorization/​jwt/​jwt_connection_settings.py Imports the relocated shared settings base.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​authorization/​jwt/​_authorize_request.py Updates the legacy configuration import.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​authorization/​connections/​connections.py Relocates the connection protocol.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​authorization/​connections/​connections_map.py Adds typed routing-map entries.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​authorization/​connections/​connection_settings_base.py Centralizes shared settings binding and extras.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​authorization/​connections/​connection_manager.py Adds Configuration-based provider construction and routing.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​authorization/​connections/​agent_auth_configuration.py Adds legacy conversion helpers and deprecation warnings.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​authorization/​connections/​__init__.py Exports consolidated connection APIs.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​authorization/​connection_settings_base.py Removes the former settings implementation.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​authorization/​connection_manager.py Forwards the legacy manager import.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​authorization/​anonymous_token_provider.py Exposes typed anonymous-provider settings.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​authorization/​access_token_provider_base.py Adds typed config access with legacy fallback.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​authorization/​_log_config.py Logs redacted Configuration-based settings.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​authorization/​_helpers.py Adds an Any typing import.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​authorization/​_entra_issuers.py Clarifies issuer-helper documentation.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​authorization/​__init__.py Exports reorganized connection APIs.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​app/​oauth/​authorization.py Binds OAuth handlers and flags from Configuration.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​app/​oauth/​auth_handler.py Accepts list-based scopes.
libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​__init__.py Exposes shared connection settings publicly.
libraries/​microsoft-agents-authentication-msal/​readme.md Documents typed MSAL configuration.
libraries/​microsoft-agents-authentication-msal/​microsoft_agents/​authentication/​msal/​msal_token_credential.py Accepts typed MSAL settings.
libraries/​microsoft-agents-authentication-msal/​microsoft_agents/​authentication/​msal/​msal_connection_manager.py Adds an explicit Configuration parameter.
libraries/​microsoft-agents-authentication-msal/​microsoft_agents/​authentication/​msal/​msal_auth.py Uses typed settings with legacy conversion.
libraries/​microsoft-agents-authentication-msal/​microsoft_agents/​authentication/​msal/​connection_settings.py Defines typed MSAL settings and validation.
libraries/​microsoft-agents-authentication-msal/​microsoft_agents/​authentication/​msal/​__init__.py Exports MsalConnectionSettings.
libraries/​microsoft-agents-authentication-entra-auth-sidecar/​readme.md Documents typed sidecar configuration.
libraries/​microsoft-agents-authentication-entra-auth-sidecar/​microsoft_agents/​authentication/​entra_auth_sidecar/​sidecar_token_credential.py Accepts typed and raw configuration inputs.
libraries/​microsoft-agents-authentication-entra-auth-sidecar/​microsoft_agents/​authentication/​entra_auth_sidecar/​sidecar_http_client.py Imports relocated sidecar constants.
libraries/​microsoft-agents-authentication-entra-auth-sidecar/​microsoft_agents/​authentication/​entra_auth_sidecar/​sidecar_auth.py Accepts typed settings and exposes config.
libraries/​microsoft-agents-authentication-entra-auth-sidecar/​microsoft_agents/​authentication/​entra_auth_sidecar/​constants.py Centralizes sidecar defaults.
libraries/​microsoft-agents-authentication-entra-auth-sidecar/​microsoft_agents/​authentication/​entra_auth_sidecar/​connection_settings.py Adds shared Configuration-based sidecar binding.
libraries/​microsoft-agents-authentication-entra-auth-sidecar/​microsoft_agents/​authentication/​entra_auth_sidecar/​_models.py Removes relocated settings and constants.
libraries/​microsoft-agents-authentication-entra-auth-sidecar/​microsoft_agents/​authentication/​entra_auth_sidecar/​__init__.py Exports the relocated settings class.
libraries/​microsoft-agents-activity/​microsoft_agents/​activity/​config/​configuration.py Adds section metadata and comma-separated scopes.
libraries/​microsoft-agents-activity/​microsoft_agents/​activity/​config/​_load_configuration.py Returns Configuration with defaults and preserved sections.
changelog.md Records connection and provider-settings changes.

Review effort: Balanced

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

String-valued sidecar flags such as "false" now bypass public-host restrictions, while unresolved compatibility regressions break existing configuration and authentication calls.

2 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Handle null or empty handler configuration before iteration

libraries/​microsoft-agents-hosting-core/​microsoft_agents/​hosting/​core/​app/​oauth/​authorization.py:112

The previous lookup used or {}, so an explicit HANDLERS: None or an empty AGENTAPPLICATION__USERAUTHORIZATION__HANDLERS environment value meant no configured handlers. Configuration.get() only applies its default to missing keys, so these existing inputs now reach .items() as None or an empty string and crash Authorization construction. Restore the empty/unset fallback before iterating.

6 resolved since last review

Review effort: Balanced

@rodrigobr-msft
Rodrigo Brandão (rodrigobr-msft) merged commit cd68482 into main Nov 4, 2026
10 checks passed
@rodrigobr-msft
Rodrigo Brandão (rodrigobr-msft) deleted the users/robrandao/connection-config branch November 4, 2026 22:02
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.

Revamp internal configuration representation in Python

3 participants