0

I am adding below code in my program.cs file

public class Program 

{ 
public static void Main(string[] args) 
{ 

CreateHostBuilder(args).Build().Run(); 

} 
public static IHostBuilder CreateHostBuilder(string[] args) => 
Host.CreateDefaultBuilder(args) 
.ConfigureWebHostDefaults(webBuilder => 
{
 webBuilder.UseStartup<Startup>(); 

}) 
.ConfigureAppConfiguration((context, config) => 

{

 var builtConfig = config.Build(); 
var vaultName = builtConfig["keyvault"]; 

var keyVaultClient = new KeyVaultClient( 

async (authoriy, resource, scope) => 

{ 

var credential = new DefaultAzureCredential(false);
 
var token = credential.GetToken( 
new TokenRequestContext( new[] {"https://vault.azure.net/.default" } 
) 

); 

return token.Token; }); 

config.AddAzureKeyVault( 

vaultName, keyVaultClient, 
new DefaultKeyVaultSecretManager());

 }); 

What I am doing exactly is to get values from key vault which is in ASP.net But getting Exception unhandled error.

Microsoft.Azure.KeyVault.Models.KeyVaultErrorException:'Operation returned an invalid status code 'Not Found'

After retrieving values I need to perform keyvault workflow in logicapps.

Please help me to resolve my error.

avariant
  • 2,234
  • 5
  • 25
  • 33
Saile B
  • 3
  • 2
  • the error may occurs becuase of keyvault url in your code https://<>.vault.azure.net/.default . because of .default it may occur once remove this and try again. – vijaya Mar 28 '23 at 04:58
  • @vijaya - As per your comment, I have tried removing the .default in the URL and it is working now. I am new to Logic Apps, so could you please assist me how can I use keyvault in logic apps? – Saile B Mar 28 '23 at 05:33

1 Answers1

0

Thanks to @Deepak paramesh addressing this issue. As per his SO question the error may occurs becuase of keyvault url in your code

"https://<<vaultName>>.vault.azure.net/.default"

by removing .default the error get resolved.

if you want to use key vault in logic Apps you can search for key vault in built in logic Apps connectors.

  • In logic Apps i have taken Recurrance trigger you may use any of the triggers based on your requirement.
  • Then after trigger you need to add action. In search box search for Azure key vault connector.
  • As shown in below image you can see different available azure key vault actions. Here i have taken Get secret action.

enter image description here

  • Then you need to add Connection name and Authentication as Managed identity. You need to enable system assigned managed identity in your logic App. Then mention Vault name. In this way you can establish azure key vault connection to logic Apps. enter image description here enter image description here

Refer this Key vault MS Document.

vijaya
  • 1,525
  • 1
  • 2
  • 6