title: Programatically adding Secrets to Key Vault in C#
body: <p>I am attempting to put some output from a service I am running in a Key Vault in Azure.  The output of my service will be user credentials which is why I want to use Key Vault for this purpose.  </p>
  
  <p>So far, I have tried the KeyVaultClient's SetSecretAsync method, but it's not working for me, I am not getting any error messages however I'm also not seeing a new secret created in my targetted KeyVault.  I have not been able to find a KeyVaultClient Add Secret method as it does not exist, am I using the right object/method here? </p>
  
  <p>The method in question here is AddResult. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>    private static AzureKeyVault instance;
      private static KeyVaultClient client;
      private AzureKeyVault()
      {
          //initialize the azure key vault
          var vaultAddress = ConfigurationManager.AppSettings["VaultUri"];
          client = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(GetAccessToken));
  
  
      }
      public static async Task&lt;string&gt; GetAccessToken(string authority, string resource, string scope)
      {
          var clientId = ConfigurationManager.AppSettings["ClientID"];
          var clientSecret = ConfigurationManager.AppSettings["ClientSecret"];
          ClientCredential clientCredential = new ClientCredential(clientId, clientSecret);
  
          var context = new AuthenticationContext(authority, TokenCache.DefaultShared);
          var result = await context.AcquireTokenAsync(resource, clientCredential);
  
          return result.AccessToken;
      }
  
  
      public static AzureKeyVault GetInstance
      {
          get
          {
              if (instance == null)
              {
                  instance = new AzureKeyVault();
              }
              return instance;
          }
      }
  
      public void AddResult(string machineIPAndPort, BruteForceResult result)
      {
          client.SetSecretAsync("https://vaultURI(redacted).vault.azure.net/", machineIPAndPort, JsonConvert.SerializeObject(result));
      }
  </code></pre>