I have the following code for obtaining a secret from the Azure key vault:
public static async Task GetToken(string authority, string resource,
Access Key Vault in .Net code Azure Setting:- App Service- 1-Enable-MSI(Managed service identity)-ON
Key Vault: 1-Open Key Vault 2-Select Access Policies from the Key Vault resource blade
3- Click the [+ Add new] button at the top of the blade 4-Click Select Principal to select the application(App Service) you created earlier
.Net Code:- Code to Access key vault secrets in .Net Code
var azureServiceTokenProvider = new AzureServiceTokenProvider();
var keyVaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));
var secret = keyVaultClient.GetSecretAsync("https://test.vault.azure.net/", "clientid").Result.Value;