title: Azure KeyVault: how to create clientId and clientSecret?
body: <p>I want to connect my application to KeyVault. Usually, I could create a <strong>New Client Secret</strong> and use it in my code.</p>
  <pre><code>var _keyVaultClient = new KeyVaultClient(
      async (string authority, string resource, string scope) =&gt;
  {
      var authContext = new AuthenticationContext(authority);
      var clientCred = new ClientCredential(clientId, clientSecret);
      var result = await authContext.AcquireTokenAsync(resource, clientCred);
      return result.AccessToken;
  });
  </code></pre>
  <p>I could create a <a href="https://www.puresourcecode.com/dotnet/azure/save-and-retrieve-secret-from-azure-keyvault/" rel="nofollow noreferrer">new client secret</a> from the Azure Portal.</p>
  <p><a href="https://i.stack.imgur.com/8UyN5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8UyN5.png" alt="enter image description here" /></a></p>
  <p>Now, I can't find this option in KeyVault.</p>
  <p><a href="https://i.stack.imgur.com/eiWSV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eiWSV.png" alt="enter image description here" /></a></p>
  <p>In <em>Program.cs</em> I have something like</p>
  <pre><code>var keyVaultEndpoint = new Uri(Environment.GetEnvironmentVariable(&quot;VaultUri&quot;));
  configApp.AddAzureKeyVault(keyVaultEndpoint, new DefaultAzureCredential());
  </code></pre>
  <p>Locally is working but when I deploy the application to Azure I have this error:</p>
  <blockquote>
  <p>Application '/LM/W3SVC/1699246683/ROOT' with physical root
  'C:\home\site\wwwroot' has exited from Program.Main with exit code =
  '0'. First 30KB characters of captured stdout and stderr logs:</p>
  <p>[10:15:57 FTL] Host terminated unexpectedly
  Azure.Identity.CredentialUnavailableException: DefaultAzureCredential
  failed to retrieve a token from the included credentials.</p>
  <p>EnvironmentCredential authentication unavailable. Environment
  variables are not fully configured.</p>
  <p>ManagedIdentityCredential
  authentication unavailable, no managed identity endpoint found.</p>
  <p>SharedTokenCacheCredential authentication unavailable. No accounts
  were found in the cache.</p>
  <p>at Azure.Identity.DefaultAzureCredential.GetTokenAsync(Boolean isAsync,
  TokenRequestContext requestContext, CancellationToken
  cancellationToken)    at
  Azure.Identity.DefaultAzureCredential.GetTokenAsync(TokenRequestContext
  requestContext, CancellationToken cancellationToken)    at
  Azure.Security.KeyVault.ChallengeBasedAuthenticationPolicy.AuthenticateRequestAsync(HttpMessage
  message, Boolean async)    at
  Azure.Security.KeyVault.ChallengeBasedAuthenticationPolicy.ProcessCoreAsync(HttpMessage
  message, ReadOnlyMemory<code>1 pipeline, Boolean async)    at Azure.Core.Pipeline.RetryPolicy.ProcessAsync(HttpMessage message, ReadOnlyMemory</code>1 pipeline, Boolean async)    at
  Azure.Core.Pipeline.RetryPolicy.ProcessAsync(HttpMessage message,
  ReadOnlyMemory<code>1 pipeline, Boolean async)    at Azure.Core.Pipeline.HttpPipelineSynchronousPolicy.ProcessAsync(HttpMessage message, ReadOnlyMemory</code>1 pipeline)    at
  Azure.Core.Pipeline.HttpPipelineSynchronousPolicy.ProcessAsync(HttpMessage
  message, ReadOnlyMemory<code>1 pipeline)    at Azure.Core.Pipeline.HttpPipeline.SendRequestAsync(Request request, CancellationToken cancellationToken)    at Azure.Security.KeyVault.KeyVaultPipeline.SendRequestAsync(Request request, CancellationToken cancellationToken)    at Azure.Security.KeyVault.KeyVaultPipeline.GetPageAsync[T](Uri firstPageUri, String nextLink, Func</code>1 itemFactory, String
  operationName, CancellationToken cancellationToken)    at
  Azure.Core.PageResponseEnumerator.FuncAsyncPageable<code>1.AsPages(String continuationToken, Nullable</code>1 pageSizeHint)+MoveNext()    at
  Azure.Core.PageResponseEnumerator.FuncAsyncPageable<code>1.AsPages(String continuationToken, Nullable</code>1
  pageSizeHint)+System.Threading.Tasks.Sources.IValueTaskSource&lt;System.Boolean&gt;.GetResult()
  at Azure.AsyncPageable<code>1.GetAsyncEnumerator(CancellationToken cancellationToken)+MoveNext()    at Azure.AsyncPageable</code>1.GetAsyncEnumerator(CancellationToken
  cancellationToken)+MoveNext()    at
  Azure.AsyncPageable<code>1.GetAsyncEnumerator(CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource&lt;System.Boolean&gt;.GetResult() at Azure.Extensions.AspNetCore.Configuration.Secrets.AzureKeyVaultConfigurationProvider.LoadAsync() at Azure.Extensions.AspNetCore.Configuration.Secrets.AzureKeyVaultConfigurationProvider.LoadAsync() at Azure.Extensions.AspNetCore.Configuration.Secrets.AzureKeyVaultConfigurationProvider.Load() at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList</code>1
  providers)    at
  Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()    at
  Microsoft.Extensions.Hosting.HostBuilder.BuildAppConfiguration()    at
  Microsoft.Extensions.Hosting.HostBuilder.Build()    at
  Skoruba.IdentityServer4.STS.Identity.Program.Main(String[] args) in
  C:\Projects\IdentityServer4\src\Skoruba.IdentityServer4.STS.Identity\Program.cs:line
  26</p>
  <p>Process Id: 13436. File Version: 13.1.20234.8. Description: IIS
  ASP.NET Core Module V2 Request Handler. Commit:
  c75b3f7a2fb9fe21fd96c93c070fdfa88a2fbe97</p>
  </blockquote>