microsoft-agents-authentication-msal 0.5.0.dev3__tar.gz → 0.5.0.dev7__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.dev7/LICENSE +21 -0
- microsoft_agents_authentication_msal-0.5.0.dev7/PKG-INFO +134 -0
- {microsoft_agents_authentication_msal-0.5.0.dev3 → microsoft_agents_authentication_msal-0.5.0.dev7}/microsoft_agents/authentication/msal/msal_connection_manager.py +11 -5
- microsoft_agents_authentication_msal-0.5.0.dev7/microsoft_agents_authentication_msal.egg-info/PKG-INFO +134 -0
- {microsoft_agents_authentication_msal-0.5.0.dev3 → microsoft_agents_authentication_msal-0.5.0.dev7}/microsoft_agents_authentication_msal.egg-info/SOURCES.txt +2 -0
- {microsoft_agents_authentication_msal-0.5.0.dev3 → microsoft_agents_authentication_msal-0.5.0.dev7}/microsoft_agents_authentication_msal.egg-info/requires.txt +1 -1
- {microsoft_agents_authentication_msal-0.5.0.dev3 → microsoft_agents_authentication_msal-0.5.0.dev7}/pyproject.toml +3 -1
- microsoft_agents_authentication_msal-0.5.0.dev7/readme.md +115 -0
- microsoft_agents_authentication_msal-0.5.0.dev3/PKG-INFO +0 -15
- microsoft_agents_authentication_msal-0.5.0.dev3/microsoft_agents_authentication_msal.egg-info/PKG-INFO +0 -15
- {microsoft_agents_authentication_msal-0.5.0.dev3 → microsoft_agents_authentication_msal-0.5.0.dev7}/microsoft_agents/authentication/msal/__init__.py +0 -0
- {microsoft_agents_authentication_msal-0.5.0.dev3 → microsoft_agents_authentication_msal-0.5.0.dev7}/microsoft_agents/authentication/msal/msal_auth.py +0 -0
- {microsoft_agents_authentication_msal-0.5.0.dev3 → microsoft_agents_authentication_msal-0.5.0.dev7}/microsoft_agents_authentication_msal.egg-info/dependency_links.txt +0 -0
- {microsoft_agents_authentication_msal-0.5.0.dev3 → microsoft_agents_authentication_msal-0.5.0.dev7}/microsoft_agents_authentication_msal.egg-info/top_level.txt +0 -0
- {microsoft_agents_authentication_msal-0.5.0.dev3 → microsoft_agents_authentication_msal-0.5.0.dev7}/setup.cfg +0 -0
- {microsoft_agents_authentication_msal-0.5.0.dev3 → microsoft_agents_authentication_msal-0.5.0.dev7}/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,134 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: microsoft-agents-authentication-msal
|
|
3
|
+
Version: 0.5.0.dev7
|
|
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: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: microsoft-agents-hosting-core==0.5.0.dev7
|
|
14
|
+
Requires-Dist: msal>=1.31.1
|
|
15
|
+
Requires-Dist: requests>=2.32.3
|
|
16
|
+
Requires-Dist: cryptography>=44.0.0
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
Dynamic: requires-dist
|
|
19
|
+
|
|
20
|
+
# Microsoft Agents MSAL Authentication
|
|
21
|
+
|
|
22
|
+
[](https://pypi.org/project/microsoft-agents-authentication-msal/)
|
|
23
|
+
|
|
24
|
+
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.
|
|
25
|
+
|
|
26
|
+
# What is this?
|
|
27
|
+
|
|
28
|
+
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.
|
|
29
|
+
|
|
30
|
+
## Packages Overview
|
|
31
|
+
|
|
32
|
+
We offer the following PyPI packages to create conversational experiences based on Agents:
|
|
33
|
+
|
|
34
|
+
| Package Name | PyPI Version | Description |
|
|
35
|
+
|--------------|-------------|-------------|
|
|
36
|
+
| `microsoft-agents-activity` | [](https://pypi.org/project/microsoft-agents-activity/) | Types and validators implementing the Activity protocol spec. |
|
|
37
|
+
| `microsoft-agents-hosting-core` | [](https://pypi.org/project/microsoft-agents-hosting-core/) | Core library for Microsoft Agents hosting. |
|
|
38
|
+
| `microsoft-agents-hosting-aiohttp` | [](https://pypi.org/project/microsoft-agents-hosting-aiohttp/) | Configures aiohttp to run the Agent. |
|
|
39
|
+
| `microsoft-agents-hosting-teams` | [](https://pypi.org/project/microsoft-agents-hosting-teams/) | Provides classes to host an Agent for Teams. |
|
|
40
|
+
| `microsoft-agents-storage-blob` | [](https://pypi.org/project/microsoft-agents-storage-blob/) | Extension to use Azure Blob as storage. |
|
|
41
|
+
| `microsoft-agents-storage-cosmos` | [](https://pypi.org/project/microsoft-agents-storage-cosmos/) | Extension to use CosmosDB as storage. |
|
|
42
|
+
| `microsoft-agents-authentication-msal` | [](https://pypi.org/project/microsoft-agents-authentication-msal/) | MSAL-based authentication for Microsoft Agents. |
|
|
43
|
+
|
|
44
|
+
Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio:
|
|
45
|
+
|
|
46
|
+
| Package Name | PyPI Version | Description |
|
|
47
|
+
|--------------|-------------|-------------|
|
|
48
|
+
| `microsoft-agents-copilotstudio-client` | [](https://pypi.org/project/microsoft-agents-copilotstudio-client/) | Direct to Engine client to interact with Agents created in CopilotStudio |
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install microsoft-agents-authentication-msal
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Quick Start
|
|
57
|
+
|
|
58
|
+
### Basic Setup with Client Secret
|
|
59
|
+
|
|
60
|
+
Define your client secrets in the ENV file
|
|
61
|
+
```python
|
|
62
|
+
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTID=client-id
|
|
63
|
+
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTSECRET=client-secret
|
|
64
|
+
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__TENANTID=tenant-id
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Load the Configuration (Code from [main.py Quickstart Sample](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/src/main.py))
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from .start_server import start_server
|
|
71
|
+
|
|
72
|
+
start_server(
|
|
73
|
+
agent_application=AGENT_APP,
|
|
74
|
+
auth_configuration=CONNECTION_MANAGER.get_default_connection_configuration(),
|
|
75
|
+
)
|
|
76
|
+
```
|
|
77
|
+
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)):
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
def start_server(
|
|
81
|
+
agent_application: AgentApplication, auth_configuration: AgentAuthConfiguration
|
|
82
|
+
):
|
|
83
|
+
async def entry_point(req: Request) -> Response:
|
|
84
|
+
agent: AgentApplication = req.app["agent_app"]
|
|
85
|
+
adapter: CloudAdapter = req.app["adapter"]
|
|
86
|
+
return await start_agent_process(
|
|
87
|
+
req,
|
|
88
|
+
agent,
|
|
89
|
+
adapter,
|
|
90
|
+
)
|
|
91
|
+
[...]
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Authentication Types
|
|
95
|
+
The M365 Agents SDK in Python supports the following Auth types:
|
|
96
|
+
```python
|
|
97
|
+
class AuthTypes(str, Enum):
|
|
98
|
+
certificate = "certificate"
|
|
99
|
+
certificate_subject_name = "CertificateSubjectName"
|
|
100
|
+
client_secret = "ClientSecret"
|
|
101
|
+
user_managed_identity = "UserManagedIdentity"
|
|
102
|
+
system_managed_identity = "SystemManagedIdentity"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Key Classes
|
|
106
|
+
|
|
107
|
+
- **`MsalAuth`** - Core authentication provider using MSAL
|
|
108
|
+
- **`MsalConnectionManager`** - Manages multiple authentication connections
|
|
109
|
+
|
|
110
|
+
## Features
|
|
111
|
+
|
|
112
|
+
✅ **Multiple auth types** - Client secret, certificate, managed identity
|
|
113
|
+
✅ **Token caching** - Automatic token refresh and caching
|
|
114
|
+
✅ **Multi-tenant** - Support for different Azure AD tenants
|
|
115
|
+
✅ **Agent-to-agent** - Secure communication between agents
|
|
116
|
+
✅ **On-behalf-of** - Act on behalf of users
|
|
117
|
+
|
|
118
|
+
# Security Best Practices
|
|
119
|
+
|
|
120
|
+
- Store secrets in Azure Key Vault or environment variables
|
|
121
|
+
- Use managed identities when possible (no secrets to manage)
|
|
122
|
+
- Regularly rotate client secrets and certificates
|
|
123
|
+
- Use least-privilege principle for scopes and permissions
|
|
124
|
+
|
|
125
|
+
# Quick Links
|
|
126
|
+
|
|
127
|
+
- 📦 [All SDK Packages on PyPI](https://pypi.org/search/?q=microsoft-agents)
|
|
128
|
+
- 📖 [Complete Documentation](https://aka.ms/agents)
|
|
129
|
+
- 💡 [Python Samples Repository](https://github.com/microsoft/Agents/tree/main/samples/python)
|
|
130
|
+
- 🐛 [Report Issues](https://github.com/microsoft/Agents-for-python/issues)
|
|
131
|
+
|
|
132
|
+
# Sample Applications
|
|
133
|
+
|
|
134
|
+
w
|
|
@@ -28,7 +28,7 @@ class MsalConnectionManager(Connections):
|
|
|
28
28
|
Initialize the MSAL connection manager.
|
|
29
29
|
|
|
30
30
|
:arg connections_configurations: A dictionary of connection configurations.
|
|
31
|
-
:type connections_configurations: Dict[str, AgentAuthConfiguration]
|
|
31
|
+
:type connections_configurations: Dict[str, :class:`microsoft_agents.hosting.core.AgentAuthConfiguration`]
|
|
32
32
|
:arg connections_map: A list of connection mappings.
|
|
33
33
|
:type connections_map: List[Dict[str, str]]
|
|
34
34
|
:raises ValueError: If no service connection configuration is provided.
|
|
@@ -64,9 +64,9 @@ class MsalConnectionManager(Connections):
|
|
|
64
64
|
Get the OAuth connection for the agent.
|
|
65
65
|
|
|
66
66
|
:arg connection_name: The name of the connection.
|
|
67
|
-
:type connection_name: str
|
|
67
|
+
:type connection_name: Optional[str]
|
|
68
68
|
:return: The OAuth connection for the agent.
|
|
69
|
-
:rtype: AccessTokenProviderBase
|
|
69
|
+
:rtype: :class:`microsoft_agents.hosting.core.AccessTokenProviderBase`
|
|
70
70
|
"""
|
|
71
71
|
# should never be None
|
|
72
72
|
return self._connections.get(connection_name, None)
|
|
@@ -74,6 +74,9 @@ class MsalConnectionManager(Connections):
|
|
|
74
74
|
def get_default_connection(self) -> AccessTokenProviderBase:
|
|
75
75
|
"""
|
|
76
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`
|
|
77
80
|
"""
|
|
78
81
|
# should never be None
|
|
79
82
|
return self._connections.get("SERVICE_CONNECTION", None)
|
|
@@ -85,11 +88,11 @@ class MsalConnectionManager(Connections):
|
|
|
85
88
|
Get the OAuth token provider for the agent.
|
|
86
89
|
|
|
87
90
|
:arg claims_identity: The claims identity of the bot.
|
|
88
|
-
:type claims_identity: ClaimsIdentity
|
|
91
|
+
:type claims_identity: :class:`microsoft_agents.hosting.core.ClaimsIdentity`
|
|
89
92
|
:arg service_url: The service URL of the bot.
|
|
90
93
|
:type service_url: str
|
|
91
94
|
:return: The OAuth token provider for the agent.
|
|
92
|
-
:rtype: AccessTokenProviderBase
|
|
95
|
+
:rtype: :class:`microsoft_agents.hosting.core.AccessTokenProviderBase`
|
|
93
96
|
:raises ValueError: If no connection is found for the given audience and service URL.
|
|
94
97
|
"""
|
|
95
98
|
if not claims_identity or not service_url:
|
|
@@ -130,5 +133,8 @@ class MsalConnectionManager(Connections):
|
|
|
130
133
|
def get_default_connection_configuration(self) -> AgentAuthConfiguration:
|
|
131
134
|
"""
|
|
132
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`
|
|
133
139
|
"""
|
|
134
140
|
return self._service_connection_configuration
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: microsoft-agents-authentication-msal
|
|
3
|
+
Version: 0.5.0.dev7
|
|
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: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: microsoft-agents-hosting-core==0.5.0.dev7
|
|
14
|
+
Requires-Dist: msal>=1.31.1
|
|
15
|
+
Requires-Dist: requests>=2.32.3
|
|
16
|
+
Requires-Dist: cryptography>=44.0.0
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
Dynamic: requires-dist
|
|
19
|
+
|
|
20
|
+
# Microsoft Agents MSAL Authentication
|
|
21
|
+
|
|
22
|
+
[](https://pypi.org/project/microsoft-agents-authentication-msal/)
|
|
23
|
+
|
|
24
|
+
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.
|
|
25
|
+
|
|
26
|
+
# What is this?
|
|
27
|
+
|
|
28
|
+
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.
|
|
29
|
+
|
|
30
|
+
## Packages Overview
|
|
31
|
+
|
|
32
|
+
We offer the following PyPI packages to create conversational experiences based on Agents:
|
|
33
|
+
|
|
34
|
+
| Package Name | PyPI Version | Description |
|
|
35
|
+
|--------------|-------------|-------------|
|
|
36
|
+
| `microsoft-agents-activity` | [](https://pypi.org/project/microsoft-agents-activity/) | Types and validators implementing the Activity protocol spec. |
|
|
37
|
+
| `microsoft-agents-hosting-core` | [](https://pypi.org/project/microsoft-agents-hosting-core/) | Core library for Microsoft Agents hosting. |
|
|
38
|
+
| `microsoft-agents-hosting-aiohttp` | [](https://pypi.org/project/microsoft-agents-hosting-aiohttp/) | Configures aiohttp to run the Agent. |
|
|
39
|
+
| `microsoft-agents-hosting-teams` | [](https://pypi.org/project/microsoft-agents-hosting-teams/) | Provides classes to host an Agent for Teams. |
|
|
40
|
+
| `microsoft-agents-storage-blob` | [](https://pypi.org/project/microsoft-agents-storage-blob/) | Extension to use Azure Blob as storage. |
|
|
41
|
+
| `microsoft-agents-storage-cosmos` | [](https://pypi.org/project/microsoft-agents-storage-cosmos/) | Extension to use CosmosDB as storage. |
|
|
42
|
+
| `microsoft-agents-authentication-msal` | [](https://pypi.org/project/microsoft-agents-authentication-msal/) | MSAL-based authentication for Microsoft Agents. |
|
|
43
|
+
|
|
44
|
+
Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio:
|
|
45
|
+
|
|
46
|
+
| Package Name | PyPI Version | Description |
|
|
47
|
+
|--------------|-------------|-------------|
|
|
48
|
+
| `microsoft-agents-copilotstudio-client` | [](https://pypi.org/project/microsoft-agents-copilotstudio-client/) | Direct to Engine client to interact with Agents created in CopilotStudio |
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install microsoft-agents-authentication-msal
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Quick Start
|
|
57
|
+
|
|
58
|
+
### Basic Setup with Client Secret
|
|
59
|
+
|
|
60
|
+
Define your client secrets in the ENV file
|
|
61
|
+
```python
|
|
62
|
+
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTID=client-id
|
|
63
|
+
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTSECRET=client-secret
|
|
64
|
+
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__TENANTID=tenant-id
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Load the Configuration (Code from [main.py Quickstart Sample](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/src/main.py))
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from .start_server import start_server
|
|
71
|
+
|
|
72
|
+
start_server(
|
|
73
|
+
agent_application=AGENT_APP,
|
|
74
|
+
auth_configuration=CONNECTION_MANAGER.get_default_connection_configuration(),
|
|
75
|
+
)
|
|
76
|
+
```
|
|
77
|
+
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)):
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
def start_server(
|
|
81
|
+
agent_application: AgentApplication, auth_configuration: AgentAuthConfiguration
|
|
82
|
+
):
|
|
83
|
+
async def entry_point(req: Request) -> Response:
|
|
84
|
+
agent: AgentApplication = req.app["agent_app"]
|
|
85
|
+
adapter: CloudAdapter = req.app["adapter"]
|
|
86
|
+
return await start_agent_process(
|
|
87
|
+
req,
|
|
88
|
+
agent,
|
|
89
|
+
adapter,
|
|
90
|
+
)
|
|
91
|
+
[...]
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Authentication Types
|
|
95
|
+
The M365 Agents SDK in Python supports the following Auth types:
|
|
96
|
+
```python
|
|
97
|
+
class AuthTypes(str, Enum):
|
|
98
|
+
certificate = "certificate"
|
|
99
|
+
certificate_subject_name = "CertificateSubjectName"
|
|
100
|
+
client_secret = "ClientSecret"
|
|
101
|
+
user_managed_identity = "UserManagedIdentity"
|
|
102
|
+
system_managed_identity = "SystemManagedIdentity"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Key Classes
|
|
106
|
+
|
|
107
|
+
- **`MsalAuth`** - Core authentication provider using MSAL
|
|
108
|
+
- **`MsalConnectionManager`** - Manages multiple authentication connections
|
|
109
|
+
|
|
110
|
+
## Features
|
|
111
|
+
|
|
112
|
+
✅ **Multiple auth types** - Client secret, certificate, managed identity
|
|
113
|
+
✅ **Token caching** - Automatic token refresh and caching
|
|
114
|
+
✅ **Multi-tenant** - Support for different Azure AD tenants
|
|
115
|
+
✅ **Agent-to-agent** - Secure communication between agents
|
|
116
|
+
✅ **On-behalf-of** - Act on behalf of users
|
|
117
|
+
|
|
118
|
+
# Security Best Practices
|
|
119
|
+
|
|
120
|
+
- Store secrets in Azure Key Vault or environment variables
|
|
121
|
+
- Use managed identities when possible (no secrets to manage)
|
|
122
|
+
- Regularly rotate client secrets and certificates
|
|
123
|
+
- Use least-privilege principle for scopes and permissions
|
|
124
|
+
|
|
125
|
+
# Quick Links
|
|
126
|
+
|
|
127
|
+
- 📦 [All SDK Packages on PyPI](https://pypi.org/search/?q=microsoft-agents)
|
|
128
|
+
- 📖 [Complete Documentation](https://aka.ms/agents)
|
|
129
|
+
- 💡 [Python Samples Repository](https://github.com/microsoft/Agents/tree/main/samples/python)
|
|
130
|
+
- 🐛 [Report Issues](https://github.com/microsoft/Agents-for-python/issues)
|
|
131
|
+
|
|
132
|
+
# Sample Applications
|
|
133
|
+
|
|
134
|
+
w
|
|
@@ -6,11 +6,13 @@ 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"}]
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
10
13
|
requires-python = ">=3.9"
|
|
11
14
|
classifiers = [
|
|
12
15
|
"Programming Language :: Python :: 3",
|
|
13
|
-
"License :: OSI Approved :: MIT License",
|
|
14
16
|
"Operating System :: OS Independent",
|
|
15
17
|
]
|
|
16
18
|
|
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
## Packages Overview
|
|
12
|
+
|
|
13
|
+
We offer the following PyPI packages to create conversational experiences based on Agents:
|
|
14
|
+
|
|
15
|
+
| Package Name | PyPI Version | Description |
|
|
16
|
+
|--------------|-------------|-------------|
|
|
17
|
+
| `microsoft-agents-activity` | [](https://pypi.org/project/microsoft-agents-activity/) | Types and validators implementing the Activity protocol spec. |
|
|
18
|
+
| `microsoft-agents-hosting-core` | [](https://pypi.org/project/microsoft-agents-hosting-core/) | Core library for Microsoft Agents hosting. |
|
|
19
|
+
| `microsoft-agents-hosting-aiohttp` | [](https://pypi.org/project/microsoft-agents-hosting-aiohttp/) | Configures aiohttp to run the Agent. |
|
|
20
|
+
| `microsoft-agents-hosting-teams` | [](https://pypi.org/project/microsoft-agents-hosting-teams/) | Provides classes to host an Agent for Teams. |
|
|
21
|
+
| `microsoft-agents-storage-blob` | [](https://pypi.org/project/microsoft-agents-storage-blob/) | Extension to use Azure Blob as storage. |
|
|
22
|
+
| `microsoft-agents-storage-cosmos` | [](https://pypi.org/project/microsoft-agents-storage-cosmos/) | Extension to use CosmosDB as storage. |
|
|
23
|
+
| `microsoft-agents-authentication-msal` | [](https://pypi.org/project/microsoft-agents-authentication-msal/) | MSAL-based authentication for Microsoft Agents. |
|
|
24
|
+
|
|
25
|
+
Additionally we provide a Copilot Studio Client, to interact with Agents created in CopilotStudio:
|
|
26
|
+
|
|
27
|
+
| Package Name | PyPI Version | Description |
|
|
28
|
+
|--------------|-------------|-------------|
|
|
29
|
+
| `microsoft-agents-copilotstudio-client` | [](https://pypi.org/project/microsoft-agents-copilotstudio-client/) | Direct to Engine client to interact with Agents created in CopilotStudio |
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install microsoft-agents-authentication-msal
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
### Basic Setup with Client Secret
|
|
40
|
+
|
|
41
|
+
Define your client secrets in the ENV file
|
|
42
|
+
```python
|
|
43
|
+
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTID=client-id
|
|
44
|
+
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTSECRET=client-secret
|
|
45
|
+
CONNECTIONS__SERVICE_CONNECTION__SETTINGS__TENANTID=tenant-id
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Load the Configuration (Code from [main.py Quickstart Sample](https://github.com/microsoft/Agents/blob/main/samples/python/quickstart/src/main.py))
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from .start_server import start_server
|
|
52
|
+
|
|
53
|
+
start_server(
|
|
54
|
+
agent_application=AGENT_APP,
|
|
55
|
+
auth_configuration=CONNECTION_MANAGER.get_default_connection_configuration(),
|
|
56
|
+
)
|
|
57
|
+
```
|
|
58
|
+
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)):
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
def start_server(
|
|
62
|
+
agent_application: AgentApplication, auth_configuration: AgentAuthConfiguration
|
|
63
|
+
):
|
|
64
|
+
async def entry_point(req: Request) -> Response:
|
|
65
|
+
agent: AgentApplication = req.app["agent_app"]
|
|
66
|
+
adapter: CloudAdapter = req.app["adapter"]
|
|
67
|
+
return await start_agent_process(
|
|
68
|
+
req,
|
|
69
|
+
agent,
|
|
70
|
+
adapter,
|
|
71
|
+
)
|
|
72
|
+
[...]
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Authentication Types
|
|
76
|
+
The M365 Agents SDK in Python supports the following Auth types:
|
|
77
|
+
```python
|
|
78
|
+
class AuthTypes(str, Enum):
|
|
79
|
+
certificate = "certificate"
|
|
80
|
+
certificate_subject_name = "CertificateSubjectName"
|
|
81
|
+
client_secret = "ClientSecret"
|
|
82
|
+
user_managed_identity = "UserManagedIdentity"
|
|
83
|
+
system_managed_identity = "SystemManagedIdentity"
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Key Classes
|
|
87
|
+
|
|
88
|
+
- **`MsalAuth`** - Core authentication provider using MSAL
|
|
89
|
+
- **`MsalConnectionManager`** - Manages multiple authentication connections
|
|
90
|
+
|
|
91
|
+
## Features
|
|
92
|
+
|
|
93
|
+
✅ **Multiple auth types** - Client secret, certificate, managed identity
|
|
94
|
+
✅ **Token caching** - Automatic token refresh and caching
|
|
95
|
+
✅ **Multi-tenant** - Support for different Azure AD tenants
|
|
96
|
+
✅ **Agent-to-agent** - Secure communication between agents
|
|
97
|
+
✅ **On-behalf-of** - Act on behalf of users
|
|
98
|
+
|
|
99
|
+
# Security Best Practices
|
|
100
|
+
|
|
101
|
+
- Store secrets in Azure Key Vault or environment variables
|
|
102
|
+
- Use managed identities when possible (no secrets to manage)
|
|
103
|
+
- Regularly rotate client secrets and certificates
|
|
104
|
+
- Use least-privilege principle for scopes and permissions
|
|
105
|
+
|
|
106
|
+
# Quick Links
|
|
107
|
+
|
|
108
|
+
- 📦 [All SDK Packages on PyPI](https://pypi.org/search/?q=microsoft-agents)
|
|
109
|
+
- 📖 [Complete Documentation](https://aka.ms/agents)
|
|
110
|
+
- 💡 [Python Samples Repository](https://github.com/microsoft/Agents/tree/main/samples/python)
|
|
111
|
+
- 🐛 [Report Issues](https://github.com/microsoft/Agents-for-python/issues)
|
|
112
|
+
|
|
113
|
+
# Sample Applications
|
|
114
|
+
|
|
115
|
+
w
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: microsoft-agents-authentication-msal
|
|
3
|
-
Version: 0.5.0.dev3
|
|
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.5.0.dev3
|
|
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.5.0.dev3
|
|
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.5.0.dev3
|
|
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
|
|
File without changes
|