Regarding the issue, that is because all of the SDKs default to using https://login.microsoftonline.com
as the Azure Active Directory authority host. Each of the other clouds have different authority host endpoints. So we need to change authority host when we create DefaultAzureCredential
.
For example. I use the sdk Azure Identity Version 1.1.0-beta.4
- Install SDK
<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.1.0-beta.4</version>
</dependency>
</dependencies>
- Code
/**
* the class `KnownAuthorityHosts` has the all cloud Azure Active Directory authority enpoint :
* https://learn.microsoft.com/en-us/java/api/com.azure.identity.knownauthorityhosts?view=azure-java-preview
*/
DefaultAzureCredential cred = new DefaultAzureCredentialBuilder().
authorityHost(KnownAuthorityHosts.AZURE_US_GOVERNMENT)
.build();
SecretClient client = new SecretClientBuilder()
.vaultUrl(<your-vault-url>)
.credential(cred )
.buildClient();
For more details, please refer to the article