[英]Azure key vault integration from visual studio 2022 connected services
I am trying to store stripe credentials in the Azure Key Vault.我正在尝试将条带凭证存储在 Azure Key Vault 中。 I used the connected services tab in my Visual studio application, That seemed to work.
我在我的 Visual Studio 应用程序中使用了连接的服务选项卡,这似乎有效。 However when I run the application locally I get errors in the program file.
但是,当我在本地运行应用程序时,程序文件中出现错误。 I am using do.net 6 core razor pages.
我正在使用 do.net 6 核心 razor 页。
These are the errors hope you can help.这些是错误希望你能帮助。
DefaultAzureCredential failed to retrieve a token from the included credentials. DefaultAzureCredential 无法从包含的凭据中检索令牌。 See the troubleshooting guide for more information.
有关详细信息,请参阅故障排除指南。 https://aka.ms/azsdk.net/identity/defaultazurecredential/troubleshoot
https://aka.ms/azsdk.net/identity/defaultazurecredential/疑难解答
This is the Program class...这是程序 class...
public class Program
{
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, config) =>
{
var keyVaultEndpoint = new
Uri(Environment.GetEnvironmentVariable("VaultUri"));
config.AddAzureKeyVault(keyVaultEndpoint, new DefaultAzureCredential());
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
public static void Main(string[] args)
{
var host = CreateHostBuilder(args).Build();
using (var scope = host.Services.CreateScope())
{
var services = scope.ServiceProvider;
var loggerFactory = services.GetRequiredService<ILoggerFactory>();
try
{
var context = services.GetRequiredService<ApplicationDbContext>();
var userManager = services.GetRequiredService<UserManager<IdentityUser>>();
var roleManager = services.GetRequiredService<RoleManager<IdentityRole>>();
}
catch (Exception ex)
{
var logger = loggerFactory.CreateLogger<Program>();
logger.LogError(ex, "An error occurred seeding the DB.");
}
}
host.Run();
}
}
... ...
Try these试试这些
Authenticate you Azure credential in Visual Studio在 Visual Studio 中验证您的 Azure 凭据
Tools - Options - Azure Service authentication - Choose an Account or Authenticate with Azure credentials工具 - 选项 - Azure 服务身份验证 - 选择一个帐户或使用 Azure 凭据进行身份验证
Ensure you have right access in AZ Keyvault (Get and List)确保您有权访问 AZ Keyvault(获取和列出)
Az portal - Keyvault - Access policy - Add - Select principal and save it az portal - Keyvault - Access policy - 添加 - Select principal 并保存
Validate these settings in launchSettings.json
file在
launchSettings.json
文件中验证这些设置
You need just to provide your TenantId for using Visual Studio credential:您只需提供您的 TenantId 即可使用 Visual Studio 凭据:
new DefaultAzureCredential(new DefaultAzureCredentialOptions { VisualStudioTenantId = "your_tenant_guid" })
PS.附言。 The TenantId is visible on the Azure Active Directory main page
TenantId 在 Azure Active Directory 主页上可见
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.