Skip to content

Commit 7667222

Browse files
committed
fix
1 parent 206a15a commit 7667222

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

packages/apps/src/microsoft/teams/apps/token_manager.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async def get_graph_token(self, tenant_id: Optional[str] = None) -> Optional[Tok
6262
return await self._get_token("https://graph.microsoft.com/.default", tenant_id)
6363

6464
async def _get_token(
65-
self, scope: str | list[str], tenant_id: str | None = None, *, caller_name: str | None = None
65+
self, scope: str, tenant_id: str | None = None, *, caller_name: str | None = None
6666
) -> Optional[TokenProtocol]:
6767
credentials = self._credentials
6868
if self._credentials is None:
@@ -72,9 +72,19 @@ async def _get_token(
7272
if isinstance(credentials, (ClientCredentials, ManagedIdentityCredentials)):
7373
tenant_id_param = tenant_id or credentials.tenant_id or "botframework.com"
7474
msal_client = self._get_msal_client(tenant_id_param)
75-
token_res: dict[str, Any] | None = await asyncio.to_thread(
76-
lambda: msal_client.acquire_token_for_client(scope if isinstance(scope, list) else [scope])
77-
)
75+
76+
# Handle different acquire_token_for_client signatures
77+
if isinstance(msal_client, ManagedIdentityClient):
78+
# ManagedIdentityClient expects resource as a keyword-only string parameter
79+
token_res: dict[str, Any] | None = await asyncio.to_thread(
80+
lambda: msal_client.acquire_token_for_client(resource=scope)
81+
)
82+
else:
83+
# ConfidentialClientApplication expects scopes as a list
84+
token_res: dict[str, Any] | None = await asyncio.to_thread(
85+
lambda: msal_client.acquire_token_for_client([scope])
86+
)
87+
7888
if token_res.get("access_token", None):
7989
access_token = token_res["access_token"]
8090
return JsonWebToken(access_token)

stubs/msal/__init__.pyi

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ConfidentialClientApplication:
99
self, client_id: str, *, client_credential: Optional[str] = None, authority: Optional[str] = None, **kwargs: Any
1010
) -> None: ...
1111
def acquire_token_for_client(
12-
self, scopes: list[str] | str, claims_challenge: Optional[str] = None, **kwargs: Any
12+
self, scopes: list[str], claims_challenge: Optional[str] = None, **kwargs: Any
1313
) -> dict[str, Any]: ...
1414

1515
class SystemAssignedManagedIdentity:
@@ -34,6 +34,4 @@ class ManagedIdentityClient:
3434
http_cache: Optional[Any] = None,
3535
client_capabilities: Optional[list[str]] = None,
3636
) -> None: ...
37-
def acquire_token_for_client(
38-
self, scopes: list[str] | str, claims_challenge: Optional[str] = None, **kwargs: Any
39-
) -> dict[str, Any]: ...
37+
def acquire_token_for_client(self, *, resource: str, claims_challenge: Optional[str] = None) -> dict[str, Any]: ...

0 commit comments

Comments
 (0)