Skip to content

Commit 718bc09

Browse files
committed
Remove use of SystemManagedIdentity
1 parent a5ce190 commit 718bc09

File tree

4 files changed

+14
-28
lines changed

4 files changed

+14
-28
lines changed

packages/api/src/microsoft/teams/api/auth/credentials.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Licensed under the MIT License.
44
"""
55

6-
from typing import Awaitable, Callable, Literal, Optional, Union
6+
from typing import Awaitable, Callable, Optional, Union
77

88
from ..models import CustomBaseModel
99

@@ -44,15 +44,11 @@ class TokenCredentials(CustomBaseModel):
4444

4545

4646
class ManagedIdentityCredentials(CustomBaseModel):
47-
"""Credentials for authentication using Azure Managed Identity."""
47+
"""Credentials for authentication using Azure User-Assigned Managed Identity."""
4848

4949
client_id: str
5050
"""
51-
The client ID of the app registration.
52-
"""
53-
managed_identity_type: Literal["system", "user"]
54-
"""
55-
The type of managed identity: 'system' for system-assigned or 'user' for user-assigned.
51+
The client ID of the user-assigned managed identity.
5652
"""
5753
tenant_id: Optional[str] = None
5854
"""

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ def _init_credentials(self) -> Optional[Credentials]:
292292
tenant_id = self.options.tenant_id or os.getenv("TENANT_ID")
293293
token = self.options.token
294294
managed_identity_client_id = self.options.managed_identity_client_id or os.getenv("MANAGED_IDENTITY_CLIENT_ID")
295-
managed_identity_type = self.options.managed_identity_type or os.getenv("MANAGED_IDENTITY_TYPE") or "user"
296295

297296
self.log.debug(f"Using CLIENT_ID: {client_id}")
298297
if not tenant_id:
@@ -311,15 +310,18 @@ def _init_credentials(self) -> Optional[Credentials]:
311310

312311
# - If client_id but no client_secret : use ManagedIdentityCredentials (inferred)
313312
if client_id:
314-
assert managed_identity_type in ("system", "user"), (
315-
f"managed_identity_type must be 'system' or 'user', got: {managed_identity_type}"
316-
)
317-
self.log.debug(f"Using managed identity: {managed_identity_type} for auth")
313+
# Validate that if managed_identity_client_id is provided, it must equal client_id
314+
if managed_identity_client_id and managed_identity_client_id != client_id:
315+
raise ValueError(
316+
"Federated Identity Credentials is not yet supported. "
317+
"managed_identity_client_id must equal client_id."
318+
)
319+
320+
self.log.debug("Using user-assigned managed identity for auth")
318321
# Use managed_identity_client_id if provided, otherwise fall back to client_id
319322
mi_client_id = managed_identity_client_id or client_id
320323
return ManagedIdentityCredentials(
321324
client_id=mi_client_id,
322-
managed_identity_type=managed_identity_type,
323325
tenant_id=tenant_id,
324326
)
325327

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from dataclasses import dataclass, field
77
from logging import Logger
8-
from typing import Any, Awaitable, Callable, List, Literal, Optional, TypedDict, Union, cast
8+
from typing import Any, Awaitable, Callable, List, Optional, TypedDict, Union, cast
99

1010
from microsoft.teams.common import Storage
1111
from typing_extensions import Unpack
@@ -33,12 +33,6 @@ class AppOptions(TypedDict, total=False):
3333
Defaults to client_id if not provided.
3434
"""
3535

36-
managed_identity_type: Optional[Literal["system", "user"]]
37-
"""
38-
The type of managed identity: 'system' for system-assigned or 'user'
39-
for user-assigned. Defaults to 'user' (if managed identity is used at all)
40-
"""
41-
4236
# Infrastructure
4337
logger: Optional[Logger]
4438
storage: Optional[Storage[str, Any]]
@@ -69,8 +63,6 @@ class InternalAppOptions:
6963
"""Custom token provider function. If provided with client_id (no client_secret), uses TokenCredentials."""
7064
managed_identity_client_id: Optional[str] = None
7165
"""The managed identity client ID for user-assigned managed identity. Defaults to client_id if not provided."""
72-
managed_identity_type: Optional[Literal["system", "user"]] = None
73-
"""The type of managed identity: 'system' for system-assigned or 'user' for user-assigned. Defaults to 'user'."""
7466
logger: Optional[Logger] = None
7567
storage: Optional[Storage[str, Any]] = None
7668

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from msal import ( # pyright: ignore[reportMissingTypeStubs]
2121
ConfidentialClientApplication,
2222
ManagedIdentityClient,
23-
SystemAssignedManagedIdentity,
2423
UserAssignedManagedIdentity,
2524
)
2625

@@ -124,11 +123,8 @@ def _get_msal_client(self, tenant_id: str) -> ConfidentialClientApplication | Ma
124123
authority=f"https://login.microsoftonline.com/{tenant_id}",
125124
)
126125
elif isinstance(credentials, ManagedIdentityCredentials):
127-
# Create the appropriate managed identity based on type
128-
if credentials.managed_identity_type == "system":
129-
managed_identity = SystemAssignedManagedIdentity()
130-
else: # "user"
131-
managed_identity = UserAssignedManagedIdentity(client_id=credentials.client_id)
126+
# Create user-assigned managed identity
127+
managed_identity = UserAssignedManagedIdentity(client_id=credentials.client_id)
132128

133129
client = ManagedIdentityClient(
134130
managed_identity,

0 commit comments

Comments
 (0)