Skip to content

Proof-of-Concept: MI via CCA #560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,24 @@ See `SerializableTokenCache` for example.

.. autoclass:: msal.SerializableTokenCache
:members:


Managed Identity
================
MSAL supports
`Managed Identity <https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview>`_.

You can create one of these two kinds of managed identity configuration objects:

.. autoclass:: msal.SystemAssignedManagedIdentity
:members:

.. autoclass:: msal.UserAssignedManagedIdentity
:members:

And then feed the configuration object into a :class:`ManagedIdentityClient` object.

.. autoclass:: msal.ManagedIdentityClient
:members:

.. automethod:: __init__
4 changes: 4 additions & 0 deletions msal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@
)
from .oauth2cli.oidc import Prompt
from .token_cache import TokenCache, SerializableTokenCache
from .managed_identity import (
SystemAssignedManagedIdentity, UserAssignedManagedIdentity,
ManagedIdentityClient,
)

9 changes: 9 additions & 0 deletions msal/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from .region import _detect_region
from .throttled_http_client import ThrottledHttpClient
from .cloudshell import _is_running_in_cloud_shell
from .imds import ManagedIdentityClient, ManagedIdentity, _scope_to_resource


# The __init__.py will import this. Not the other way around.
Expand Down Expand Up @@ -2021,6 +2022,14 @@ def acquire_token_for_client(self, scopes, claims_challenge=None, **kwargs):
- an error response would contain "error" and usually "error_description".
"""
# TBD: force_refresh behavior
if ManagedIdentity.is_managed_identity(self.client_id):
if len(scopes) != 1:
raise ValueError("Managed Identity supports only one scope/resource")
if claims_challenge:
raise ValueError("Managed Identity does not support claims_challenge")
return ManagedIdentityClient(
self.http_client, self.client_id, self.token_cache
).acquire_token(_scope_to_resource(scopes[0]))
if self.authority.tenant.lower() in ["common", "organizations"]:
warnings.warn(
"Using /common or /organizations authority "
Expand Down
Loading