Skip to content

Instantly share code, notes, and snippets.

@asadrefai
Last active July 7, 2021 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asadrefai/82f60fe172dda74e770ed4885cadd740 to your computer and use it in GitHub Desktop.
Save asadrefai/82f60fe172dda74e770ed4885cadd740 to your computer and use it in GitHub Desktop.
const string secretName = "Test";
var keyVaultName = "test-blog-kv";
var kvUri = $"https://{keyVaultName}.vault.azure.net";
// Creating an object and excluding methods which I do not want to be executed. Although these are executed in series, i.e. in my code, due to Enviornment Variables or Visual Studio exception was thrown.
// Ideally I would expect, if one method does not work, without breaking code it should move to another one.
DefaultAzureCredentialOptions options = new DefaultAzureCredentialOptions();
options.ExcludeEnvironmentCredential = true;
options.ExcludeInteractiveBrowserCredential = true;
options.ExcludeManagedIdentityCredential = true;
options.ExcludeSharedTokenCacheCredential = true;
options.ExcludeVisualStudioCodeCredential = true;
options.ExcludeVisualStudioCredential = true;
var client = new SecretClient(new Uri(kvUri), new DefaultAzureCredential(options));
var secret = await client.GetSecretAsync(secretName);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment