Skip to content

Implement azure-identity's multi-tenant authentication API #20881

@jiasli

Description

@jiasli

Context

azure-identity introduced its new multi-tenant authentication API get_token(tenant_id=...):

Meanwhile, before this is implemented, Azure CLI developed its own multi-tenant authentication implementation using CredentialAdaptor.get_auxiliary_tokens (#19853):

# Track 2 currently lacks the ability to take external credentials.
# https://github.com/Azure/azure-sdk-for-python/issues/8313
# As a temporary workaround, manually add external tokens to 'x-ms-authorization-auxiliary' header.
# https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/authenticate-multi-tenant
if hasattr(cred, "get_auxiliary_tokens"):
aux_tokens = cred.get_auxiliary_tokens(*scopes)
if aux_tokens:
# Hard-code scheme to 'Bearer' as _BearerTokenCredentialPolicyBase._update_headers does.
client_kwargs['headers']['x-ms-authorization-auxiliary'] = \
', '.join("Bearer {}".format(token.token) for token in aux_tokens)

This makes CredentialAdaptor.get_token incompatible with azure-identity's InteractiveCredential.get_token which takes tenant_id and resolves it at

https://github.com/Azure/azure-sdk-for-python/blob/01d0b99e53a1995b39e59649bf3d550dc5408875/sdk/identity/azure-identity/azure/identity/_internal/msal_credentials.py#L62

    def _get_app(self, **kwargs):
        # type: (**Any) -> msal.ClientApplication
        tenant_id = resolve_tenant(self._tenant_id, **kwargs)

TODO

CredentialAdaptor.get_token should be able to take tenant_id.

References

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions