microsoft-agents-authentication-msal 0.4.0.dev16__tar.gz → 0.5.0__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-0.5.0/LICENSE +21 -0
- microsoft_agents_authentication_msal-0.5.0/PKG-INFO +166 -0
- {microsoft_agents_authentication_msal-0.4.0.dev16 → microsoft_agents_authentication_msal-0.5.0}/microsoft_agents/authentication/msal/msal_auth.py +75 -47
- {microsoft_agents_authentication_msal-0.4.0.dev16 → microsoft_agents_authentication_msal-0.5.0}/microsoft_agents/authentication/msal/msal_connection_manager.py +14 -5
- microsoft_agents_authentication_msal-0.5.0/microsoft_agents_authentication_msal.egg-info/PKG-INFO +166 -0
- {microsoft_agents_authentication_msal-0.4.0.dev16 → microsoft_agents_authentication_msal-0.5.0}/microsoft_agents_authentication_msal.egg-info/SOURCES.txt +2 -0
- {microsoft_agents_authentication_msal-0.4.0.dev16 → microsoft_agents_authentication_msal-0.5.0}/microsoft_agents_authentication_msal.egg-info/requires.txt +1 -1
- {microsoft_agents_authentication_msal-0.4.0.dev16 → microsoft_agents_authentication_msal-0.5.0}/pyproject.toml +9 -2
- microsoft_agents_authentication_msal-0.5.0/readme.md +142 -0
- microsoft_agents_authentication_msal-0.4.0.dev16/PKG-INFO +0 -15
- microsoft_agents_authentication_msal-0.4.0.dev16/microsoft_agents_authentication_msal.egg-info/PKG-INFO +0 -15
- {microsoft_agents_authentication_msal-0.4.0.dev16 → microsoft_agents_authentication_msal-0.5.0}/microsoft_agents/authentication/msal/__init__.py +0 -0
- {microsoft_agents_authentication_msal-0.4.0.dev16 → microsoft_agents_authentication_msal-0.5.0}/microsoft_agents_authentication_msal.egg-info/dependency_links.txt +0 -0
- {microsoft_agents_authentication_msal-0.4.0.dev16 → microsoft_agents_authentication_msal-0.5.0}/microsoft_agents_authentication_msal.egg-info/top_level.txt +0 -0
- {microsoft_agents_authentication_msal-0.4.0.dev16 → microsoft_agents_authentication_msal-0.5.0}/setup.cfg +0 -0
- {microsoft_agents_authentication_msal-0.4.0.dev16 → microsoft_agents_authentication_msal-0.5.0}/setup.py +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Microsoft Corporation.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: microsoft-agents-authentication-msal
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: A msal-based authentication library for Microsoft Agents
|
|
5
|
+
Author: Microsoft Corporation
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/microsoft/Agents
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: microsoft-agents-hosting-core==0.5.0
|
|
19
|
+
Requires-Dist: msal>=1.31.1
|
|
20
|
+
Requires-Dist: requests>=2.32.3
|
|
21
|
+
Requires-Dist: cryptography>=44.0.0
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
Dynamic: requires-dist
|
|
24
|
+
|
|
25
|
+
# Microsoft Agents MSAL Authentication
|
|
26
|
+
|
|
27
|
+
[](https://pypi.org/project/microsoft-agents-authentication-msal/)
|
|
28
|
+
|
|
29
|
+
Provides secure authentication for your agents using Microsoft Authentication Library (MSAL). It handles getting tokens from Azure AD so your agent can securely communicate with Microsoft services like Teams, Graph API, and other Azure resources.
|
|
30
|
+
|
|
31
|
+
# What is this?
|
|
32
|
+
|
|
33
|
+
This library is part of the **Microsoft 365 Agents SDK for Python** - a comprehensive framework for building enterprise-grade conversational AI agents. The SDK enables developers to create intelligent agents that work across multiple platforms including Microsoft Teams, M365 Copilot, Copilot Studio, and web chat, with support for third-party integrations like Slack, Facebook Messenger, and Twilio.
|
|
34
|
+
|
|
35
|
+
## Release Notes
|
|
36
|
+
<table style="width:100%">
|
|
37
|
+
<tr>
|
|
38
|
+
<th style="width:20%">Version</th>
|
|
39
|
+
<th style="width:20%">Date</th>
|
|
40
|
+
<th style="width:60%">Release Notes</th>
|
|
41
|
+
</tr>
|
|
42
|
+
<tr>
|
|
43
|
+
<td>0.5.0</td>
|
|
44
|
+
<td>2025-10-22</td>
|
|
45
|
+
<td>
|
|
46
|
+
<a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md">
|
|
47
|
+
0.5.0 Release Notes
|
|
48
|
+
</a>
|
|
49
|
+
</td>
|
|
50
|
+
</tr>
|
|
51
|
+
</table>
|
|
52
|
+
|
|
53
|
+
## Packages Overview
|
|
54
|
+
|
|
55
|
+
We offer the following PyPI packages to create conversational experiences based on Agents:
|
|
56
|
+
|
|
57
|
+
| Package Name | PyPI Version | Description |
|
|
58
|
+
|--------------|-------------|-------------|
|
|
59
|
+
| `microsoft-agents-activity` | [](https://pypi.org/project/microsoft-agents-activity/) | Types and validators implementing the Activity protocol spec. |
|
|
60
|
+
| `microsoft-agents-hosting-core` | [](https://pypi.org/project/microsoft-agents-hosting-core/) | Core library for Microsoft Agents hosting. |
|
|
61
|
+
| `microsoft-agents-hosting-aiohttp` | [](https://pypi.org/project/microsoft-agents-hosting-aiohttp/) | Configures aiohttp to run the Agent. |
|
|
62
|
+
| `microsoft-agents-hosting-teams` | [](https://pypi.org/project/microsoft-agents-hosting-teams/) | Provides classes to host an Agent for Teams. |
|
|
63
|
+
| `microsoft-agents-storage-blob` | [](https://pypi.org/project/microsoft-agents-storage-blob/) | Extension to use Azure Blob as storage. |
|
|
64
|
+
| `microsoft-agents-storage-cosmos` | [](https://pypi.org/project/microsoft-agents-storage-cosmos/) | Extension to use CosmosDB as storage. |
|
|
65
|
+
| `microsoft-agents-authentication-msal` | [](https://pypi.org/project/microsoft-agents-authentication-msal/) | MSAL-based authentication for Microsoft Agents. |
|
|
66
|
+
|
|
67
|
+
Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio:
|
|
68
|
+
|
|
69
|
+
| Package Name | PyPI Version | Description |
|
|
70
|
+
|--------------|-------------|-------------|
|
|
71
|
+
| `microsoft-agents-copilotstudio-client` | [](https://pypi.org/project/microsoft-agents-copilotstudio-client/) | Direct to Engine client to interact with Agents created in CopilotStudio |
|
|
72
|
+
|
|
73
|
+
## Installation
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pip install microsoft-agents-authentication-msal
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Quick Start
|
|
80
|
+
|
|
81
|
+
### Basic Setup with Client Secret
|
|
82
|
+
|
|
83
|
+
Define your client secrets in the ENV file
|
|
84
|
+
```python
|
|
85
|
+
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTID=client-id
|
|
86
|
+
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTSECRET=client-secret
|
|
87
|
+
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__TENANTID=tenant-id
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Load the Configuration (Code from [main.py Quickstart Sample](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/src/main.py))
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from .start_server import start_server
|
|
94
|
+
|
|
95
|
+
start_server(
|
|
96
|
+
agent_application=AGENT_APP,
|
|
97
|
+
auth_configuration=CONNECTION_MANAGER.get_default_connection_configuration(),
|
|
98
|
+
)
|
|
99
|
+
```
|
|
100
|
+
Then start the Agent (code snipped from (start_server.py Quickstart Sample](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/src/start_server.py)):
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
def start_server(
|
|
104
|
+
agent_application: AgentApplication, auth_configuration: AgentAuthConfiguration
|
|
105
|
+
):
|
|
106
|
+
async def entry_point(req: Request) -> Response:
|
|
107
|
+
agent: AgentApplication = req.app["agent_app"]
|
|
108
|
+
adapter: CloudAdapter = req.app["adapter"]
|
|
109
|
+
return await start_agent_process(
|
|
110
|
+
req,
|
|
111
|
+
agent,
|
|
112
|
+
adapter,
|
|
113
|
+
)
|
|
114
|
+
[...]
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Authentication Types
|
|
118
|
+
The M365 Agents SDK in Python supports the following Auth types:
|
|
119
|
+
```python
|
|
120
|
+
class AuthTypes(str, Enum):
|
|
121
|
+
certificate = "certificate"
|
|
122
|
+
certificate_subject_name = "CertificateSubjectName"
|
|
123
|
+
client_secret = "ClientSecret"
|
|
124
|
+
user_managed_identity = "UserManagedIdentity"
|
|
125
|
+
system_managed_identity = "SystemManagedIdentity"
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Key Classes
|
|
129
|
+
|
|
130
|
+
- **`MsalAuth`** - Core authentication provider using MSAL
|
|
131
|
+
- **`MsalConnectionManager`** - Manages multiple authentication connections
|
|
132
|
+
|
|
133
|
+
## Features
|
|
134
|
+
|
|
135
|
+
✅ **Multiple auth types** - Client secret, certificate, managed identity
|
|
136
|
+
✅ **Token caching** - Automatic token refresh and caching
|
|
137
|
+
✅ **Multi-tenant** - Support for different Azure AD tenants
|
|
138
|
+
✅ **Agent-to-agent** - Secure communication between agents
|
|
139
|
+
✅ **On-behalf-of** - Act on behalf of users
|
|
140
|
+
|
|
141
|
+
# Security Best Practices
|
|
142
|
+
|
|
143
|
+
- Store secrets in Azure Key Vault or environment variables
|
|
144
|
+
- Use managed identities when possible (no secrets to manage)
|
|
145
|
+
- Regularly rotate client secrets and certificates
|
|
146
|
+
- Use least-privilege principle for scopes and permissions
|
|
147
|
+
|
|
148
|
+
# Quick Links
|
|
149
|
+
|
|
150
|
+
- 📦 [All SDK Packages on PyPI](https://pypi.org/search/?q=microsoft-agents)
|
|
151
|
+
- 📖 [Complete Documentation](https://aka.ms/agents)
|
|
152
|
+
- 💡 [Python Samples Repository](https://github.com/microsoft/Agents/tree/main/samples/python)
|
|
153
|
+
- 🐛 [Report Issues](https://github.com/microsoft/Agents-for-python/issues)
|
|
154
|
+
|
|
155
|
+
# Sample Applications
|
|
156
|
+
Explore working examples in the [Python samples repository](https://github.com/microsoft/Agents/tree/main/samples/python):
|
|
157
|
+
|
|
158
|
+
|Name|Description|README|
|
|
159
|
+
|----|----|----|
|
|
160
|
+
|Quickstart|Simplest agent|[Quickstart](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/README.md)|
|
|
161
|
+
|Auto Sign In|Simple OAuth agent using Graph and GitHub|[auto-signin](https://github.com/microsoft/Agents/blob/main/samples/python/auto-signin/README.md)|
|
|
162
|
+
|OBO Authorization|OBO flow to access a Copilot Studio Agent|[obo-authorization](https://github.com/microsoft/Agents/blob/main/samples/python/obo-authorization/README.md)|
|
|
163
|
+
|Semantic Kernel Integration|A weather agent built with Semantic Kernel|[semantic-kernel-multiturn](https://github.com/microsoft/Agents/blob/main/samples/python/semantic-kernel-multiturn/README.md)|
|
|
164
|
+
|Streaming Agent|Streams OpenAI responses|[azure-ai-streaming](https://github.com/microsoft/Agents/blob/main/samples/python/azureai-streaming/README.md)|
|
|
165
|
+
|Copilot Studio Client|Console app to consume a Copilot Studio Agent|[copilotstudio-client](https://github.com/microsoft/Agents/blob/main/samples/python/copilotstudio-client/README.md)|
|
|
166
|
+
|Cards Agent|Agent that uses rich cards to enhance conversation design |[cards](https://github.com/microsoft/Agents/blob/main/samples/python/cards/README.md)|
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
# Licensed under the MIT License.
|
|
3
|
+
|
|
1
4
|
from __future__ import annotations
|
|
2
5
|
|
|
6
|
+
import asyncio
|
|
3
7
|
import logging
|
|
4
8
|
import jwt
|
|
5
9
|
from typing import Optional
|
|
@@ -36,12 +40,29 @@ class _DeferredLogOfBlueprintId:
|
|
|
36
40
|
return f"Agentic blueprint id: {agentic_blueprint_id}"
|
|
37
41
|
|
|
38
42
|
|
|
43
|
+
async def _async_acquire_token_for_client(msal_auth_client, *args, **kwargs):
|
|
44
|
+
"""MSAL in Python does not support async, so we use asyncio.to_thread to run it in
|
|
45
|
+
a separate thread and avoid blocking the event loop
|
|
46
|
+
"""
|
|
47
|
+
return await asyncio.to_thread(
|
|
48
|
+
lambda: msal_auth_client.acquire_token_for_client(*args, **kwargs)
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
39
52
|
class MsalAuth(AccessTokenProviderBase):
|
|
40
53
|
|
|
41
54
|
_client_credential_cache = None
|
|
42
55
|
|
|
43
56
|
def __init__(self, msal_configuration: AgentAuthConfiguration):
|
|
57
|
+
"""Initializes the MsalAuth class with the given configuration.
|
|
58
|
+
|
|
59
|
+
:param msal_configuration: The MSAL authentication configuration. Assumed to
|
|
60
|
+
not be mutated after being passed in.
|
|
61
|
+
:type msal_configuration: AgentAuthConfiguration
|
|
62
|
+
"""
|
|
63
|
+
|
|
44
64
|
self._msal_configuration = msal_configuration
|
|
65
|
+
self._msal_auth_client = None
|
|
45
66
|
logger.debug(
|
|
46
67
|
f"Initializing MsalAuth with configuration: {self._msal_configuration}"
|
|
47
68
|
)
|
|
@@ -57,17 +78,17 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
57
78
|
raise ValueError("Invalid instance URL")
|
|
58
79
|
|
|
59
80
|
local_scopes = self._resolve_scopes_list(instance_uri, scopes)
|
|
60
|
-
|
|
81
|
+
self._create_client_application()
|
|
61
82
|
|
|
62
|
-
if isinstance(
|
|
83
|
+
if isinstance(self._msal_auth_client, ManagedIdentityClient):
|
|
63
84
|
logger.info("Acquiring token using Managed Identity Client.")
|
|
64
|
-
auth_result_payload =
|
|
65
|
-
resource=resource_url
|
|
85
|
+
auth_result_payload = await _async_acquire_token_for_client(
|
|
86
|
+
self._msal_auth_client, resource=resource_url
|
|
66
87
|
)
|
|
67
|
-
elif isinstance(
|
|
88
|
+
elif isinstance(self._msal_auth_client, ConfidentialClientApplication):
|
|
68
89
|
logger.info("Acquiring token using Confidential Client Application.")
|
|
69
|
-
auth_result_payload =
|
|
70
|
-
scopes=local_scopes
|
|
90
|
+
auth_result_payload = await _async_acquire_token_for_client(
|
|
91
|
+
self._msal_auth_client, scopes=local_scopes
|
|
71
92
|
)
|
|
72
93
|
else:
|
|
73
94
|
auth_result_payload = None
|
|
@@ -76,6 +97,7 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
76
97
|
if not res:
|
|
77
98
|
logger.error("Failed to acquire token for resource %s", auth_result_payload)
|
|
78
99
|
raise ValueError(f"Failed to acquire token. {str(auth_result_payload)}")
|
|
100
|
+
|
|
79
101
|
return res
|
|
80
102
|
|
|
81
103
|
async def acquire_token_on_behalf_of(
|
|
@@ -88,19 +110,23 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
88
110
|
:return: The access token as a string.
|
|
89
111
|
"""
|
|
90
112
|
|
|
91
|
-
|
|
92
|
-
if isinstance(
|
|
113
|
+
self._create_client_application()
|
|
114
|
+
if isinstance(self._msal_auth_client, ManagedIdentityClient):
|
|
93
115
|
logger.error(
|
|
94
116
|
"Attempted on-behalf-of flow with Managed Identity authentication."
|
|
95
117
|
)
|
|
96
118
|
raise NotImplementedError(
|
|
97
119
|
"On-behalf-of flow is not supported with Managed Identity authentication."
|
|
98
120
|
)
|
|
99
|
-
elif isinstance(
|
|
121
|
+
elif isinstance(self._msal_auth_client, ConfidentialClientApplication):
|
|
100
122
|
# TODO: Handling token error / acquisition failed
|
|
101
123
|
|
|
102
|
-
|
|
103
|
-
|
|
124
|
+
# MSAL in Python does not support async, so we use asyncio.to_thread to run it in
|
|
125
|
+
# a separate thread and avoid blocking the event loop
|
|
126
|
+
token = await asyncio.to_thread(
|
|
127
|
+
lambda: self._msal_auth_client.acquire_token_on_behalf_of(
|
|
128
|
+
scopes=scopes, user_assertion=user_assertion
|
|
129
|
+
)
|
|
104
130
|
)
|
|
105
131
|
|
|
106
132
|
if "access_token" not in token:
|
|
@@ -112,19 +138,19 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
112
138
|
return token["access_token"]
|
|
113
139
|
|
|
114
140
|
logger.error(
|
|
115
|
-
f"On-behalf-of flow is not supported with the current authentication type: {
|
|
141
|
+
f"On-behalf-of flow is not supported with the current authentication type: {self._msal_auth_client.__class__.__name__}"
|
|
116
142
|
)
|
|
117
143
|
raise NotImplementedError(
|
|
118
|
-
f"On-behalf-of flow is not supported with the current authentication type: {
|
|
144
|
+
f"On-behalf-of flow is not supported with the current authentication type: {self._msal_auth_client.__class__.__name__}"
|
|
119
145
|
)
|
|
120
146
|
|
|
121
|
-
def _create_client_application(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
147
|
+
def _create_client_application(self) -> None:
|
|
148
|
+
|
|
149
|
+
if self._msal_auth_client:
|
|
150
|
+
return
|
|
125
151
|
|
|
126
152
|
if self._msal_configuration.AUTH_TYPE == AuthTypes.user_managed_identity:
|
|
127
|
-
|
|
153
|
+
self._msal_auth_client = ManagedIdentityClient(
|
|
128
154
|
UserAssignedManagedIdentity(
|
|
129
155
|
client_id=self._msal_configuration.CLIENT_ID
|
|
130
156
|
),
|
|
@@ -132,7 +158,7 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
132
158
|
)
|
|
133
159
|
|
|
134
160
|
elif self._msal_configuration.AUTH_TYPE == AuthTypes.system_managed_identity:
|
|
135
|
-
|
|
161
|
+
self._msal_auth_client = ManagedIdentityClient(
|
|
136
162
|
SystemAssignedManagedIdentity(),
|
|
137
163
|
http_client=Session(),
|
|
138
164
|
)
|
|
@@ -173,14 +199,12 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
173
199
|
)
|
|
174
200
|
raise NotImplementedError("Authentication type not supported")
|
|
175
201
|
|
|
176
|
-
|
|
202
|
+
self._msal_auth_client = ConfidentialClientApplication(
|
|
177
203
|
client_id=self._msal_configuration.CLIENT_ID,
|
|
178
204
|
authority=authority,
|
|
179
205
|
client_credential=self._client_credential_cache,
|
|
180
206
|
)
|
|
181
207
|
|
|
182
|
-
return msal_auth_client
|
|
183
|
-
|
|
184
208
|
@staticmethod
|
|
185
209
|
def _uri_validator(url_str: str) -> tuple[bool, Optional[URI]]:
|
|
186
210
|
try:
|
|
@@ -225,12 +249,13 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
225
249
|
"Attempting to get agentic application token from agent_app_instance_id %s",
|
|
226
250
|
agent_app_instance_id,
|
|
227
251
|
)
|
|
228
|
-
|
|
252
|
+
self._create_client_application()
|
|
229
253
|
|
|
230
|
-
if isinstance(
|
|
254
|
+
if isinstance(self._msal_auth_client, ConfidentialClientApplication):
|
|
231
255
|
|
|
232
256
|
# https://github.dev/AzureAD/microsoft-authentication-library-for-dotnet
|
|
233
|
-
auth_result_payload =
|
|
257
|
+
auth_result_payload = await _async_acquire_token_for_client(
|
|
258
|
+
self._msal_auth_client,
|
|
234
259
|
["api://AzureAdTokenExchange/.default"],
|
|
235
260
|
data={"fmi_path": agent_app_instance_id},
|
|
236
261
|
)
|
|
@@ -281,8 +306,8 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
281
306
|
client_credential={"client_assertion": agent_token_result},
|
|
282
307
|
)
|
|
283
308
|
|
|
284
|
-
agentic_instance_token =
|
|
285
|
-
["api://AzureAdTokenExchange/.default"]
|
|
309
|
+
agentic_instance_token = await _async_acquire_token_for_client(
|
|
310
|
+
instance_app, ["api://AzureAdTokenExchange/.default"]
|
|
286
311
|
)
|
|
287
312
|
|
|
288
313
|
if not agentic_instance_token:
|
|
@@ -308,28 +333,28 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
308
333
|
return agentic_instance_token["access_token"], agent_token_result
|
|
309
334
|
|
|
310
335
|
async def get_agentic_user_token(
|
|
311
|
-
self, agent_app_instance_id: str,
|
|
336
|
+
self, agent_app_instance_id: str, agentic_user_id: str, scopes: list[str]
|
|
312
337
|
) -> Optional[str]:
|
|
313
|
-
"""Gets the agentic user token for the given agent application instance ID and user
|
|
338
|
+
"""Gets the agentic user token for the given agent application instance ID and agentic user Id and the scopes.
|
|
314
339
|
|
|
315
340
|
:param agent_app_instance_id: The agent application instance ID.
|
|
316
341
|
:type agent_app_instance_id: str
|
|
317
|
-
:param
|
|
318
|
-
:type
|
|
342
|
+
:param agentic_user_id: The agentic user ID.
|
|
343
|
+
:type agentic_user_id: str
|
|
319
344
|
:param scopes: The scopes to request for the token.
|
|
320
345
|
:type scopes: list[str]
|
|
321
346
|
:return: The agentic user token, or None if not found.
|
|
322
347
|
:rtype: Optional[str]
|
|
323
348
|
"""
|
|
324
|
-
if not agent_app_instance_id or not
|
|
349
|
+
if not agent_app_instance_id or not agentic_user_id:
|
|
325
350
|
raise ValueError(
|
|
326
|
-
"Agent application instance Id and user
|
|
351
|
+
"Agent application instance Id and agentic user Id must be provided."
|
|
327
352
|
)
|
|
328
353
|
|
|
329
354
|
logger.info(
|
|
330
|
-
"Attempting to get agentic user token from agent_app_instance_id %s and
|
|
355
|
+
"Attempting to get agentic user token from agent_app_instance_id %s and agentic_user_id %s",
|
|
331
356
|
agent_app_instance_id,
|
|
332
|
-
|
|
357
|
+
agentic_user_id,
|
|
333
358
|
)
|
|
334
359
|
instance_token, agent_token = await self.get_agentic_instance_token(
|
|
335
360
|
agent_app_instance_id
|
|
@@ -337,12 +362,12 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
337
362
|
|
|
338
363
|
if not instance_token or not agent_token:
|
|
339
364
|
logger.error(
|
|
340
|
-
"Failed to acquire instance token or agent token for agent_app_instance_id %s and
|
|
365
|
+
"Failed to acquire instance token or agent token for agent_app_instance_id %s and agentic_user_id %s",
|
|
341
366
|
agent_app_instance_id,
|
|
342
|
-
|
|
367
|
+
agentic_user_id,
|
|
343
368
|
)
|
|
344
369
|
raise Exception(
|
|
345
|
-
f"Failed to acquire instance token or agent token for agent_app_instance_id {agent_app_instance_id} and
|
|
370
|
+
f"Failed to acquire instance token or agent token for agent_app_instance_id {agent_app_instance_id} and agentic_user_id {agentic_user_id}"
|
|
346
371
|
)
|
|
347
372
|
|
|
348
373
|
authority = (
|
|
@@ -356,14 +381,17 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
356
381
|
)
|
|
357
382
|
|
|
358
383
|
logger.info(
|
|
359
|
-
"Acquiring agentic user token for agent_app_instance_id %s and
|
|
384
|
+
"Acquiring agentic user token for agent_app_instance_id %s and agentic_user_id %s",
|
|
360
385
|
agent_app_instance_id,
|
|
361
|
-
|
|
386
|
+
agentic_user_id,
|
|
362
387
|
)
|
|
363
|
-
|
|
388
|
+
# MSAL in Python does not support async, so we use asyncio.to_thread to run it in
|
|
389
|
+
# a separate thread and avoid blocking the event loop
|
|
390
|
+
auth_result_payload = await _async_acquire_token_for_client(
|
|
391
|
+
instance_app,
|
|
364
392
|
scopes,
|
|
365
393
|
data={
|
|
366
|
-
"
|
|
394
|
+
"user_id": agentic_user_id,
|
|
367
395
|
"user_federated_identity_credential": instance_token,
|
|
368
396
|
"grant_type": "user_fic",
|
|
369
397
|
},
|
|
@@ -371,9 +399,9 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
371
399
|
|
|
372
400
|
if not auth_result_payload:
|
|
373
401
|
logger.error(
|
|
374
|
-
"Failed to acquire agentic user token for agent_app_instance_id %s and
|
|
402
|
+
"Failed to acquire agentic user token for agent_app_instance_id %s and agentic_user_id %s, %s",
|
|
375
403
|
agent_app_instance_id,
|
|
376
|
-
|
|
404
|
+
agentic_user_id,
|
|
377
405
|
auth_result_payload,
|
|
378
406
|
)
|
|
379
407
|
return None
|
|
@@ -381,9 +409,9 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
381
409
|
access_token = auth_result_payload.get("access_token")
|
|
382
410
|
if not access_token:
|
|
383
411
|
logger.error(
|
|
384
|
-
"Failed to acquire agentic user token for agent_app_instance_id %s and
|
|
412
|
+
"Failed to acquire agentic user token for agent_app_instance_id %s and agentic_user_id %s, %s",
|
|
385
413
|
agent_app_instance_id,
|
|
386
|
-
|
|
414
|
+
agentic_user_id,
|
|
387
415
|
auth_result_payload,
|
|
388
416
|
)
|
|
389
417
|
return None
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
# Licensed under the MIT License.
|
|
3
|
+
|
|
1
4
|
import re
|
|
2
5
|
from typing import Dict, List, Optional
|
|
3
6
|
from microsoft_agents.hosting.core import (
|
|
@@ -25,7 +28,7 @@ class MsalConnectionManager(Connections):
|
|
|
25
28
|
Initialize the MSAL connection manager.
|
|
26
29
|
|
|
27
30
|
:arg connections_configurations: A dictionary of connection configurations.
|
|
28
|
-
:type connections_configurations: Dict[str, AgentAuthConfiguration]
|
|
31
|
+
:type connections_configurations: Dict[str, :class:`microsoft_agents.hosting.core.AgentAuthConfiguration`]
|
|
29
32
|
:arg connections_map: A list of connection mappings.
|
|
30
33
|
:type connections_map: List[Dict[str, str]]
|
|
31
34
|
:raises ValueError: If no service connection configuration is provided.
|
|
@@ -61,9 +64,9 @@ class MsalConnectionManager(Connections):
|
|
|
61
64
|
Get the OAuth connection for the agent.
|
|
62
65
|
|
|
63
66
|
:arg connection_name: The name of the connection.
|
|
64
|
-
:type connection_name: str
|
|
67
|
+
:type connection_name: Optional[str]
|
|
65
68
|
:return: The OAuth connection for the agent.
|
|
66
|
-
:rtype: AccessTokenProviderBase
|
|
69
|
+
:rtype: :class:`microsoft_agents.hosting.core.AccessTokenProviderBase`
|
|
67
70
|
"""
|
|
68
71
|
# should never be None
|
|
69
72
|
return self._connections.get(connection_name, None)
|
|
@@ -71,6 +74,9 @@ class MsalConnectionManager(Connections):
|
|
|
71
74
|
def get_default_connection(self) -> AccessTokenProviderBase:
|
|
72
75
|
"""
|
|
73
76
|
Get the default OAuth connection for the agent.
|
|
77
|
+
|
|
78
|
+
:return: The default OAuth connection for the agent.
|
|
79
|
+
:rtype: :class:`microsoft_agents.hosting.core.AccessTokenProviderBase`
|
|
74
80
|
"""
|
|
75
81
|
# should never be None
|
|
76
82
|
return self._connections.get("SERVICE_CONNECTION", None)
|
|
@@ -82,11 +88,11 @@ class MsalConnectionManager(Connections):
|
|
|
82
88
|
Get the OAuth token provider for the agent.
|
|
83
89
|
|
|
84
90
|
:arg claims_identity: The claims identity of the bot.
|
|
85
|
-
:type claims_identity: ClaimsIdentity
|
|
91
|
+
:type claims_identity: :class:`microsoft_agents.hosting.core.ClaimsIdentity`
|
|
86
92
|
:arg service_url: The service URL of the bot.
|
|
87
93
|
:type service_url: str
|
|
88
94
|
:return: The OAuth token provider for the agent.
|
|
89
|
-
:rtype: AccessTokenProviderBase
|
|
95
|
+
:rtype: :class:`microsoft_agents.hosting.core.AccessTokenProviderBase`
|
|
90
96
|
:raises ValueError: If no connection is found for the given audience and service URL.
|
|
91
97
|
"""
|
|
92
98
|
if not claims_identity or not service_url:
|
|
@@ -127,5 +133,8 @@ class MsalConnectionManager(Connections):
|
|
|
127
133
|
def get_default_connection_configuration(self) -> AgentAuthConfiguration:
|
|
128
134
|
"""
|
|
129
135
|
Get the default connection configuration for the agent.
|
|
136
|
+
|
|
137
|
+
:return: The default connection configuration for the agent.
|
|
138
|
+
:rtype: :class:`microsoft_agents.hosting.core.AgentAuthConfiguration`
|
|
130
139
|
"""
|
|
131
140
|
return self._service_connection_configuration
|
microsoft_agents_authentication_msal-0.5.0/microsoft_agents_authentication_msal.egg-info/PKG-INFO
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: microsoft-agents-authentication-msal
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: A msal-based authentication library for Microsoft Agents
|
|
5
|
+
Author: Microsoft Corporation
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/microsoft/Agents
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: microsoft-agents-hosting-core==0.5.0
|
|
19
|
+
Requires-Dist: msal>=1.31.1
|
|
20
|
+
Requires-Dist: requests>=2.32.3
|
|
21
|
+
Requires-Dist: cryptography>=44.0.0
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
Dynamic: requires-dist
|
|
24
|
+
|
|
25
|
+
# Microsoft Agents MSAL Authentication
|
|
26
|
+
|
|
27
|
+
[](https://pypi.org/project/microsoft-agents-authentication-msal/)
|
|
28
|
+
|
|
29
|
+
Provides secure authentication for your agents using Microsoft Authentication Library (MSAL). It handles getting tokens from Azure AD so your agent can securely communicate with Microsoft services like Teams, Graph API, and other Azure resources.
|
|
30
|
+
|
|
31
|
+
# What is this?
|
|
32
|
+
|
|
33
|
+
This library is part of the **Microsoft 365 Agents SDK for Python** - a comprehensive framework for building enterprise-grade conversational AI agents. The SDK enables developers to create intelligent agents that work across multiple platforms including Microsoft Teams, M365 Copilot, Copilot Studio, and web chat, with support for third-party integrations like Slack, Facebook Messenger, and Twilio.
|
|
34
|
+
|
|
35
|
+
## Release Notes
|
|
36
|
+
<table style="width:100%">
|
|
37
|
+
<tr>
|
|
38
|
+
<th style="width:20%">Version</th>
|
|
39
|
+
<th style="width:20%">Date</th>
|
|
40
|
+
<th style="width:60%">Release Notes</th>
|
|
41
|
+
</tr>
|
|
42
|
+
<tr>
|
|
43
|
+
<td>0.5.0</td>
|
|
44
|
+
<td>2025-10-22</td>
|
|
45
|
+
<td>
|
|
46
|
+
<a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md">
|
|
47
|
+
0.5.0 Release Notes
|
|
48
|
+
</a>
|
|
49
|
+
</td>
|
|
50
|
+
</tr>
|
|
51
|
+
</table>
|
|
52
|
+
|
|
53
|
+
## Packages Overview
|
|
54
|
+
|
|
55
|
+
We offer the following PyPI packages to create conversational experiences based on Agents:
|
|
56
|
+
|
|
57
|
+
| Package Name | PyPI Version | Description |
|
|
58
|
+
|--------------|-------------|-------------|
|
|
59
|
+
| `microsoft-agents-activity` | [](https://pypi.org/project/microsoft-agents-activity/) | Types and validators implementing the Activity protocol spec. |
|
|
60
|
+
| `microsoft-agents-hosting-core` | [](https://pypi.org/project/microsoft-agents-hosting-core/) | Core library for Microsoft Agents hosting. |
|
|
61
|
+
| `microsoft-agents-hosting-aiohttp` | [](https://pypi.org/project/microsoft-agents-hosting-aiohttp/) | Configures aiohttp to run the Agent. |
|
|
62
|
+
| `microsoft-agents-hosting-teams` | [](https://pypi.org/project/microsoft-agents-hosting-teams/) | Provides classes to host an Agent for Teams. |
|
|
63
|
+
| `microsoft-agents-storage-blob` | [](https://pypi.org/project/microsoft-agents-storage-blob/) | Extension to use Azure Blob as storage. |
|
|
64
|
+
| `microsoft-agents-storage-cosmos` | [](https://pypi.org/project/microsoft-agents-storage-cosmos/) | Extension to use CosmosDB as storage. |
|
|
65
|
+
| `microsoft-agents-authentication-msal` | [](https://pypi.org/project/microsoft-agents-authentication-msal/) | MSAL-based authentication for Microsoft Agents. |
|
|
66
|
+
|
|
67
|
+
Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio:
|
|
68
|
+
|
|
69
|
+
| Package Name | PyPI Version | Description |
|
|
70
|
+
|--------------|-------------|-------------|
|
|
71
|
+
| `microsoft-agents-copilotstudio-client` | [](https://pypi.org/project/microsoft-agents-copilotstudio-client/) | Direct to Engine client to interact with Agents created in CopilotStudio |
|
|
72
|
+
|
|
73
|
+
## Installation
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pip install microsoft-agents-authentication-msal
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Quick Start
|
|
80
|
+
|
|
81
|
+
### Basic Setup with Client Secret
|
|
82
|
+
|
|
83
|
+
Define your client secrets in the ENV file
|
|
84
|
+
```python
|
|
85
|
+
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTID=client-id
|
|
86
|
+
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTSECRET=client-secret
|
|
87
|
+
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__TENANTID=tenant-id
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Load the Configuration (Code from [main.py Quickstart Sample](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/src/main.py))
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from .start_server import start_server
|
|
94
|
+
|
|
95
|
+
start_server(
|
|
96
|
+
agent_application=AGENT_APP,
|
|
97
|
+
auth_configuration=CONNECTION_MANAGER.get_default_connection_configuration(),
|
|
98
|
+
)
|
|
99
|
+
```
|
|
100
|
+
Then start the Agent (code snipped from (start_server.py Quickstart Sample](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/src/start_server.py)):
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
def start_server(
|
|
104
|
+
agent_application: AgentApplication, auth_configuration: AgentAuthConfiguration
|
|
105
|
+
):
|
|
106
|
+
async def entry_point(req: Request) -> Response:
|
|
107
|
+
agent: AgentApplication = req.app["agent_app"]
|
|
108
|
+
adapter: CloudAdapter = req.app["adapter"]
|
|
109
|
+
return await start_agent_process(
|
|
110
|
+
req,
|
|
111
|
+
agent,
|
|
112
|
+
adapter,
|
|
113
|
+
)
|
|
114
|
+
[...]
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Authentication Types
|
|
118
|
+
The M365 Agents SDK in Python supports the following Auth types:
|
|
119
|
+
```python
|
|
120
|
+
class AuthTypes(str, Enum):
|
|
121
|
+
certificate = "certificate"
|
|
122
|
+
certificate_subject_name = "CertificateSubjectName"
|
|
123
|
+
client_secret = "ClientSecret"
|
|
124
|
+
user_managed_identity = "UserManagedIdentity"
|
|
125
|
+
system_managed_identity = "SystemManagedIdentity"
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Key Classes
|
|
129
|
+
|
|
130
|
+
- **`MsalAuth`** - Core authentication provider using MSAL
|
|
131
|
+
- **`MsalConnectionManager`** - Manages multiple authentication connections
|
|
132
|
+
|
|
133
|
+
## Features
|
|
134
|
+
|
|
135
|
+
✅ **Multiple auth types** - Client secret, certificate, managed identity
|
|
136
|
+
✅ **Token caching** - Automatic token refresh and caching
|
|
137
|
+
✅ **Multi-tenant** - Support for different Azure AD tenants
|
|
138
|
+
✅ **Agent-to-agent** - Secure communication between agents
|
|
139
|
+
✅ **On-behalf-of** - Act on behalf of users
|
|
140
|
+
|
|
141
|
+
# Security Best Practices
|
|
142
|
+
|
|
143
|
+
- Store secrets in Azure Key Vault or environment variables
|
|
144
|
+
- Use managed identities when possible (no secrets to manage)
|
|
145
|
+
- Regularly rotate client secrets and certificates
|
|
146
|
+
- Use least-privilege principle for scopes and permissions
|
|
147
|
+
|
|
148
|
+
# Quick Links
|
|
149
|
+
|
|
150
|
+
- 📦 [All SDK Packages on PyPI](https://pypi.org/search/?q=microsoft-agents)
|
|
151
|
+
- 📖 [Complete Documentation](https://aka.ms/agents)
|
|
152
|
+
- 💡 [Python Samples Repository](https://github.com/microsoft/Agents/tree/main/samples/python)
|
|
153
|
+
- 🐛 [Report Issues](https://github.com/microsoft/Agents-for-python/issues)
|
|
154
|
+
|
|
155
|
+
# Sample Applications
|
|
156
|
+
Explore working examples in the [Python samples repository](https://github.com/microsoft/Agents/tree/main/samples/python):
|
|
157
|
+
|
|
158
|
+
|Name|Description|README|
|
|
159
|
+
|----|----|----|
|
|
160
|
+
|Quickstart|Simplest agent|[Quickstart](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/README.md)|
|
|
161
|
+
|Auto Sign In|Simple OAuth agent using Graph and GitHub|[auto-signin](https://github.com/microsoft/Agents/blob/main/samples/python/auto-signin/README.md)|
|
|
162
|
+
|OBO Authorization|OBO flow to access a Copilot Studio Agent|[obo-authorization](https://github.com/microsoft/Agents/blob/main/samples/python/obo-authorization/README.md)|
|
|
163
|
+
|Semantic Kernel Integration|A weather agent built with Semantic Kernel|[semantic-kernel-multiturn](https://github.com/microsoft/Agents/blob/main/samples/python/semantic-kernel-multiturn/README.md)|
|
|
164
|
+
|Streaming Agent|Streams OpenAI responses|[azure-ai-streaming](https://github.com/microsoft/Agents/blob/main/samples/python/azureai-streaming/README.md)|
|
|
165
|
+
|Copilot Studio Client|Console app to consume a Copilot Studio Agent|[copilotstudio-client](https://github.com/microsoft/Agents/blob/main/samples/python/copilotstudio-client/README.md)|
|
|
166
|
+
|Cards Agent|Agent that uses rich cards to enhance conversation design |[cards](https://github.com/microsoft/Agents/blob/main/samples/python/cards/README.md)|
|
|
@@ -6,11 +6,18 @@ build-backend = "setuptools.build_meta"
|
|
|
6
6
|
name = "microsoft-agents-authentication-msal"
|
|
7
7
|
dynamic = ["version", "dependencies"]
|
|
8
8
|
description = "A msal-based authentication library for Microsoft Agents"
|
|
9
|
+
readme = {file = "readme.md", content-type = "text/markdown"}
|
|
9
10
|
authors = [{name = "Microsoft Corporation"}]
|
|
10
|
-
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
requires-python = ">=3.10"
|
|
11
14
|
classifiers = [
|
|
12
15
|
"Programming Language :: Python :: 3",
|
|
13
|
-
"
|
|
16
|
+
"Programming Language :: Python :: 3.10",
|
|
17
|
+
"Programming Language :: Python :: 3.11",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"Programming Language :: Python :: 3.13",
|
|
20
|
+
"Programming Language :: Python :: 3.14",
|
|
14
21
|
"Operating System :: OS Independent",
|
|
15
22
|
]
|
|
16
23
|
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Microsoft Agents MSAL Authentication
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/microsoft-agents-authentication-msal/)
|
|
4
|
+
|
|
5
|
+
Provides secure authentication for your agents using Microsoft Authentication Library (MSAL). It handles getting tokens from Azure AD so your agent can securely communicate with Microsoft services like Teams, Graph API, and other Azure resources.
|
|
6
|
+
|
|
7
|
+
# What is this?
|
|
8
|
+
|
|
9
|
+
This library is part of the **Microsoft 365 Agents SDK for Python** - a comprehensive framework for building enterprise-grade conversational AI agents. The SDK enables developers to create intelligent agents that work across multiple platforms including Microsoft Teams, M365 Copilot, Copilot Studio, and web chat, with support for third-party integrations like Slack, Facebook Messenger, and Twilio.
|
|
10
|
+
|
|
11
|
+
## Release Notes
|
|
12
|
+
<table style="width:100%">
|
|
13
|
+
<tr>
|
|
14
|
+
<th style="width:20%">Version</th>
|
|
15
|
+
<th style="width:20%">Date</th>
|
|
16
|
+
<th style="width:60%">Release Notes</th>
|
|
17
|
+
</tr>
|
|
18
|
+
<tr>
|
|
19
|
+
<td>0.5.0</td>
|
|
20
|
+
<td>2025-10-22</td>
|
|
21
|
+
<td>
|
|
22
|
+
<a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md">
|
|
23
|
+
0.5.0 Release Notes
|
|
24
|
+
</a>
|
|
25
|
+
</td>
|
|
26
|
+
</tr>
|
|
27
|
+
</table>
|
|
28
|
+
|
|
29
|
+
## Packages Overview
|
|
30
|
+
|
|
31
|
+
We offer the following PyPI packages to create conversational experiences based on Agents:
|
|
32
|
+
|
|
33
|
+
| Package Name | PyPI Version | Description |
|
|
34
|
+
|--------------|-------------|-------------|
|
|
35
|
+
| `microsoft-agents-activity` | [](https://pypi.org/project/microsoft-agents-activity/) | Types and validators implementing the Activity protocol spec. |
|
|
36
|
+
| `microsoft-agents-hosting-core` | [](https://pypi.org/project/microsoft-agents-hosting-core/) | Core library for Microsoft Agents hosting. |
|
|
37
|
+
| `microsoft-agents-hosting-aiohttp` | [](https://pypi.org/project/microsoft-agents-hosting-aiohttp/) | Configures aiohttp to run the Agent. |
|
|
38
|
+
| `microsoft-agents-hosting-teams` | [](https://pypi.org/project/microsoft-agents-hosting-teams/) | Provides classes to host an Agent for Teams. |
|
|
39
|
+
| `microsoft-agents-storage-blob` | [](https://pypi.org/project/microsoft-agents-storage-blob/) | Extension to use Azure Blob as storage. |
|
|
40
|
+
| `microsoft-agents-storage-cosmos` | [](https://pypi.org/project/microsoft-agents-storage-cosmos/) | Extension to use CosmosDB as storage. |
|
|
41
|
+
| `microsoft-agents-authentication-msal` | [](https://pypi.org/project/microsoft-agents-authentication-msal/) | MSAL-based authentication for Microsoft Agents. |
|
|
42
|
+
|
|
43
|
+
Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio:
|
|
44
|
+
|
|
45
|
+
| Package Name | PyPI Version | Description |
|
|
46
|
+
|--------------|-------------|-------------|
|
|
47
|
+
| `microsoft-agents-copilotstudio-client` | [](https://pypi.org/project/microsoft-agents-copilotstudio-client/) | Direct to Engine client to interact with Agents created in CopilotStudio |
|
|
48
|
+
|
|
49
|
+
## Installation
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install microsoft-agents-authentication-msal
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Quick Start
|
|
56
|
+
|
|
57
|
+
### Basic Setup with Client Secret
|
|
58
|
+
|
|
59
|
+
Define your client secrets in the ENV file
|
|
60
|
+
```python
|
|
61
|
+
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTID=client-id
|
|
62
|
+
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTSECRET=client-secret
|
|
63
|
+
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__TENANTID=tenant-id
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Load the Configuration (Code from [main.py Quickstart Sample](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/src/main.py))
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from .start_server import start_server
|
|
70
|
+
|
|
71
|
+
start_server(
|
|
72
|
+
agent_application=AGENT_APP,
|
|
73
|
+
auth_configuration=CONNECTION_MANAGER.get_default_connection_configuration(),
|
|
74
|
+
)
|
|
75
|
+
```
|
|
76
|
+
Then start the Agent (code snipped from (start_server.py Quickstart Sample](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/src/start_server.py)):
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
def start_server(
|
|
80
|
+
agent_application: AgentApplication, auth_configuration: AgentAuthConfiguration
|
|
81
|
+
):
|
|
82
|
+
async def entry_point(req: Request) -> Response:
|
|
83
|
+
agent: AgentApplication = req.app["agent_app"]
|
|
84
|
+
adapter: CloudAdapter = req.app["adapter"]
|
|
85
|
+
return await start_agent_process(
|
|
86
|
+
req,
|
|
87
|
+
agent,
|
|
88
|
+
adapter,
|
|
89
|
+
)
|
|
90
|
+
[...]
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Authentication Types
|
|
94
|
+
The M365 Agents SDK in Python supports the following Auth types:
|
|
95
|
+
```python
|
|
96
|
+
class AuthTypes(str, Enum):
|
|
97
|
+
certificate = "certificate"
|
|
98
|
+
certificate_subject_name = "CertificateSubjectName"
|
|
99
|
+
client_secret = "ClientSecret"
|
|
100
|
+
user_managed_identity = "UserManagedIdentity"
|
|
101
|
+
system_managed_identity = "SystemManagedIdentity"
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Key Classes
|
|
105
|
+
|
|
106
|
+
- **`MsalAuth`** - Core authentication provider using MSAL
|
|
107
|
+
- **`MsalConnectionManager`** - Manages multiple authentication connections
|
|
108
|
+
|
|
109
|
+
## Features
|
|
110
|
+
|
|
111
|
+
✅ **Multiple auth types** - Client secret, certificate, managed identity
|
|
112
|
+
✅ **Token caching** - Automatic token refresh and caching
|
|
113
|
+
✅ **Multi-tenant** - Support for different Azure AD tenants
|
|
114
|
+
✅ **Agent-to-agent** - Secure communication between agents
|
|
115
|
+
✅ **On-behalf-of** - Act on behalf of users
|
|
116
|
+
|
|
117
|
+
# Security Best Practices
|
|
118
|
+
|
|
119
|
+
- Store secrets in Azure Key Vault or environment variables
|
|
120
|
+
- Use managed identities when possible (no secrets to manage)
|
|
121
|
+
- Regularly rotate client secrets and certificates
|
|
122
|
+
- Use least-privilege principle for scopes and permissions
|
|
123
|
+
|
|
124
|
+
# Quick Links
|
|
125
|
+
|
|
126
|
+
- 📦 [All SDK Packages on PyPI](https://pypi.org/search/?q=microsoft-agents)
|
|
127
|
+
- 📖 [Complete Documentation](https://aka.ms/agents)
|
|
128
|
+
- 💡 [Python Samples Repository](https://github.com/microsoft/Agents/tree/main/samples/python)
|
|
129
|
+
- 🐛 [Report Issues](https://github.com/microsoft/Agents-for-python/issues)
|
|
130
|
+
|
|
131
|
+
# Sample Applications
|
|
132
|
+
Explore working examples in the [Python samples repository](https://github.com/microsoft/Agents/tree/main/samples/python):
|
|
133
|
+
|
|
134
|
+
|Name|Description|README|
|
|
135
|
+
|----|----|----|
|
|
136
|
+
|Quickstart|Simplest agent|[Quickstart](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/README.md)|
|
|
137
|
+
|Auto Sign In|Simple OAuth agent using Graph and GitHub|[auto-signin](https://github.com/microsoft/Agents/blob/main/samples/python/auto-signin/README.md)|
|
|
138
|
+
|OBO Authorization|OBO flow to access a Copilot Studio Agent|[obo-authorization](https://github.com/microsoft/Agents/blob/main/samples/python/obo-authorization/README.md)|
|
|
139
|
+
|Semantic Kernel Integration|A weather agent built with Semantic Kernel|[semantic-kernel-multiturn](https://github.com/microsoft/Agents/blob/main/samples/python/semantic-kernel-multiturn/README.md)|
|
|
140
|
+
|Streaming Agent|Streams OpenAI responses|[azure-ai-streaming](https://github.com/microsoft/Agents/blob/main/samples/python/azureai-streaming/README.md)|
|
|
141
|
+
|Copilot Studio Client|Console app to consume a Copilot Studio Agent|[copilotstudio-client](https://github.com/microsoft/Agents/blob/main/samples/python/copilotstudio-client/README.md)|
|
|
142
|
+
|Cards Agent|Agent that uses rich cards to enhance conversation design |[cards](https://github.com/microsoft/Agents/blob/main/samples/python/cards/README.md)|
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: microsoft-agents-authentication-msal
|
|
3
|
-
Version: 0.4.0.dev16
|
|
4
|
-
Summary: A msal-based authentication library for Microsoft Agents
|
|
5
|
-
Author: Microsoft Corporation
|
|
6
|
-
Project-URL: Homepage, https://github.com/microsoft/Agents
|
|
7
|
-
Classifier: Programming Language :: Python :: 3
|
|
8
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
-
Classifier: Operating System :: OS Independent
|
|
10
|
-
Requires-Python: >=3.9
|
|
11
|
-
Requires-Dist: microsoft-agents-hosting-core==0.4.0.dev16
|
|
12
|
-
Requires-Dist: msal>=1.31.1
|
|
13
|
-
Requires-Dist: requests>=2.32.3
|
|
14
|
-
Requires-Dist: cryptography>=44.0.0
|
|
15
|
-
Dynamic: requires-dist
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: microsoft-agents-authentication-msal
|
|
3
|
-
Version: 0.4.0.dev16
|
|
4
|
-
Summary: A msal-based authentication library for Microsoft Agents
|
|
5
|
-
Author: Microsoft Corporation
|
|
6
|
-
Project-URL: Homepage, https://github.com/microsoft/Agents
|
|
7
|
-
Classifier: Programming Language :: Python :: 3
|
|
8
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
-
Classifier: Operating System :: OS Independent
|
|
10
|
-
Requires-Python: >=3.9
|
|
11
|
-
Requires-Dist: microsoft-agents-hosting-core==0.4.0.dev16
|
|
12
|
-
Requires-Dist: msal>=1.31.1
|
|
13
|
-
Requires-Dist: requests>=2.32.3
|
|
14
|
-
Requires-Dist: cryptography>=44.0.0
|
|
15
|
-
Dynamic: requires-dist
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|