microsoft-agents-authentication-msal 1.2.0.dev20__tar.gz → 1.4.0.dev10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {microsoft_agents_authentication_msal-1.2.0.dev20 → microsoft_agents_authentication_msal-1.4.0.dev10}/PKG-INFO +33 -3
- microsoft_agents_authentication_msal-1.4.0.dev10/VERSION.txt +1 -0
- {microsoft_agents_authentication_msal-1.2.0.dev20 → microsoft_agents_authentication_msal-1.4.0.dev10}/microsoft_agents/authentication/msal/msal_auth.py +22 -0
- microsoft_agents_authentication_msal-1.4.0.dev10/microsoft_agents/authentication/msal/msal_connection_manager.py +43 -0
- {microsoft_agents_authentication_msal-1.2.0.dev20 → microsoft_agents_authentication_msal-1.4.0.dev10}/microsoft_agents_authentication_msal.egg-info/PKG-INFO +33 -3
- microsoft_agents_authentication_msal-1.4.0.dev10/microsoft_agents_authentication_msal.egg-info/requires.txt +3 -0
- {microsoft_agents_authentication_msal-1.2.0.dev20 → microsoft_agents_authentication_msal-1.4.0.dev10}/readme.md +31 -1
- microsoft_agents_authentication_msal-1.2.0.dev20/VERSION.txt +0 -1
- microsoft_agents_authentication_msal-1.2.0.dev20/microsoft_agents/authentication/msal/msal_connection_manager.py +0 -160
- microsoft_agents_authentication_msal-1.2.0.dev20/microsoft_agents_authentication_msal.egg-info/requires.txt +0 -3
- {microsoft_agents_authentication_msal-1.2.0.dev20 → microsoft_agents_authentication_msal-1.4.0.dev10}/LICENSE +0 -0
- {microsoft_agents_authentication_msal-1.2.0.dev20 → microsoft_agents_authentication_msal-1.4.0.dev10}/MANIFEST.in +0 -0
- {microsoft_agents_authentication_msal-1.2.0.dev20 → microsoft_agents_authentication_msal-1.4.0.dev10}/microsoft_agents/authentication/msal/__init__.py +0 -0
- {microsoft_agents_authentication_msal-1.2.0.dev20 → microsoft_agents_authentication_msal-1.4.0.dev10}/microsoft_agents/authentication/msal/errors/__init__.py +0 -0
- {microsoft_agents_authentication_msal-1.2.0.dev20 → microsoft_agents_authentication_msal-1.4.0.dev10}/microsoft_agents/authentication/msal/errors/error_resources.py +0 -0
- {microsoft_agents_authentication_msal-1.2.0.dev20 → microsoft_agents_authentication_msal-1.4.0.dev10}/microsoft_agents_authentication_msal.egg-info/SOURCES.txt +0 -0
- {microsoft_agents_authentication_msal-1.2.0.dev20 → microsoft_agents_authentication_msal-1.4.0.dev10}/microsoft_agents_authentication_msal.egg-info/dependency_links.txt +0 -0
- {microsoft_agents_authentication_msal-1.2.0.dev20 → microsoft_agents_authentication_msal-1.4.0.dev10}/microsoft_agents_authentication_msal.egg-info/top_level.txt +0 -0
- {microsoft_agents_authentication_msal-1.2.0.dev20 → microsoft_agents_authentication_msal-1.4.0.dev10}/pyproject.toml +0 -0
- {microsoft_agents_authentication_msal-1.2.0.dev20 → microsoft_agents_authentication_msal-1.4.0.dev10}/setup.cfg +0 -0
- {microsoft_agents_authentication_msal-1.2.0.dev20 → microsoft_agents_authentication_msal-1.4.0.dev10}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: microsoft-agents-authentication-msal
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.4.0.dev10
|
|
4
4
|
Summary: A msal-based authentication library for Microsoft Agents
|
|
5
5
|
Author: Microsoft Corporation
|
|
6
6
|
License-Expression: MIT
|
|
@@ -15,7 +15,7 @@ Classifier: Operating System :: OS Independent
|
|
|
15
15
|
Requires-Python: >=3.10
|
|
16
16
|
Description-Content-Type: text/markdown
|
|
17
17
|
License-File: LICENSE
|
|
18
|
-
Requires-Dist: microsoft-agents-hosting-core==1.
|
|
18
|
+
Requires-Dist: microsoft-agents-hosting-core==1.4.0.dev10
|
|
19
19
|
Requires-Dist: msal>=1.34.0
|
|
20
20
|
Requires-Dist: requests>=2.32.3
|
|
21
21
|
Dynamic: license-file
|
|
@@ -38,6 +38,24 @@ This library is part of the **Microsoft 365 Agents SDK for Python** - a comprehe
|
|
|
38
38
|
<th style="width:20%">Date</th>
|
|
39
39
|
<th style="width:60%">Release Notes</th>
|
|
40
40
|
</tr>
|
|
41
|
+
<tr>
|
|
42
|
+
<td>1.3.0</td>
|
|
43
|
+
<td>2026-07-30</td>
|
|
44
|
+
<td>
|
|
45
|
+
<a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md#microsoft-365-agents-sdk-for-python---release-notes-v130">
|
|
46
|
+
1.3.0 Release Notes
|
|
47
|
+
</a>
|
|
48
|
+
</td>
|
|
49
|
+
</tr>
|
|
50
|
+
<tr>
|
|
51
|
+
<td>1.2.0</td>
|
|
52
|
+
<td>2026-07-17</td>
|
|
53
|
+
<td>
|
|
54
|
+
<a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md#microsoft-365-agents-sdk-for-python---release-notes-v120">
|
|
55
|
+
1.2.0 Release Notes
|
|
56
|
+
</a>
|
|
57
|
+
</td>
|
|
58
|
+
</tr>
|
|
41
59
|
<tr>
|
|
42
60
|
<td>1.1.0</td>
|
|
43
61
|
<td>2026-06-19</td>
|
|
@@ -56,6 +74,15 @@ This library is part of the **Microsoft 365 Agents SDK for Python** - a comprehe
|
|
|
56
74
|
</a>
|
|
57
75
|
</td>
|
|
58
76
|
</tr>
|
|
77
|
+
<tr>
|
|
78
|
+
<td>0.9.1</td>
|
|
79
|
+
<td>2026-05-04</td>
|
|
80
|
+
<td>
|
|
81
|
+
<a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md#microsoft-365-agents-sdk-for-python---release-notes-v091">
|
|
82
|
+
0.9.1 Release Notes
|
|
83
|
+
</a>
|
|
84
|
+
</td>
|
|
85
|
+
</tr>
|
|
59
86
|
<tr>
|
|
60
87
|
<td>0.9.0</td>
|
|
61
88
|
<td>2026-04-15</td>
|
|
@@ -121,11 +148,14 @@ We offer the following PyPI packages to create conversational experiences based
|
|
|
121
148
|
| `microsoft-agents-activity` | [](https://pypi.org/project/microsoft-agents-activity/) | Types and validators implementing the Activity protocol spec. |
|
|
122
149
|
| `microsoft-agents-hosting-core` | [](https://pypi.org/project/microsoft-agents-hosting-core/) | Core library for Microsoft Agents hosting. |
|
|
123
150
|
| `microsoft-agents-hosting-aiohttp` | [](https://pypi.org/project/microsoft-agents-hosting-aiohttp/) | Configures aiohttp to run the Agent. |
|
|
124
|
-
| `microsoft-agents-hosting-
|
|
151
|
+
| `microsoft-agents-hosting-fastapi` | [](https://pypi.org/project/microsoft-agents-hosting-fastapi/) | Configures fastapi to run the Agent. |
|
|
152
|
+
| `microsoft-agents-hosting-msteams` | [](https://pypi.org/project/microsoft-agents-hosting-msteams/) | Provides classes to host an Agent for Teams. |
|
|
125
153
|
| `microsoft-agents-hosting-dialogs` | [](https://pypi.org/project/microsoft-agents-hosting-dialogs/) | Dialog system with waterfall dialogs, prompts, and multi-turn conversation management. |
|
|
154
|
+
| `microsoft-agents-hosting-slack` | [](https://pypi.org/project/microsoft-agents-hosting-slack/) | Provides classes to host an Agent for Slack. |
|
|
126
155
|
| `microsoft-agents-storage-blob` | [](https://pypi.org/project/microsoft-agents-storage-blob/) | Extension to use Azure Blob as storage. |
|
|
127
156
|
| `microsoft-agents-storage-cosmos` | [](https://pypi.org/project/microsoft-agents-storage-cosmos/) | Extension to use CosmosDB as storage. |
|
|
128
157
|
| `microsoft-agents-authentication-msal` | [](https://pypi.org/project/microsoft-agents-authentication-msal/) | MSAL-based authentication for Microsoft Agents. |
|
|
158
|
+
| `microsoft-agents-authentication-entra-auth-sidecar` | [](https://pypi.org/project/microsoft-agents-authentication-entra-auth-sidecar/) | Credential-free Entra ID Agent ID authentication via the sidecar. |
|
|
129
159
|
|
|
130
160
|
Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio:
|
|
131
161
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.4.0.dev10
|
|
@@ -61,6 +61,15 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
61
61
|
f"Initializing MsalAuth with configuration: {self._msal_configuration}"
|
|
62
62
|
)
|
|
63
63
|
|
|
64
|
+
@property
|
|
65
|
+
def configuration(self) -> AgentAuthConfiguration:
|
|
66
|
+
"""Returns the MSAL authentication configuration.
|
|
67
|
+
|
|
68
|
+
:return: The MSAL authentication configuration.
|
|
69
|
+
:rtype: :class:`microsoft_agents.hosting.core.authorization.agent_auth_configuration.AgentAuthConfiguration`
|
|
70
|
+
"""
|
|
71
|
+
return self._msal_configuration
|
|
72
|
+
|
|
64
73
|
async def get_access_token(
|
|
65
74
|
self, resource_url: str, scopes: list[str], force_refresh: bool = False
|
|
66
75
|
) -> str:
|
|
@@ -272,6 +281,19 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
272
281
|
)
|
|
273
282
|
return result["access_token"]
|
|
274
283
|
|
|
284
|
+
client_credential = {"client_assertion": get_assertion}
|
|
285
|
+
elif self._msal_configuration.AUTH_TYPE == AuthTypes.workload_identity:
|
|
286
|
+
if not self._msal_configuration.FEDERATED_TOKEN_FILE:
|
|
287
|
+
raise ValueError(
|
|
288
|
+
"FEDERATED_TOKEN_FILE must be set in configuration."
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
federated_token_file = self._msal_configuration.FEDERATED_TOKEN_FILE
|
|
292
|
+
|
|
293
|
+
def get_assertion() -> str:
|
|
294
|
+
with open(federated_token_file, encoding="utf-8") as f:
|
|
295
|
+
return f.read().strip()
|
|
296
|
+
|
|
275
297
|
client_credential = {"client_assertion": get_assertion}
|
|
276
298
|
else:
|
|
277
299
|
logger.error(
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
# Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
from microsoft_agents.hosting.core import (
|
|
5
|
+
AgentAuthConfiguration,
|
|
6
|
+
ConnectionManager,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
from .msal_auth import MsalAuth
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class MsalConnectionManager(ConnectionManager):
|
|
13
|
+
"""
|
|
14
|
+
Connection manager that uses :class:`MsalAuth` as the token provider.
|
|
15
|
+
|
|
16
|
+
Thin convenience subclass of the generic
|
|
17
|
+
:class:`microsoft_agents.hosting.core.ConnectionManager` that defaults the
|
|
18
|
+
``provider_factory`` to :class:`MsalAuth`. All connection routing logic lives
|
|
19
|
+
in the base class.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
connections_configurations: dict[str, AgentAuthConfiguration] | None = None,
|
|
25
|
+
connections_map: list[dict[str, str]] | None = None,
|
|
26
|
+
**kwargs,
|
|
27
|
+
):
|
|
28
|
+
"""
|
|
29
|
+
Initialize the MSAL connection manager.
|
|
30
|
+
|
|
31
|
+
:param connections_configurations: A dictionary of connection configurations.
|
|
32
|
+
:type connections_configurations: dict[str, :class:`microsoft_agents.hosting.core.AgentAuthConfiguration`]
|
|
33
|
+
:param connections_map: A list of connection mappings.
|
|
34
|
+
:type connections_map: list[dict[str, str]]
|
|
35
|
+
:raises ValueError: If no service connection configuration is provided.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
super().__init__(
|
|
39
|
+
provider_factory=MsalAuth,
|
|
40
|
+
connections_configurations=connections_configurations,
|
|
41
|
+
connections_map=connections_map,
|
|
42
|
+
**kwargs,
|
|
43
|
+
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: microsoft-agents-authentication-msal
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.4.0.dev10
|
|
4
4
|
Summary: A msal-based authentication library for Microsoft Agents
|
|
5
5
|
Author: Microsoft Corporation
|
|
6
6
|
License-Expression: MIT
|
|
@@ -15,7 +15,7 @@ Classifier: Operating System :: OS Independent
|
|
|
15
15
|
Requires-Python: >=3.10
|
|
16
16
|
Description-Content-Type: text/markdown
|
|
17
17
|
License-File: LICENSE
|
|
18
|
-
Requires-Dist: microsoft-agents-hosting-core==1.
|
|
18
|
+
Requires-Dist: microsoft-agents-hosting-core==1.4.0.dev10
|
|
19
19
|
Requires-Dist: msal>=1.34.0
|
|
20
20
|
Requires-Dist: requests>=2.32.3
|
|
21
21
|
Dynamic: license-file
|
|
@@ -38,6 +38,24 @@ This library is part of the **Microsoft 365 Agents SDK for Python** - a comprehe
|
|
|
38
38
|
<th style="width:20%">Date</th>
|
|
39
39
|
<th style="width:60%">Release Notes</th>
|
|
40
40
|
</tr>
|
|
41
|
+
<tr>
|
|
42
|
+
<td>1.3.0</td>
|
|
43
|
+
<td>2026-07-30</td>
|
|
44
|
+
<td>
|
|
45
|
+
<a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md#microsoft-365-agents-sdk-for-python---release-notes-v130">
|
|
46
|
+
1.3.0 Release Notes
|
|
47
|
+
</a>
|
|
48
|
+
</td>
|
|
49
|
+
</tr>
|
|
50
|
+
<tr>
|
|
51
|
+
<td>1.2.0</td>
|
|
52
|
+
<td>2026-07-17</td>
|
|
53
|
+
<td>
|
|
54
|
+
<a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md#microsoft-365-agents-sdk-for-python---release-notes-v120">
|
|
55
|
+
1.2.0 Release Notes
|
|
56
|
+
</a>
|
|
57
|
+
</td>
|
|
58
|
+
</tr>
|
|
41
59
|
<tr>
|
|
42
60
|
<td>1.1.0</td>
|
|
43
61
|
<td>2026-06-19</td>
|
|
@@ -56,6 +74,15 @@ This library is part of the **Microsoft 365 Agents SDK for Python** - a comprehe
|
|
|
56
74
|
</a>
|
|
57
75
|
</td>
|
|
58
76
|
</tr>
|
|
77
|
+
<tr>
|
|
78
|
+
<td>0.9.1</td>
|
|
79
|
+
<td>2026-05-04</td>
|
|
80
|
+
<td>
|
|
81
|
+
<a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md#microsoft-365-agents-sdk-for-python---release-notes-v091">
|
|
82
|
+
0.9.1 Release Notes
|
|
83
|
+
</a>
|
|
84
|
+
</td>
|
|
85
|
+
</tr>
|
|
59
86
|
<tr>
|
|
60
87
|
<td>0.9.0</td>
|
|
61
88
|
<td>2026-04-15</td>
|
|
@@ -121,11 +148,14 @@ We offer the following PyPI packages to create conversational experiences based
|
|
|
121
148
|
| `microsoft-agents-activity` | [](https://pypi.org/project/microsoft-agents-activity/) | Types and validators implementing the Activity protocol spec. |
|
|
122
149
|
| `microsoft-agents-hosting-core` | [](https://pypi.org/project/microsoft-agents-hosting-core/) | Core library for Microsoft Agents hosting. |
|
|
123
150
|
| `microsoft-agents-hosting-aiohttp` | [](https://pypi.org/project/microsoft-agents-hosting-aiohttp/) | Configures aiohttp to run the Agent. |
|
|
124
|
-
| `microsoft-agents-hosting-
|
|
151
|
+
| `microsoft-agents-hosting-fastapi` | [](https://pypi.org/project/microsoft-agents-hosting-fastapi/) | Configures fastapi to run the Agent. |
|
|
152
|
+
| `microsoft-agents-hosting-msteams` | [](https://pypi.org/project/microsoft-agents-hosting-msteams/) | Provides classes to host an Agent for Teams. |
|
|
125
153
|
| `microsoft-agents-hosting-dialogs` | [](https://pypi.org/project/microsoft-agents-hosting-dialogs/) | Dialog system with waterfall dialogs, prompts, and multi-turn conversation management. |
|
|
154
|
+
| `microsoft-agents-hosting-slack` | [](https://pypi.org/project/microsoft-agents-hosting-slack/) | Provides classes to host an Agent for Slack. |
|
|
126
155
|
| `microsoft-agents-storage-blob` | [](https://pypi.org/project/microsoft-agents-storage-blob/) | Extension to use Azure Blob as storage. |
|
|
127
156
|
| `microsoft-agents-storage-cosmos` | [](https://pypi.org/project/microsoft-agents-storage-cosmos/) | Extension to use CosmosDB as storage. |
|
|
128
157
|
| `microsoft-agents-authentication-msal` | [](https://pypi.org/project/microsoft-agents-authentication-msal/) | MSAL-based authentication for Microsoft Agents. |
|
|
158
|
+
| `microsoft-agents-authentication-entra-auth-sidecar` | [](https://pypi.org/project/microsoft-agents-authentication-entra-auth-sidecar/) | Credential-free Entra ID Agent ID authentication via the sidecar. |
|
|
129
159
|
|
|
130
160
|
Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio:
|
|
131
161
|
|
|
@@ -15,6 +15,24 @@ This library is part of the **Microsoft 365 Agents SDK for Python** - a comprehe
|
|
|
15
15
|
<th style="width:20%">Date</th>
|
|
16
16
|
<th style="width:60%">Release Notes</th>
|
|
17
17
|
</tr>
|
|
18
|
+
<tr>
|
|
19
|
+
<td>1.3.0</td>
|
|
20
|
+
<td>2026-07-30</td>
|
|
21
|
+
<td>
|
|
22
|
+
<a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md#microsoft-365-agents-sdk-for-python---release-notes-v130">
|
|
23
|
+
1.3.0 Release Notes
|
|
24
|
+
</a>
|
|
25
|
+
</td>
|
|
26
|
+
</tr>
|
|
27
|
+
<tr>
|
|
28
|
+
<td>1.2.0</td>
|
|
29
|
+
<td>2026-07-17</td>
|
|
30
|
+
<td>
|
|
31
|
+
<a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md#microsoft-365-agents-sdk-for-python---release-notes-v120">
|
|
32
|
+
1.2.0 Release Notes
|
|
33
|
+
</a>
|
|
34
|
+
</td>
|
|
35
|
+
</tr>
|
|
18
36
|
<tr>
|
|
19
37
|
<td>1.1.0</td>
|
|
20
38
|
<td>2026-06-19</td>
|
|
@@ -33,6 +51,15 @@ This library is part of the **Microsoft 365 Agents SDK for Python** - a comprehe
|
|
|
33
51
|
</a>
|
|
34
52
|
</td>
|
|
35
53
|
</tr>
|
|
54
|
+
<tr>
|
|
55
|
+
<td>0.9.1</td>
|
|
56
|
+
<td>2026-05-04</td>
|
|
57
|
+
<td>
|
|
58
|
+
<a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md#microsoft-365-agents-sdk-for-python---release-notes-v091">
|
|
59
|
+
0.9.1 Release Notes
|
|
60
|
+
</a>
|
|
61
|
+
</td>
|
|
62
|
+
</tr>
|
|
36
63
|
<tr>
|
|
37
64
|
<td>0.9.0</td>
|
|
38
65
|
<td>2026-04-15</td>
|
|
@@ -98,11 +125,14 @@ We offer the following PyPI packages to create conversational experiences based
|
|
|
98
125
|
| `microsoft-agents-activity` | [](https://pypi.org/project/microsoft-agents-activity/) | Types and validators implementing the Activity protocol spec. |
|
|
99
126
|
| `microsoft-agents-hosting-core` | [](https://pypi.org/project/microsoft-agents-hosting-core/) | Core library for Microsoft Agents hosting. |
|
|
100
127
|
| `microsoft-agents-hosting-aiohttp` | [](https://pypi.org/project/microsoft-agents-hosting-aiohttp/) | Configures aiohttp to run the Agent. |
|
|
101
|
-
| `microsoft-agents-hosting-
|
|
128
|
+
| `microsoft-agents-hosting-fastapi` | [](https://pypi.org/project/microsoft-agents-hosting-fastapi/) | Configures fastapi to run the Agent. |
|
|
129
|
+
| `microsoft-agents-hosting-msteams` | [](https://pypi.org/project/microsoft-agents-hosting-msteams/) | Provides classes to host an Agent for Teams. |
|
|
102
130
|
| `microsoft-agents-hosting-dialogs` | [](https://pypi.org/project/microsoft-agents-hosting-dialogs/) | Dialog system with waterfall dialogs, prompts, and multi-turn conversation management. |
|
|
131
|
+
| `microsoft-agents-hosting-slack` | [](https://pypi.org/project/microsoft-agents-hosting-slack/) | Provides classes to host an Agent for Slack. |
|
|
103
132
|
| `microsoft-agents-storage-blob` | [](https://pypi.org/project/microsoft-agents-storage-blob/) | Extension to use Azure Blob as storage. |
|
|
104
133
|
| `microsoft-agents-storage-cosmos` | [](https://pypi.org/project/microsoft-agents-storage-cosmos/) | Extension to use CosmosDB as storage. |
|
|
105
134
|
| `microsoft-agents-authentication-msal` | [](https://pypi.org/project/microsoft-agents-authentication-msal/) | MSAL-based authentication for Microsoft Agents. |
|
|
135
|
+
| `microsoft-agents-authentication-entra-auth-sidecar` | [](https://pypi.org/project/microsoft-agents-authentication-entra-auth-sidecar/) | Credential-free Entra ID Agent ID authentication via the sidecar. |
|
|
106
136
|
|
|
107
137
|
Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio:
|
|
108
138
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
1.2.0.dev20
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
# Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import re
|
|
5
|
-
from typing import Optional
|
|
6
|
-
from microsoft_agents.hosting.core import (
|
|
7
|
-
AgentAuthConfiguration,
|
|
8
|
-
AccessTokenProviderBase,
|
|
9
|
-
ClaimsIdentity,
|
|
10
|
-
Connections,
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
from .msal_auth import MsalAuth
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class MsalConnectionManager(Connections):
|
|
17
|
-
_connections: dict[str, MsalAuth]
|
|
18
|
-
_connections_map: list[dict[str, str]]
|
|
19
|
-
_service_connection_configuration: AgentAuthConfiguration
|
|
20
|
-
|
|
21
|
-
def __init__(
|
|
22
|
-
self,
|
|
23
|
-
connections_configurations: Optional[dict[str, AgentAuthConfiguration]] = None,
|
|
24
|
-
connections_map: Optional[list[dict[str, str]]] = None,
|
|
25
|
-
**kwargs,
|
|
26
|
-
):
|
|
27
|
-
"""
|
|
28
|
-
Initialize the MSAL connection manager.
|
|
29
|
-
|
|
30
|
-
:arg connections_configurations: A dictionary of connection configurations.
|
|
31
|
-
:type connections_configurations: dict[str, :class:`microsoft_agents.hosting.core.AgentAuthConfiguration`]
|
|
32
|
-
:arg connections_map: A list of connection mappings.
|
|
33
|
-
:type connections_map: list[dict[str, str]]
|
|
34
|
-
:raises ValueError: If no service connection configuration is provided.
|
|
35
|
-
"""
|
|
36
|
-
|
|
37
|
-
self._connections: dict[str, MsalAuth] = {}
|
|
38
|
-
self._connections_map = connections_map or kwargs.get("CONNECTIONSMAP", {})
|
|
39
|
-
self._config_map: dict[str, AgentAuthConfiguration] = {}
|
|
40
|
-
|
|
41
|
-
if connections_configurations:
|
|
42
|
-
for (
|
|
43
|
-
connection_name,
|
|
44
|
-
agent_auth_config,
|
|
45
|
-
) in connections_configurations.items():
|
|
46
|
-
self._connections[connection_name] = MsalAuth(agent_auth_config)
|
|
47
|
-
self._config_map[connection_name] = agent_auth_config
|
|
48
|
-
else:
|
|
49
|
-
raw_configurations: dict[str, dict] = kwargs.get("CONNECTIONS", {})
|
|
50
|
-
for connection_name, connection_settings in raw_configurations.items():
|
|
51
|
-
parsed_configuration = AgentAuthConfiguration(
|
|
52
|
-
**connection_settings.get("SETTINGS", {})
|
|
53
|
-
)
|
|
54
|
-
self._connections[connection_name] = MsalAuth(parsed_configuration)
|
|
55
|
-
self._config_map[connection_name] = parsed_configuration
|
|
56
|
-
|
|
57
|
-
# JWT-patch
|
|
58
|
-
for connection_name, config in self._config_map.items():
|
|
59
|
-
config._connections = self._config_map
|
|
60
|
-
|
|
61
|
-
if not self._connections.get("SERVICE_CONNECTION", None):
|
|
62
|
-
raise ValueError("No service connection configuration provided.")
|
|
63
|
-
|
|
64
|
-
def get_connection(self, connection_name: Optional[str]) -> AccessTokenProviderBase:
|
|
65
|
-
"""
|
|
66
|
-
Get the OAuth connection for the agent.
|
|
67
|
-
|
|
68
|
-
:arg connection_name: The name of the connection.
|
|
69
|
-
:type connection_name: Optional[str]
|
|
70
|
-
:return: The OAuth connection for the agent.
|
|
71
|
-
:rtype: :class:`microsoft_agents.hosting.core.AccessTokenProviderBase`
|
|
72
|
-
"""
|
|
73
|
-
original_name = connection_name
|
|
74
|
-
connection_name = connection_name or "SERVICE_CONNECTION"
|
|
75
|
-
connection = self._connections.get(connection_name, None)
|
|
76
|
-
if not connection:
|
|
77
|
-
if original_name:
|
|
78
|
-
raise ValueError(f"No connection found for '{original_name}'.")
|
|
79
|
-
else:
|
|
80
|
-
raise ValueError(
|
|
81
|
-
"No default service connection found. Expected 'SERVICE_CONNECTION'."
|
|
82
|
-
)
|
|
83
|
-
return connection
|
|
84
|
-
|
|
85
|
-
def get_default_connection(self) -> AccessTokenProviderBase:
|
|
86
|
-
"""
|
|
87
|
-
Get the default OAuth connection for the agent.
|
|
88
|
-
|
|
89
|
-
:return: The default OAuth connection for the agent.
|
|
90
|
-
:rtype: :class:`microsoft_agents.hosting.core.AccessTokenProviderBase`
|
|
91
|
-
"""
|
|
92
|
-
connection = self._connections.get("SERVICE_CONNECTION", None)
|
|
93
|
-
if not connection:
|
|
94
|
-
raise ValueError(
|
|
95
|
-
"No default service connection found. Expected 'SERVICE_CONNECTION'."
|
|
96
|
-
)
|
|
97
|
-
return connection
|
|
98
|
-
|
|
99
|
-
def get_token_provider(
|
|
100
|
-
self, claims_identity: ClaimsIdentity, service_url: str
|
|
101
|
-
) -> AccessTokenProviderBase:
|
|
102
|
-
"""
|
|
103
|
-
Get the OAuth token provider for the agent.
|
|
104
|
-
|
|
105
|
-
:arg claims_identity: The claims identity of the bot.
|
|
106
|
-
:type claims_identity: :class:`microsoft_agents.hosting.core.ClaimsIdentity`
|
|
107
|
-
:arg service_url: The service URL of the bot.
|
|
108
|
-
:type service_url: str
|
|
109
|
-
:return: The OAuth token provider for the agent.
|
|
110
|
-
:rtype: :class:`microsoft_agents.hosting.core.AccessTokenProviderBase`
|
|
111
|
-
:raises ValueError: If no connection is found for the given audience and service URL.
|
|
112
|
-
"""
|
|
113
|
-
if not claims_identity or not service_url:
|
|
114
|
-
raise ValueError(
|
|
115
|
-
"Claims identity and Service URL are required to get the token provider."
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
if not self._connections_map:
|
|
119
|
-
return self.get_default_connection()
|
|
120
|
-
|
|
121
|
-
aud = claims_identity.get_app_id() or ""
|
|
122
|
-
for item in self._connections_map:
|
|
123
|
-
audience_match = True
|
|
124
|
-
item_aud = item.get("AUDIENCE", "")
|
|
125
|
-
if item_aud:
|
|
126
|
-
audience_match = item_aud.lower() == aud.lower()
|
|
127
|
-
|
|
128
|
-
if audience_match:
|
|
129
|
-
item_service_url = item.get("SERVICEURL", "")
|
|
130
|
-
if item_service_url == "*" or item_service_url == "":
|
|
131
|
-
connection_name = item.get("CONNECTION")
|
|
132
|
-
connection = self.get_connection(connection_name)
|
|
133
|
-
if connection:
|
|
134
|
-
return connection
|
|
135
|
-
|
|
136
|
-
else:
|
|
137
|
-
res = re.match(item_service_url, service_url, re.IGNORECASE)
|
|
138
|
-
if res:
|
|
139
|
-
connection_name = item.get("CONNECTION")
|
|
140
|
-
connection = self.get_connection(connection_name)
|
|
141
|
-
if connection:
|
|
142
|
-
return connection
|
|
143
|
-
|
|
144
|
-
raise ValueError(
|
|
145
|
-
f"No connection found for audience '{aud}' and serviceUrl '{service_url}'."
|
|
146
|
-
)
|
|
147
|
-
|
|
148
|
-
def get_default_connection_configuration(self) -> AgentAuthConfiguration:
|
|
149
|
-
"""
|
|
150
|
-
Get the default connection configuration for the agent.
|
|
151
|
-
|
|
152
|
-
:return: The default connection configuration for the agent.
|
|
153
|
-
:rtype: :class:`microsoft_agents.hosting.core.AgentAuthConfiguration`
|
|
154
|
-
"""
|
|
155
|
-
config = self._config_map.get("SERVICE_CONNECTION")
|
|
156
|
-
if not config:
|
|
157
|
-
raise ValueError(
|
|
158
|
-
"No default service connection configuration found. Expected 'SERVICE_CONNECTION'."
|
|
159
|
-
)
|
|
160
|
-
return config
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|