microsoft-agents-authentication-msal 1.5.0.dev11__tar.gz → 1.6.1.dev1__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.5.0.dev11/microsoft_agents_authentication_msal.egg-info → microsoft_agents_authentication_msal-1.6.1.dev1}/PKG-INFO +13 -2
- microsoft_agents_authentication_msal-1.6.1.dev1/VERSION.txt +1 -0
- microsoft_agents_authentication_msal-1.6.1.dev1/microsoft_agents/authentication/msal/__init__.py +12 -0
- {microsoft_agents_authentication_msal-1.5.0.dev11 → microsoft_agents_authentication_msal-1.6.1.dev1}/microsoft_agents/authentication/msal/msal_auth.py +39 -2
- microsoft_agents_authentication_msal-1.6.1.dev1/microsoft_agents/authentication/msal/msal_token_credential.py +58 -0
- {microsoft_agents_authentication_msal-1.5.0.dev11 → microsoft_agents_authentication_msal-1.6.1.dev1/microsoft_agents_authentication_msal.egg-info}/PKG-INFO +13 -2
- {microsoft_agents_authentication_msal-1.5.0.dev11 → microsoft_agents_authentication_msal-1.6.1.dev1}/microsoft_agents_authentication_msal.egg-info/SOURCES.txt +1 -0
- microsoft_agents_authentication_msal-1.6.1.dev1/microsoft_agents_authentication_msal.egg-info/requires.txt +4 -0
- {microsoft_agents_authentication_msal-1.5.0.dev11 → microsoft_agents_authentication_msal-1.6.1.dev1}/readme.md +10 -0
- {microsoft_agents_authentication_msal-1.5.0.dev11 → microsoft_agents_authentication_msal-1.6.1.dev1}/setup.py +1 -0
- microsoft_agents_authentication_msal-1.5.0.dev11/VERSION.txt +0 -1
- microsoft_agents_authentication_msal-1.5.0.dev11/microsoft_agents/authentication/msal/__init__.py +0 -7
- microsoft_agents_authentication_msal-1.5.0.dev11/microsoft_agents_authentication_msal.egg-info/requires.txt +0 -3
- {microsoft_agents_authentication_msal-1.5.0.dev11 → microsoft_agents_authentication_msal-1.6.1.dev1}/LICENSE +0 -0
- {microsoft_agents_authentication_msal-1.5.0.dev11 → microsoft_agents_authentication_msal-1.6.1.dev1}/MANIFEST.in +0 -0
- {microsoft_agents_authentication_msal-1.5.0.dev11 → microsoft_agents_authentication_msal-1.6.1.dev1}/microsoft_agents/authentication/msal/errors/__init__.py +0 -0
- {microsoft_agents_authentication_msal-1.5.0.dev11 → microsoft_agents_authentication_msal-1.6.1.dev1}/microsoft_agents/authentication/msal/errors/error_resources.py +0 -0
- {microsoft_agents_authentication_msal-1.5.0.dev11 → microsoft_agents_authentication_msal-1.6.1.dev1}/microsoft_agents/authentication/msal/msal_connection_manager.py +0 -0
- {microsoft_agents_authentication_msal-1.5.0.dev11 → microsoft_agents_authentication_msal-1.6.1.dev1}/microsoft_agents/authentication/msal/py.typed +0 -0
- {microsoft_agents_authentication_msal-1.5.0.dev11 → microsoft_agents_authentication_msal-1.6.1.dev1}/microsoft_agents_authentication_msal.egg-info/dependency_links.txt +0 -0
- {microsoft_agents_authentication_msal-1.5.0.dev11 → microsoft_agents_authentication_msal-1.6.1.dev1}/microsoft_agents_authentication_msal.egg-info/top_level.txt +0 -0
- {microsoft_agents_authentication_msal-1.5.0.dev11 → microsoft_agents_authentication_msal-1.6.1.dev1}/pyproject.toml +0 -0
- {microsoft_agents_authentication_msal-1.5.0.dev11 → microsoft_agents_authentication_msal-1.6.1.dev1}/setup.cfg +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.6.1.dev1
|
|
4
4
|
Summary: A msal-based authentication library for Microsoft Agents
|
|
5
5
|
Author: Microsoft Corporation
|
|
6
6
|
License-Expression: MIT
|
|
@@ -15,7 +15,8 @@ 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.6.1.dev1
|
|
19
|
+
Requires-Dist: azure-core
|
|
19
20
|
Requires-Dist: msal>=1.34.0
|
|
20
21
|
Requires-Dist: requests>=2.32.3
|
|
21
22
|
Dynamic: license-file
|
|
@@ -38,6 +39,15 @@ This library is part of the **Microsoft 365 Agents SDK for Python** - a comprehe
|
|
|
38
39
|
<th style="width:20%">Date</th>
|
|
39
40
|
<th style="width:60%">Release Notes</th>
|
|
40
41
|
</tr>
|
|
42
|
+
<tr>
|
|
43
|
+
<td>1.5.0</td>
|
|
44
|
+
<td>2026-08-26</td>
|
|
45
|
+
<td>
|
|
46
|
+
<a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md#microsoft-365-agents-sdk-for-python---release-notes-v150">
|
|
47
|
+
1.5.0 Release Notes
|
|
48
|
+
</a>
|
|
49
|
+
</td>
|
|
50
|
+
</tr>
|
|
41
51
|
<tr>
|
|
42
52
|
<td>1.4.0</td>
|
|
43
53
|
<td>2026-08-18</td>
|
|
@@ -231,6 +241,7 @@ class AuthTypes(str, Enum):
|
|
|
231
241
|
|
|
232
242
|
- **`MsalAuth`** - Core authentication provider using MSAL
|
|
233
243
|
- **`MsalConnectionManager`** - Manages multiple authentication connections
|
|
244
|
+
- **`MsalTokenCredential`** - Asynchronous Azure Core token credential backed by MSAL
|
|
234
245
|
|
|
235
246
|
## Features
|
|
236
247
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.6.1.dev1
|
microsoft_agents_authentication_msal-1.6.1.dev1/microsoft_agents/authentication/msal/__init__.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
# Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
from .msal_auth import MsalAuth
|
|
5
|
+
from .msal_connection_manager import MsalConnectionManager
|
|
6
|
+
from .msal_token_credential import MsalTokenCredential
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"MsalAuth",
|
|
10
|
+
"MsalConnectionManager",
|
|
11
|
+
"MsalTokenCredential",
|
|
12
|
+
]
|
|
@@ -6,6 +6,7 @@ from __future__ import annotations
|
|
|
6
6
|
import re
|
|
7
7
|
import asyncio
|
|
8
8
|
import logging
|
|
9
|
+
import time
|
|
9
10
|
import jwt
|
|
10
11
|
from typing import Optional
|
|
11
12
|
from urllib.parse import urlparse, ParseResult as URI
|
|
@@ -16,6 +17,7 @@ from msal import (
|
|
|
16
17
|
SystemAssignedManagedIdentity,
|
|
17
18
|
TokenCache,
|
|
18
19
|
)
|
|
20
|
+
from azure.core.credentials import AccessToken
|
|
19
21
|
from requests import Session
|
|
20
22
|
|
|
21
23
|
from microsoft_agents.activity._utils import _DeferredString
|
|
@@ -73,6 +75,28 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
73
75
|
async def get_access_token(
|
|
74
76
|
self, resource_url: str, scopes: list[str], force_refresh: bool = False
|
|
75
77
|
) -> str:
|
|
78
|
+
"""Gets an access token for the specified resource URL and scopes.
|
|
79
|
+
|
|
80
|
+
:param resource_url: The resource URL for which to acquire the access token.
|
|
81
|
+
:param scopes: The scopes for which the access token is requested.
|
|
82
|
+
:param force_refresh: Whether to force a refresh of the access token.
|
|
83
|
+
:return: The acquired access token as a string.
|
|
84
|
+
:rtype: str
|
|
85
|
+
"""
|
|
86
|
+
access_token = await self._get_access_token(resource_url, scopes, force_refresh)
|
|
87
|
+
return access_token.token
|
|
88
|
+
|
|
89
|
+
async def _get_access_token(
|
|
90
|
+
self, resource_url: str, scopes: list[str], force_refresh: bool = False
|
|
91
|
+
) -> AccessToken:
|
|
92
|
+
"""Internal method to get an access token for the specified resource URL and scopes.
|
|
93
|
+
|
|
94
|
+
:param resource_url: The resource URL for which to acquire the access token.
|
|
95
|
+
:param scopes: The scopes for which the access token is requested.
|
|
96
|
+
:param force_refresh: Whether to force a refresh of the access token.
|
|
97
|
+
:return: The acquired access token as an AccessToken object.
|
|
98
|
+
:rtype: AccessToken
|
|
99
|
+
"""
|
|
76
100
|
with spans.GetAccessToken(
|
|
77
101
|
scopes,
|
|
78
102
|
self._msal_configuration.AUTH_TYPE,
|
|
@@ -99,7 +123,7 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
99
123
|
msal_auth_client, scopes=local_scopes
|
|
100
124
|
)
|
|
101
125
|
else:
|
|
102
|
-
auth_result_payload =
|
|
126
|
+
auth_result_payload = {}
|
|
103
127
|
|
|
104
128
|
res = (
|
|
105
129
|
auth_result_payload.get("access_token") if auth_result_payload else None
|
|
@@ -114,7 +138,15 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
114
138
|
)
|
|
115
139
|
)
|
|
116
140
|
|
|
117
|
-
|
|
141
|
+
expires_on = auth_result_payload.get("expires_on")
|
|
142
|
+
if expires_on is not None:
|
|
143
|
+
return AccessToken(res, int(expires_on))
|
|
144
|
+
|
|
145
|
+
expires_in = auth_result_payload.get("expires_in")
|
|
146
|
+
if expires_in is None:
|
|
147
|
+
raise ValueError("Token response does not include an expiration.")
|
|
148
|
+
|
|
149
|
+
return AccessToken(res, int(time.time()) + int(expires_in))
|
|
118
150
|
|
|
119
151
|
async def acquire_token_on_behalf_of(
|
|
120
152
|
self, scopes: list[str], user_assertion: str
|
|
@@ -186,6 +218,11 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
186
218
|
def _resolve_azure_region(config: AgentAuthConfiguration) -> str | None:
|
|
187
219
|
"""Resolves the Azure regional token service (ESTS-R) to use, if configured.
|
|
188
220
|
|
|
221
|
+
:param config: The agent authentication configuration.
|
|
222
|
+
:type config: :class:`microsoft_agents.hosting.core.AgentAuthConfiguration`
|
|
223
|
+
:return: The resolved Azure region or None if not configured.
|
|
224
|
+
:rtype: str | None
|
|
225
|
+
|
|
189
226
|
Returns the configured region only when it is populated and non-whitespace,
|
|
190
227
|
otherwise None so that MSAL falls back to the global token service.
|
|
191
228
|
"""
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
# Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import logging
|
|
5
|
+
|
|
6
|
+
from azure.core.credentials import AccessToken
|
|
7
|
+
from azure.core.credentials_async import AsyncTokenCredential
|
|
8
|
+
|
|
9
|
+
from microsoft_agents.hosting.core import AgentAuthConfiguration
|
|
10
|
+
|
|
11
|
+
from .msal_auth import MsalAuth
|
|
12
|
+
|
|
13
|
+
logger = logging.getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _get_resource(scope: str) -> str:
|
|
17
|
+
"""Extracts the resource by removing a trailing '/.default' from the scope.
|
|
18
|
+
|
|
19
|
+
:param scope: The scope string.
|
|
20
|
+
:return: The extracted resource string.
|
|
21
|
+
:rtype: str
|
|
22
|
+
"""
|
|
23
|
+
return scope.removesuffix("/.default")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class MsalTokenCredential(AsyncTokenCredential):
|
|
27
|
+
"""Provides an asynchronous Azure Core token credential using MSAL."""
|
|
28
|
+
|
|
29
|
+
def __init__(self, config: AgentAuthConfiguration):
|
|
30
|
+
"""Initializes the MsalTokenCredential with the given configuration.
|
|
31
|
+
|
|
32
|
+
:param config: The agent authentication configuration.
|
|
33
|
+
:type config: :class:`microsoft_agents.hosting.core.AgentAuthConfiguration`
|
|
34
|
+
"""
|
|
35
|
+
self._config = config
|
|
36
|
+
self._provider: MsalAuth | None = None
|
|
37
|
+
|
|
38
|
+
async def get_token(self, *scopes: str, **kwargs) -> AccessToken:
|
|
39
|
+
"""Acquire an access token for the specified scopes.
|
|
40
|
+
|
|
41
|
+
:param scopes: The scopes for which the access token is requested.
|
|
42
|
+
:param kwargs: Additional keyword arguments.
|
|
43
|
+
|
|
44
|
+
:return: The acquired access token.
|
|
45
|
+
:rtype: AccessToken
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
logger.debug("get_token scope=%s", scopes)
|
|
49
|
+
|
|
50
|
+
if not scopes:
|
|
51
|
+
raise ValueError("At least one scope must be provided.")
|
|
52
|
+
|
|
53
|
+
if not self._provider:
|
|
54
|
+
self._provider = MsalAuth(self._config)
|
|
55
|
+
|
|
56
|
+
resource = _get_resource(scopes[0])
|
|
57
|
+
|
|
58
|
+
return await self._provider._get_access_token(resource, list(scopes))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: microsoft-agents-authentication-msal
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.6.1.dev1
|
|
4
4
|
Summary: A msal-based authentication library for Microsoft Agents
|
|
5
5
|
Author: Microsoft Corporation
|
|
6
6
|
License-Expression: MIT
|
|
@@ -15,7 +15,8 @@ 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.6.1.dev1
|
|
19
|
+
Requires-Dist: azure-core
|
|
19
20
|
Requires-Dist: msal>=1.34.0
|
|
20
21
|
Requires-Dist: requests>=2.32.3
|
|
21
22
|
Dynamic: license-file
|
|
@@ -38,6 +39,15 @@ This library is part of the **Microsoft 365 Agents SDK for Python** - a comprehe
|
|
|
38
39
|
<th style="width:20%">Date</th>
|
|
39
40
|
<th style="width:60%">Release Notes</th>
|
|
40
41
|
</tr>
|
|
42
|
+
<tr>
|
|
43
|
+
<td>1.5.0</td>
|
|
44
|
+
<td>2026-08-26</td>
|
|
45
|
+
<td>
|
|
46
|
+
<a href="https://github.com/microsoft/Agents-for-python/blob/main/changelog.md#microsoft-365-agents-sdk-for-python---release-notes-v150">
|
|
47
|
+
1.5.0 Release Notes
|
|
48
|
+
</a>
|
|
49
|
+
</td>
|
|
50
|
+
</tr>
|
|
41
51
|
<tr>
|
|
42
52
|
<td>1.4.0</td>
|
|
43
53
|
<td>2026-08-18</td>
|
|
@@ -231,6 +241,7 @@ class AuthTypes(str, Enum):
|
|
|
231
241
|
|
|
232
242
|
- **`MsalAuth`** - Core authentication provider using MSAL
|
|
233
243
|
- **`MsalConnectionManager`** - Manages multiple authentication connections
|
|
244
|
+
- **`MsalTokenCredential`** - Asynchronous Azure Core token credential backed by MSAL
|
|
234
245
|
|
|
235
246
|
## Features
|
|
236
247
|
|
|
@@ -7,6 +7,7 @@ setup.py
|
|
|
7
7
|
microsoft_agents/authentication/msal/__init__.py
|
|
8
8
|
microsoft_agents/authentication/msal/msal_auth.py
|
|
9
9
|
microsoft_agents/authentication/msal/msal_connection_manager.py
|
|
10
|
+
microsoft_agents/authentication/msal/msal_token_credential.py
|
|
10
11
|
microsoft_agents/authentication/msal/py.typed
|
|
11
12
|
microsoft_agents/authentication/msal/errors/__init__.py
|
|
12
13
|
microsoft_agents/authentication/msal/errors/error_resources.py
|
|
@@ -15,6 +15,15 @@ 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.5.0</td>
|
|
20
|
+
<td>2026-08-26</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-v150">
|
|
23
|
+
1.5.0 Release Notes
|
|
24
|
+
</a>
|
|
25
|
+
</td>
|
|
26
|
+
</tr>
|
|
18
27
|
<tr>
|
|
19
28
|
<td>1.4.0</td>
|
|
20
29
|
<td>2026-08-18</td>
|
|
@@ -208,6 +217,7 @@ class AuthTypes(str, Enum):
|
|
|
208
217
|
|
|
209
218
|
- **`MsalAuth`** - Core authentication provider using MSAL
|
|
210
219
|
- **`MsalConnectionManager`** - Manages multiple authentication connections
|
|
220
|
+
- **`MsalTokenCredential`** - Asynchronous Azure Core token credential backed by MSAL
|
|
211
221
|
|
|
212
222
|
## Features
|
|
213
223
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
1.5.0.dev11
|
|
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
|