microsoft-agents-authentication-msal 0.9.0.dev5__tar.gz → 0.9.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.9.0.dev5/microsoft_agents_authentication_msal.egg-info → microsoft_agents_authentication_msal-0.9.0.dev7}/PKG-INFO +2 -3
- microsoft_agents_authentication_msal-0.9.0.dev7/VERSION.txt +1 -0
- {microsoft_agents_authentication_msal-0.9.0.dev5 → microsoft_agents_authentication_msal-0.9.0.dev7}/microsoft_agents/authentication/msal/msal_auth.py +182 -190
- {microsoft_agents_authentication_msal-0.9.0.dev5 → microsoft_agents_authentication_msal-0.9.0.dev7/microsoft_agents_authentication_msal.egg-info}/PKG-INFO +2 -3
- microsoft_agents_authentication_msal-0.9.0.dev7/microsoft_agents_authentication_msal.egg-info/requires.txt +3 -0
- {microsoft_agents_authentication_msal-0.9.0.dev5 → microsoft_agents_authentication_msal-0.9.0.dev7}/setup.py +0 -1
- microsoft_agents_authentication_msal-0.9.0.dev5/VERSION.txt +0 -1
- microsoft_agents_authentication_msal-0.9.0.dev5/microsoft_agents_authentication_msal.egg-info/requires.txt +0 -4
- {microsoft_agents_authentication_msal-0.9.0.dev5 → microsoft_agents_authentication_msal-0.9.0.dev7}/LICENSE +0 -0
- {microsoft_agents_authentication_msal-0.9.0.dev5 → microsoft_agents_authentication_msal-0.9.0.dev7}/MANIFEST.in +0 -0
- {microsoft_agents_authentication_msal-0.9.0.dev5 → microsoft_agents_authentication_msal-0.9.0.dev7}/microsoft_agents/authentication/msal/__init__.py +0 -0
- {microsoft_agents_authentication_msal-0.9.0.dev5 → microsoft_agents_authentication_msal-0.9.0.dev7}/microsoft_agents/authentication/msal/errors/__init__.py +0 -0
- {microsoft_agents_authentication_msal-0.9.0.dev5 → microsoft_agents_authentication_msal-0.9.0.dev7}/microsoft_agents/authentication/msal/errors/error_resources.py +0 -0
- {microsoft_agents_authentication_msal-0.9.0.dev5 → microsoft_agents_authentication_msal-0.9.0.dev7}/microsoft_agents/authentication/msal/msal_connection_manager.py +0 -0
- {microsoft_agents_authentication_msal-0.9.0.dev5 → microsoft_agents_authentication_msal-0.9.0.dev7}/microsoft_agents_authentication_msal.egg-info/SOURCES.txt +0 -0
- {microsoft_agents_authentication_msal-0.9.0.dev5 → microsoft_agents_authentication_msal-0.9.0.dev7}/microsoft_agents_authentication_msal.egg-info/dependency_links.txt +0 -0
- {microsoft_agents_authentication_msal-0.9.0.dev5 → microsoft_agents_authentication_msal-0.9.0.dev7}/microsoft_agents_authentication_msal.egg-info/top_level.txt +0 -0
- {microsoft_agents_authentication_msal-0.9.0.dev5 → microsoft_agents_authentication_msal-0.9.0.dev7}/pyproject.toml +0 -0
- {microsoft_agents_authentication_msal-0.9.0.dev5 → microsoft_agents_authentication_msal-0.9.0.dev7}/readme.md +0 -0
- {microsoft_agents_authentication_msal-0.9.0.dev5 → microsoft_agents_authentication_msal-0.9.0.dev7}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: microsoft-agents-authentication-msal
|
|
3
|
-
Version: 0.9.0.
|
|
3
|
+
Version: 0.9.0.dev7
|
|
4
4
|
Summary: A msal-based authentication library for Microsoft Agents
|
|
5
5
|
Author: Microsoft Corporation
|
|
6
6
|
License-Expression: MIT
|
|
@@ -15,10 +15,9 @@ 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==0.9.0.
|
|
18
|
+
Requires-Dist: microsoft-agents-hosting-core==0.9.0.dev7
|
|
19
19
|
Requires-Dist: msal>=1.34.0
|
|
20
20
|
Requires-Dist: requests>=2.32.3
|
|
21
|
-
Requires-Dist: cryptography>=44.0.0
|
|
22
21
|
Dynamic: license-file
|
|
23
22
|
Dynamic: requires-dist
|
|
24
23
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.9.0.dev7
|
|
@@ -17,9 +17,6 @@ from msal import (
|
|
|
17
17
|
TokenCache,
|
|
18
18
|
)
|
|
19
19
|
from requests import Session
|
|
20
|
-
from cryptography.x509 import load_pem_x509_certificate
|
|
21
|
-
from cryptography.hazmat.backends import default_backend
|
|
22
|
-
from cryptography.hazmat.primitives import hashes
|
|
23
20
|
|
|
24
21
|
from microsoft_agents.activity._utils import _DeferredString
|
|
25
22
|
|
|
@@ -28,6 +25,7 @@ from microsoft_agents.hosting.core import (
|
|
|
28
25
|
AccessTokenProviderBase,
|
|
29
26
|
AgentAuthConfiguration,
|
|
30
27
|
)
|
|
28
|
+
from microsoft_agents.hosting.core.authorization.telemetry import spans
|
|
31
29
|
from microsoft_agents.authentication.msal.errors import authentication_errors
|
|
32
30
|
|
|
33
31
|
logger = logging.getLogger(__name__)
|
|
@@ -68,40 +66,48 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
68
66
|
async def get_access_token(
|
|
69
67
|
self, resource_url: str, scopes: list[str], force_refresh: bool = False
|
|
70
68
|
) -> str:
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
assert instance_uri is not None # for mypy
|
|
78
|
-
|
|
79
|
-
local_scopes = self._resolve_scopes_list(instance_uri, scopes)
|
|
80
|
-
msal_auth_client = self._get_client()
|
|
81
|
-
|
|
82
|
-
if isinstance(msal_auth_client, ManagedIdentityClient):
|
|
83
|
-
logger.info("Acquiring token using Managed Identity Client.")
|
|
84
|
-
auth_result_payload = await _async_acquire_token_for_client(
|
|
85
|
-
msal_auth_client, resource=resource_url
|
|
86
|
-
)
|
|
87
|
-
elif isinstance(msal_auth_client, ConfidentialClientApplication):
|
|
88
|
-
logger.info("Acquiring token using Confidential Client Application.")
|
|
89
|
-
auth_result_payload = await _async_acquire_token_for_client(
|
|
90
|
-
msal_auth_client, scopes=local_scopes
|
|
69
|
+
with spans.GetAccessToken(
|
|
70
|
+
scopes,
|
|
71
|
+
self._msal_configuration.AUTH_TYPE,
|
|
72
|
+
):
|
|
73
|
+
logger.debug(
|
|
74
|
+
f"Requesting access token for resource: {resource_url}, scopes: {scopes}"
|
|
91
75
|
)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
76
|
+
valid_uri, instance_uri = self._uri_validator(resource_url)
|
|
77
|
+
if not valid_uri:
|
|
78
|
+
raise ValueError(str(authentication_errors.InvalidInstanceUrl))
|
|
79
|
+
assert instance_uri is not None # for mypy
|
|
80
|
+
|
|
81
|
+
local_scopes = self._resolve_scopes_list(instance_uri, scopes)
|
|
82
|
+
msal_auth_client = self._get_client()
|
|
83
|
+
|
|
84
|
+
if isinstance(msal_auth_client, ManagedIdentityClient):
|
|
85
|
+
logger.info("Acquiring token using Managed Identity Client.")
|
|
86
|
+
auth_result_payload = await _async_acquire_token_for_client(
|
|
87
|
+
msal_auth_client, resource=resource_url
|
|
88
|
+
)
|
|
89
|
+
elif isinstance(msal_auth_client, ConfidentialClientApplication):
|
|
90
|
+
logger.info("Acquiring token using Confidential Client Application.")
|
|
91
|
+
auth_result_payload = await _async_acquire_token_for_client(
|
|
92
|
+
msal_auth_client, scopes=local_scopes
|
|
101
93
|
)
|
|
94
|
+
else:
|
|
95
|
+
auth_result_payload = None
|
|
96
|
+
|
|
97
|
+
res = (
|
|
98
|
+
auth_result_payload.get("access_token") if auth_result_payload else None
|
|
102
99
|
)
|
|
100
|
+
if not res:
|
|
101
|
+
logger.error(
|
|
102
|
+
"Failed to acquire token for resource %s", auth_result_payload
|
|
103
|
+
)
|
|
104
|
+
raise ValueError(
|
|
105
|
+
authentication_errors.FailedToAcquireToken.format(
|
|
106
|
+
str(auth_result_payload)
|
|
107
|
+
)
|
|
108
|
+
)
|
|
103
109
|
|
|
104
|
-
|
|
110
|
+
return res
|
|
105
111
|
|
|
106
112
|
async def acquire_token_on_behalf_of(
|
|
107
113
|
self, scopes: list[str], user_assertion: str
|
|
@@ -112,44 +118,44 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
112
118
|
:param user_assertion: The user assertion token.
|
|
113
119
|
:return: The access token as a string.
|
|
114
120
|
"""
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
logger.error(
|
|
119
|
-
"Attempted on-behalf-of flow with Managed Identity authentication."
|
|
120
|
-
)
|
|
121
|
-
raise NotImplementedError(
|
|
122
|
-
str(authentication_errors.OnBehalfOfFlowNotSupportedManagedIdentity)
|
|
123
|
-
)
|
|
124
|
-
elif isinstance(msal_auth_client, ConfidentialClientApplication):
|
|
125
|
-
# TODO: Handling token error / acquisition failed
|
|
126
|
-
|
|
127
|
-
# MSAL in Python does not support async, so we use asyncio.to_thread to run it in
|
|
128
|
-
# a separate thread and avoid blocking the event loop
|
|
129
|
-
token = await asyncio.to_thread(
|
|
130
|
-
lambda: msal_auth_client.acquire_token_on_behalf_of(
|
|
131
|
-
scopes=scopes, user_assertion=user_assertion
|
|
132
|
-
)
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
if "access_token" not in token:
|
|
121
|
+
with spans.AcquireTokenOnBehalfOf(scopes):
|
|
122
|
+
msal_auth_client = self._get_client()
|
|
123
|
+
if isinstance(msal_auth_client, ManagedIdentityClient):
|
|
136
124
|
logger.error(
|
|
137
|
-
|
|
125
|
+
"Attempted on-behalf-of flow with Managed Identity authentication."
|
|
138
126
|
)
|
|
139
|
-
raise
|
|
140
|
-
authentication_errors.
|
|
127
|
+
raise NotImplementedError(
|
|
128
|
+
str(authentication_errors.OnBehalfOfFlowNotSupportedManagedIdentity)
|
|
129
|
+
)
|
|
130
|
+
elif isinstance(msal_auth_client, ConfidentialClientApplication):
|
|
131
|
+
# TODO: Handling token error / acquisition failed
|
|
132
|
+
|
|
133
|
+
# MSAL in Python does not support async, so we use asyncio.to_thread to run it in
|
|
134
|
+
# a separate thread and avoid blocking the event loop
|
|
135
|
+
token = await asyncio.to_thread(
|
|
136
|
+
lambda: msal_auth_client.acquire_token_on_behalf_of(
|
|
137
|
+
scopes=scopes, user_assertion=user_assertion
|
|
138
|
+
)
|
|
141
139
|
)
|
|
142
140
|
|
|
143
|
-
|
|
141
|
+
if "access_token" not in token:
|
|
142
|
+
logger.error(
|
|
143
|
+
f"Failed to acquire token on behalf of user: {user_assertion}"
|
|
144
|
+
)
|
|
145
|
+
raise ValueError(
|
|
146
|
+
authentication_errors.FailedToAcquireToken.format(str(token))
|
|
147
|
+
)
|
|
144
148
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
return token["access_token"]
|
|
150
|
+
|
|
151
|
+
logger.error(
|
|
152
|
+
f"On-behalf-of flow is not supported with the current authentication type: {msal_auth_client.__class__.__name__}"
|
|
153
|
+
)
|
|
154
|
+
raise NotImplementedError(
|
|
155
|
+
authentication_errors.OnBehalfOfFlowNotSupportedAuthType.format(
|
|
156
|
+
msal_auth_client.__class__.__name__
|
|
157
|
+
)
|
|
151
158
|
)
|
|
152
|
-
)
|
|
153
159
|
|
|
154
160
|
@staticmethod
|
|
155
161
|
def _resolve_authority(
|
|
@@ -212,26 +218,8 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
212
218
|
elif self._msal_configuration.AUTH_TYPE == AuthTypes.client_secret:
|
|
213
219
|
self._client_credential_cache = self._msal_configuration.CLIENT_SECRET
|
|
214
220
|
elif self._msal_configuration.AUTH_TYPE == AuthTypes.certificate:
|
|
215
|
-
with open(self._msal_configuration.CERT_KEY_FILE) as file:
|
|
216
|
-
logger.info(
|
|
217
|
-
"Loading certificate private key for MSAL authentication."
|
|
218
|
-
)
|
|
219
|
-
private_key = file.read()
|
|
220
|
-
|
|
221
|
-
with open(self._msal_configuration.CERT_PEM_FILE) as file:
|
|
222
|
-
logger.info("Loading public certificate for MSAL authentication.")
|
|
223
|
-
public_certificate = file.read()
|
|
224
|
-
|
|
225
|
-
# Create an X509 object and calculate the thumbprint
|
|
226
|
-
logger.info("Calculating thumbprint for the public certificate.")
|
|
227
|
-
cert = load_pem_x509_certificate(
|
|
228
|
-
data=bytes(public_certificate, "UTF-8"), backend=default_backend()
|
|
229
|
-
)
|
|
230
|
-
thumbprint = cert.fingerprint(hashes.SHA1()).hex()
|
|
231
|
-
|
|
232
221
|
self._client_credential_cache = {
|
|
233
|
-
"
|
|
234
|
-
"private_key": private_key,
|
|
222
|
+
"private_key_pfx_path": self._msal_configuration.CERT_PFX_FILE,
|
|
235
223
|
}
|
|
236
224
|
else:
|
|
237
225
|
logger.error(
|
|
@@ -339,78 +327,80 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
339
327
|
:return: A tuple containing the agentic instance token and the agent application token.
|
|
340
328
|
:rtype: tuple[str, str]
|
|
341
329
|
"""
|
|
342
|
-
|
|
343
330
|
if not agent_app_instance_id:
|
|
344
331
|
raise ValueError(
|
|
345
332
|
str(authentication_errors.AgentApplicationInstanceIdRequired)
|
|
346
333
|
)
|
|
347
334
|
|
|
348
|
-
|
|
349
|
-
"Attempting to get agentic instance token from agent_app_instance_id %s",
|
|
350
|
-
agent_app_instance_id,
|
|
351
|
-
)
|
|
352
|
-
agent_token_result = await self.get_agentic_application_token(
|
|
353
|
-
tenant_id, agent_app_instance_id
|
|
354
|
-
)
|
|
335
|
+
with spans.GetAgenticInstanceToken(agent_app_instance_id):
|
|
355
336
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
"Failed to acquire agentic instance token or agent token for agent_app_instance_id %s",
|
|
337
|
+
logger.info(
|
|
338
|
+
"Attempting to get agentic instance token from agent_app_instance_id %s",
|
|
359
339
|
agent_app_instance_id,
|
|
360
340
|
)
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
agent_app_instance_id
|
|
364
|
-
)
|
|
341
|
+
agent_token_result = await self.get_agentic_application_token(
|
|
342
|
+
tenant_id, agent_app_instance_id
|
|
365
343
|
)
|
|
366
344
|
|
|
367
|
-
|
|
345
|
+
if not agent_token_result:
|
|
346
|
+
logger.error(
|
|
347
|
+
"Failed to acquire agentic instance token or agent token for agent_app_instance_id %s",
|
|
348
|
+
agent_app_instance_id,
|
|
349
|
+
)
|
|
350
|
+
raise Exception(
|
|
351
|
+
authentication_errors.FailedToAcquireAgenticInstanceToken.format(
|
|
352
|
+
agent_app_instance_id
|
|
353
|
+
)
|
|
354
|
+
)
|
|
368
355
|
|
|
369
|
-
|
|
370
|
-
client_id=agent_app_instance_id,
|
|
371
|
-
authority=authority,
|
|
372
|
-
client_credential={"client_assertion": agent_token_result},
|
|
373
|
-
# token_cache=self._token_cache,
|
|
374
|
-
)
|
|
356
|
+
authority = MsalAuth._resolve_authority(self._msal_configuration, tenant_id)
|
|
375
357
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
358
|
+
instance_app = ConfidentialClientApplication(
|
|
359
|
+
client_id=agent_app_instance_id,
|
|
360
|
+
authority=authority,
|
|
361
|
+
client_credential={"client_assertion": agent_token_result},
|
|
362
|
+
# token_cache=self._token_cache,
|
|
363
|
+
)
|
|
379
364
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
"Failed to acquire agentic instance token or agent token for agent_app_instance_id %s",
|
|
383
|
-
agent_app_instance_id,
|
|
365
|
+
agentic_instance_token = await _async_acquire_token_for_client(
|
|
366
|
+
instance_app, ["api://AzureAdTokenExchange/.default"]
|
|
384
367
|
)
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
368
|
+
|
|
369
|
+
if not agentic_instance_token:
|
|
370
|
+
logger.error(
|
|
371
|
+
"Failed to acquire agentic instance token or agent token for agent_app_instance_id %s",
|
|
372
|
+
agent_app_instance_id,
|
|
373
|
+
)
|
|
374
|
+
raise Exception(
|
|
375
|
+
authentication_errors.FailedToAcquireAgenticInstanceToken.format(
|
|
376
|
+
agent_app_instance_id
|
|
377
|
+
)
|
|
388
378
|
)
|
|
389
|
-
)
|
|
390
379
|
|
|
391
|
-
|
|
380
|
+
# future scenario where we don't know the blueprint id upfront
|
|
392
381
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
raise ValueError(
|
|
399
|
-
authentication_errors.FailedToAcquireToken.format(
|
|
400
|
-
str(agentic_instance_token)
|
|
382
|
+
token = agentic_instance_token.get("access_token")
|
|
383
|
+
if not token:
|
|
384
|
+
logger.error(
|
|
385
|
+
"Failed to acquire agentic instance token, %s",
|
|
386
|
+
agentic_instance_token,
|
|
401
387
|
)
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
_DeferredString(
|
|
407
|
-
lambda: jwt.decode(token, options={"verify_signature": False}).get(
|
|
408
|
-
"xms_par_app_azp"
|
|
388
|
+
raise ValueError(
|
|
389
|
+
authentication_errors.FailedToAcquireToken.format(
|
|
390
|
+
str(agentic_instance_token)
|
|
391
|
+
)
|
|
409
392
|
)
|
|
410
|
-
),
|
|
411
|
-
)
|
|
412
393
|
|
|
413
|
-
|
|
394
|
+
logger.debug(
|
|
395
|
+
"Agentic blueprint id: %s",
|
|
396
|
+
_DeferredString(
|
|
397
|
+
lambda: jwt.decode(token, options={"verify_signature": False}).get(
|
|
398
|
+
"xms_par_app_azp"
|
|
399
|
+
)
|
|
400
|
+
),
|
|
401
|
+
)
|
|
402
|
+
|
|
403
|
+
return agentic_instance_token["access_token"], agent_token_result
|
|
414
404
|
|
|
415
405
|
async def get_agentic_user_token(
|
|
416
406
|
self,
|
|
@@ -435,71 +425,73 @@ class MsalAuth(AccessTokenProviderBase):
|
|
|
435
425
|
str(authentication_errors.AgentApplicationInstanceIdAndUserIdRequired)
|
|
436
426
|
)
|
|
437
427
|
|
|
438
|
-
|
|
439
|
-
"Attempting to get agentic user token from agent_app_instance_id %s and agentic_user_id %s",
|
|
440
|
-
agent_app_instance_id,
|
|
441
|
-
agentic_user_id,
|
|
442
|
-
)
|
|
443
|
-
instance_token, agent_token = await self.get_agentic_instance_token(
|
|
444
|
-
tenant_id, agent_app_instance_id
|
|
445
|
-
)
|
|
428
|
+
with spans.GetAgenticUserToken(agent_app_instance_id, agentic_user_id, scopes):
|
|
446
429
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
"Failed to acquire instance token or agent token for agent_app_instance_id %s and agentic_user_id %s",
|
|
430
|
+
logger.info(
|
|
431
|
+
"Attempting to get agentic user token from agent_app_instance_id %s and agentic_user_id %s",
|
|
450
432
|
agent_app_instance_id,
|
|
451
433
|
agentic_user_id,
|
|
452
434
|
)
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
agent_app_instance_id, agentic_user_id
|
|
456
|
-
)
|
|
435
|
+
instance_token, agent_token = await self.get_agentic_instance_token(
|
|
436
|
+
tenant_id, agent_app_instance_id
|
|
457
437
|
)
|
|
458
438
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
439
|
+
if not instance_token or not agent_token:
|
|
440
|
+
logger.error(
|
|
441
|
+
"Failed to acquire instance token or agent token for agent_app_instance_id %s and agentic_user_id %s",
|
|
442
|
+
agent_app_instance_id,
|
|
443
|
+
agentic_user_id,
|
|
444
|
+
)
|
|
445
|
+
raise Exception(
|
|
446
|
+
authentication_errors.FailedToAcquireInstanceOrAgentToken.format(
|
|
447
|
+
agent_app_instance_id, agentic_user_id
|
|
448
|
+
)
|
|
449
|
+
)
|
|
467
450
|
|
|
468
|
-
|
|
469
|
-
"Acquiring agentic user token for agent_app_instance_id %s and agentic_user_id %s",
|
|
470
|
-
agent_app_instance_id,
|
|
471
|
-
agentic_user_id,
|
|
472
|
-
)
|
|
473
|
-
# MSAL in Python does not support async, so we use asyncio.to_thread to run it in
|
|
474
|
-
# a separate thread and avoid blocking the event loop
|
|
475
|
-
auth_result_payload = await _async_acquire_token_for_client(
|
|
476
|
-
instance_app,
|
|
477
|
-
scopes,
|
|
478
|
-
data={
|
|
479
|
-
"user_id": agentic_user_id,
|
|
480
|
-
"user_federated_identity_credential": instance_token,
|
|
481
|
-
"grant_type": "user_fic",
|
|
482
|
-
},
|
|
483
|
-
)
|
|
451
|
+
authority = MsalAuth._resolve_authority(self._msal_configuration, tenant_id)
|
|
484
452
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
auth_result_payload,
|
|
453
|
+
instance_app = ConfidentialClientApplication(
|
|
454
|
+
client_id=agent_app_instance_id,
|
|
455
|
+
authority=authority,
|
|
456
|
+
client_credential={"client_assertion": agent_token},
|
|
457
|
+
# token_cache=self._token_cache,
|
|
491
458
|
)
|
|
492
|
-
return None
|
|
493
459
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
logger.error(
|
|
497
|
-
"Failed to acquire agentic user token for agent_app_instance_id %s and agentic_user_id %s, %s",
|
|
460
|
+
logger.info(
|
|
461
|
+
"Acquiring agentic user token for agent_app_instance_id %s and agentic_user_id %s",
|
|
498
462
|
agent_app_instance_id,
|
|
499
463
|
agentic_user_id,
|
|
500
|
-
auth_result_payload,
|
|
501
464
|
)
|
|
502
|
-
|
|
465
|
+
# MSAL in Python does not support async, so we use asyncio.to_thread to run it in
|
|
466
|
+
# a separate thread and avoid blocking the event loop
|
|
467
|
+
auth_result_payload = await _async_acquire_token_for_client(
|
|
468
|
+
instance_app,
|
|
469
|
+
scopes,
|
|
470
|
+
data={
|
|
471
|
+
"user_id": agentic_user_id,
|
|
472
|
+
"user_federated_identity_credential": instance_token,
|
|
473
|
+
"grant_type": "user_fic",
|
|
474
|
+
},
|
|
475
|
+
)
|
|
476
|
+
|
|
477
|
+
if not auth_result_payload:
|
|
478
|
+
logger.error(
|
|
479
|
+
"Failed to acquire agentic user token for agent_app_instance_id %s and agentic_user_id %s, %s",
|
|
480
|
+
agent_app_instance_id,
|
|
481
|
+
agentic_user_id,
|
|
482
|
+
auth_result_payload,
|
|
483
|
+
)
|
|
484
|
+
return None
|
|
485
|
+
|
|
486
|
+
access_token = auth_result_payload.get("access_token")
|
|
487
|
+
if not access_token:
|
|
488
|
+
logger.error(
|
|
489
|
+
"Failed to acquire agentic user token for agent_app_instance_id %s and agentic_user_id %s, %s",
|
|
490
|
+
agent_app_instance_id,
|
|
491
|
+
agentic_user_id,
|
|
492
|
+
auth_result_payload,
|
|
493
|
+
)
|
|
494
|
+
return None
|
|
503
495
|
|
|
504
|
-
|
|
505
|
-
|
|
496
|
+
logger.info("Acquired agentic user token response.")
|
|
497
|
+
return access_token
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: microsoft-agents-authentication-msal
|
|
3
|
-
Version: 0.9.0.
|
|
3
|
+
Version: 0.9.0.dev7
|
|
4
4
|
Summary: A msal-based authentication library for Microsoft Agents
|
|
5
5
|
Author: Microsoft Corporation
|
|
6
6
|
License-Expression: MIT
|
|
@@ -15,10 +15,9 @@ 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==0.9.0.
|
|
18
|
+
Requires-Dist: microsoft-agents-hosting-core==0.9.0.dev7
|
|
19
19
|
Requires-Dist: msal>=1.34.0
|
|
20
20
|
Requires-Dist: requests>=2.32.3
|
|
21
|
-
Requires-Dist: cryptography>=44.0.0
|
|
22
21
|
Dynamic: license-file
|
|
23
22
|
Dynamic: requires-dist
|
|
24
23
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
0.9.0.dev5
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|