Repository navigation
Refactoring Connections configuration #642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Rodrigo Brandão (rodrigobr-msft)
merged 17 commits into
main
from
users/robrandao/connection-config
Nov 4, 2026
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6aa0caf
Caching of TokenValidator for jwt middleware
rodrigobr-msft 4b69f23
Merge branch 'main' of https://github.com/microsoft/Agents-for-python…
rodrigobr-msft 15db5ba
Porting jwt config changes
rodrigobr-msft 21aaf64
Improving tests
rodrigobr-msft 8a2fe39
Formatting
rodrigobr-msft 02cae35
Small test fix
rodrigobr-msft 1d061d2
Addressing PR feedback
rodrigobr-msft 4956a99
Changelog
rodrigobr-msft 1a6d053
Addressing PR feedback
rodrigobr-msft f11b0b6
Connection configuraiton overhault
rodrigobr-msft f1b28e1
Updating changelog
rodrigobr-msft d50e142
Addressing PR feedback
rodrigobr-msft 704de28
Addressing PR feedback and updating configuration handling in test sa…
rodrigobr-msft 5a729d3
Updating samples
rodrigobr-msft 3d8100f
Fixing tests issue
rodrigobr-msft a8a3ad6
Another commit
rodrigobr-msft 7371257
Addressing PR feedback
rodrigobr-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
116 changes: 116 additions & 0 deletions
116
...ra-auth-sidecar/microsoft_agents/authentication/entra_auth_sidecar/connection_settings.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Mapping | ||
| from dataclasses import dataclass | ||
| from typing_extensions import Self | ||
|
|
||
| from microsoft_agents.activity.config import ( | ||
| Configuration, | ||
| coerce_bool, | ||
| xpath, | ||
| ) | ||
| from microsoft_agents.hosting.core.authorization.connections import ( | ||
| AgentAuthConfiguration, | ||
| ConnectionSettingsBase, | ||
| ) | ||
| from .constants import ( | ||
| DEFAULT_SERVICE_NAME, | ||
| DEFAULT_BLUEPRINT_SERVICE_NAME, | ||
| DEFAULT_SIDECAR_BASE_URL, | ||
| DEFAULT_REQUEST_TIMEOUT_SECONDS, | ||
| DEFAULT_RETRY_COUNT, | ||
| ) | ||
|
|
||
|
|
||
| def _or_default(s: str | None, default: str) -> str: | ||
| return (s.strip() if s else None) or default | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class SidecarConnectionSettings(ConnectionSettingsBase): | ||
| """ | ||
| Connection settings for the sidecar-based token provider. | ||
|
|
||
| Extends | ||
| :class:`microsoft_agents.hosting.core.authorization.connection_settings_base._ConnectionSettingsBase` | ||
| with the sidecar-specific fields, mirroring the .NET | ||
| ``Microsoft.Agents.Authentication.EntraAuthSidecar.SidecarConnectionSettings`` | ||
| which derives from ``_ConnectionSettingsBase``. Bound from an | ||
| :class:`microsoft_agents.hosting.core.AgentAuthConfiguration` (or its raw | ||
| ``SETTINGS`` keyword arguments). No secrets/certificates are required: the | ||
| sidecar owns all credential management. | ||
| """ | ||
|
|
||
| service_name: str | None = DEFAULT_SERVICE_NAME | ||
| blueprint_service_name: str | None = DEFAULT_BLUEPRINT_SERVICE_NAME | ||
| sidecar_base_url: str | None = None | ||
| bypass_local_network_restriction: bool = False | ||
| request_timeout: float = DEFAULT_REQUEST_TIMEOUT_SECONDS | ||
| retry_count: int = DEFAULT_RETRY_COUNT | ||
|
|
||
| def __post_init__(self) -> None: | ||
| object.__setattr__( | ||
| self, | ||
| "bypass_local_network_restriction", | ||
| coerce_bool(self.bypass_local_network_restriction), | ||
| ) | ||
|
|
||
| @classmethod | ||
| def _get_init_kwargs(cls, config: Configuration) -> dict: | ||
| base = super()._get_init_kwargs(config) | ||
|
|
||
| # An explicitly blank or whitespace-only value (e.g. binding yields "" or | ||
| # " ") must never produce an invalid sidecar endpoint path, so strip and | ||
| # normalize to the defaults here. | ||
| _service_name = config.get_strn(xpath("service_name")) | ||
| service_name = _or_default(_service_name, DEFAULT_SERVICE_NAME) | ||
|
|
||
| blueprint_service_name = config.get_str( | ||
| xpath("blueprint_service_name"), default=DEFAULT_BLUEPRINT_SERVICE_NAME | ||
| ) | ||
| blueprint_service_name = _or_default( | ||
| blueprint_service_name, DEFAULT_BLUEPRINT_SERVICE_NAME | ||
| ) | ||
|
|
||
| sidecar_base_url = config.get_strn(xpath("sidecar_base_url")) | ||
|
|
||
| # Config values can arrive as strings from ``load_configuration_from_env``, | ||
| # so coerce explicitly: ``bool("false")`` would otherwise be ``True`` and | ||
| # silently disable the SSRF guard, and ``max(0, "5")`` would raise. | ||
| bypass_local_network_restriction = config.get_bool( | ||
| xpath("bypass_local_network_restriction"), | ||
| default=False, | ||
| ) | ||
| request_timeout = config.get_float( | ||
| xpath("request_timeout"), | ||
| default=DEFAULT_REQUEST_TIMEOUT_SECONDS, | ||
| ) | ||
| retry_count = config.get_int( | ||
| xpath("retry_count"), | ||
| default=DEFAULT_RETRY_COUNT, | ||
| ) | ||
|
|
||
| base.update( | ||
| { | ||
| "service_name": service_name, | ||
| "blueprint_service_name": blueprint_service_name, | ||
| "sidecar_base_url": sidecar_base_url, | ||
| "bypass_local_network_restriction": bypass_local_network_restriction, | ||
| "request_timeout": request_timeout, | ||
| "retry_count": retry_count, | ||
| } | ||
| ) | ||
| return base | ||
|
|
||
| @classmethod | ||
| def from_configuration( | ||
| cls, config: Configuration | Mapping | AgentAuthConfiguration | Self | ||
| ) -> Self: | ||
| if isinstance(config, AgentAuthConfiguration): | ||
| return cls._from_agent_auth_config(config) | ||
| if isinstance(config, Mapping): | ||
| config = Configuration.from_mapping(config) | ||
| return super().from_configuration(config) |
8 changes: 8 additions & 0 deletions
8
...cation-entra-auth-sidecar/microsoft_agents/authentication/entra_auth_sidecar/constants.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| DEFAULT_SERVICE_NAME = "default" | ||
| DEFAULT_BLUEPRINT_SERVICE_NAME = "agenticblueprint" | ||
| DEFAULT_SIDECAR_BASE_URL = "http://localhost:5178" | ||
| DEFAULT_REQUEST_TIMEOUT_SECONDS = 30.0 | ||
| DEFAULT_RETRY_COUNT = 3 |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.