You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: msal-python-conceptual/advanced/managed-identity.md
+37-1Lines changed: 37 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,7 +54,7 @@ In both system- and user-assigned identities, developers need to use <xref:msal.
54
54
System-assigned managed identities can be used by instantiating <xref:msal.managed_identity.SystemAssignedManagedIdentity> and passing to <xref:msal.managed_identity.ManagedIdentityClient>.
55
55
56
56
>[!NOTE]
57
-
>You also need to pass a `http_client` reference, which can be set to `requests.Session()`, which keeps track of a pool of connections to the IMDS endpoint.
57
+
>You need to include a `http_client` reference, which can be set to `requests.Session()`. This enables MSAL to maintain a pool of connections to the IMDS endpoint.
58
58
59
59
You can specify the target resource scope when calling [`acquire_token_for_client`](xref:msal.managed_identity.ManagedIdentityClient.acquire_token_for_client).
60
60
@@ -72,3 +72,39 @@ if "access_token" in result:
72
72
print("Token obtained!")
73
73
```
74
74
75
+
>[!IMPORTANT]
76
+
>You need to enable a system-assigned identity for the resource where the Python code runs; otherwise, no token will be returned.
77
+
78
+
### User-assigned managed identities
79
+
80
+
User-assigned managed identities can be used by instantiating <xref:msal.managed_identity.UserAssignedManagedIdentity> and passing to <xref:msal.managed_identity.ManagedIdentityClient>. You will need to specify the **one of the following**:
81
+
82
+
- Client ID (`client_id`)
83
+
- Resource ID (`resource_id`)
84
+
- Object ID (`object_id`)
85
+
86
+
>[!NOTE]
87
+
>You need to include a `http_client` reference, which can be set to `requests.Session()`. This enables MSAL to maintain a pool of connections to the IMDS endpoint.
88
+
89
+
You can specify the target resource scope when calling [`acquire_token_for_client`](xref:msal.managed_identity.ManagedIdentityClient.acquire_token_for_client).
result = global_app.acquire_token_for_client(resource='https://vault.azure.net')
100
+
101
+
if"access_token"in result:
102
+
print("Token obtained!")
103
+
```
104
+
105
+
>[!IMPORTANT]
106
+
>You need to attach a user-assigned identity for the resource where the Python code runs; otherwise, no token will be returned. If an incorrect identifier is used for the user-assigned managed identity, no token will be returned as well.
107
+
108
+
## Caching
109
+
110
+
By default, MSAL Python supports in-memory caching. MSAL does not support cache extensibility for managed identity because of security concerns when using distributed cache. Since a token acquired for managed identity belongs to an Azure resource, using a distributed cache might expose it to the other Azure resources sharing the cache.
0 commit comments