title: How to authenticate with DefaultAzureCredentials in VS Code with Java?
body: <p>I am using VS Code to develop an Azure function with Java 11. I am able to authenticate using VisualStudioCodeCredential but when I try to use the DefaultAzureCredential class I get the below error. It is my understanding that for this app to run locally and in the Azure hosted environment that I need the DefaultAzureCredential. Why does this happen and how do I fix it? Is there a better/preferred way to do the authentication?</p>
  <pre><code>Caused by: com.azure.core.exception.ClientAuthenticationException: DefaultAzureCredential 
  authentication failed. ---&gt; IntelliJCredential authentication failed. Error Details: 
  Unrecognized field &quot;tenantId&quot; (class 
  com.azure.identity.implementation.IntelliJAuthMethodDetails), not marked as ignorable (4 known 
  properties: &quot;authMethod&quot;, &quot;azureEnv&quot;, &quot;accountEmail&quot;, &quot;credFilePath&quot;])
  </code></pre>
  <p>Here is my code. The error occurs when I try to get the secret from the vault.</p>
  <pre><code>    secretClient = new SecretClientBuilder().vaultUrl(System.getenv(&quot;KeyVaultURL&quot;))
              .credential(new DefaultAzureCredentialBuilder().build()).buildClient();
      String secretValue= secretClient.getSecret(&quot;secretValue&quot;).getValue();
  </code></pre>
  <p>Using VisualStudioCodeCredential works:</p>
  <pre><code>    secretClient = new SecretClientBuilder().vaultUrl(System.getenv(&quot;KeyVaultURL&quot;))
              .credential(new VisualStudioCodeCredential().build()).buildClient();
      String secretValue= secretClient.getSecret(&quot;secretValue&quot;).getValue();
  </code></pre>
  <p>Links to some of the docs that I have used for reference.</p>
  <p><a href="https://docs.microsoft.com/en-us/java/api/overview/azure/identity-readme?view=azure-java-stable" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/java/api/overview/azure/identity-readme?view=azure-java-stable</a></p>
  <p><a href="https://docs.microsoft.com/en-us/azure/developer/java/sdk/identity#key-concepts" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/developer/java/sdk/identity#key-concepts</a></p>
  <p><a href="https://docs.microsoft.com/en-us/azure/developer/java/sdk/identity-azure-hosted-auth#default-azure-credential" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/developer/java/sdk/identity-azure-hosted-auth#default-azure-credential</a></p>