- 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());
});
});
- 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.
-
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
-
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:
- provide the functionality of building a token credential from (a: existing credential, b: tenant id) for refresh token based credentials: InteractiveBrowserCredential and DeviceCodeCredential, VisualStudioCodeCredential
- provide the functionality of setting tenant id for AzureCliCredential
- provide a valid token in VisualStudioCodeCredentialBuilder without tenant id, use this token we can list the tenants
- 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
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: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
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:
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: