Skip to content

[FEATURE REQ] [Identity] Support non-microsoft tenants #19443

Description

@andxu
  1. Consider the case, I want use to login using device code and list all the subscriptions associate with the account, the code bellowing will promote user many times for listing all subscriptions, how can I fork a new TokenCredential with a tenant which will be used in the second call of 'AzureResourceManager.authenticate', the InteractiveBrowserCredential has the same issue.
        TokenCredential tokenCredential = new DeviceCodeCredentialBuilder().build();
        AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
        AzureResourceManager.authenticate(tokenCredential, profile).tenants().list().stream().forEach(tenant-> {
            System.out.println(tenant.tenantId());

            // here I want to use tokenCredential, but I cannot change the tenant from null to tenant.tenantId()
            // if I use new DeviceCodeCredentialBuilder() then the user must input the code twice and select the same account in page
            AzureResourceManager.authenticate(new DeviceCodeCredentialBuilder().tenantId(tenant.tenantId()).build(), profile).subscriptions().list().stream().forEach(
                    subscription -> {
                System.out.println(subscription.displayName());
                System.out.println(subscription.subscriptionId());
            });
        });
  1. Another issue, for VisualStudioCodeCredentialBuilder, how does the the app know the Azure Environment and tenant id? Otherwise the credential from new VisualStudioCodeCredentialBuilder().build() while in vscode I signed in a account which is not a microsoft tenant(72f988bf-86f1-41af-91ab-2d7cd011db47) will report error for listing tenants:
AADSTS70002: The client does not exist or is not enabled for consumers. If you are the application developer, configure a new application through the App Registrations in the Azure Portal at https://go.microsoft.com/fwlink/?linkid=2083908.
  1. The third case, the azure cli credential doesn't support tenant, actually we can get access token through:
    az account get-access-token -t xxxx

  2. The 4th case, for SharedTokenCacheCredential, we cannot list the accounts saved in TokenCache, I have to use very strange logic to get the cached accounts: https://github.com/microsoft/azure-maven-plugins/blob/andy-wip2/azure-toolkit-libs/azure-toolkit-auth-lib/src/main/java/com/microsoft/azure/toolkit/lib/auth/core/visualstudio/VisualStudioAccountEntityBuilder.java#L61

Summary
To provide an access token, we need to specify the following properties:

  • a. Azure environment(Azure cloud name)
  • b. Tenant (organization/domain, eg: onmicrosoft.com)
  • c. Client Id (referring to different clients)
  • d. Scopes (resource)

TokenCredential has enveloped the D, in most cases, the client id is implied, but for tenant id, it is hard for apps using azure-identity to provide and it can be populated through the listing tenant call, so I want azure identity:

  1. provide the functionality of building a token credential from (a: existing credential, b: tenant id) for refresh token based credentials: InteractiveBrowserCredential and DeviceCodeCredential, VisualStudioCodeCredential
  2. provide the functionality of setting tenant id for AzureCliCredential
  3. provide a valid token in VisualStudioCodeCredentialBuilder without tenant id, use this token we can list the tenants
  4. We want identity not to only to provide functionality to get the token but also the functionality of listing cached account(azure environment, tenant id, user name, client id) for SharedTokenCacheCredential

Metadata

Metadata

Labels

Azure.IdentityClientThis issue points to a problem in the data-plane of the library.feature-requestThis issue requires a new behavior in the product in order be resolved.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions