简体   繁体   English

Azure visual studio 2022 connected services 的 key vault 集成

[英]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/疑难解答

  • EnvironmentCredential authentication unavailable. EnvironmentCredential 身份验证不可用。 Environment variables are not fully configured.环境变量没有完全配置。 See the troubleshooting guide for more information.有关详细信息,请参阅故障排除指南。 https://aka.ms/azsdk.net/identity/environmentcredential/troubleshoot https://aka.ms/azsdk.net/identity/environmentcredential/troubleshoot
  • ManagedIdentityCredential authentication unavailable. ManagedIdentityCredential 身份验证不可用。 Multiple attempts failed to obtain a token from the managed identity endpoint.多次尝试未能从托管标识终结点获取令牌。
  • Process "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\lybeojxv.4oe\TokenService\Microsoft.Asal.TokenService.exe" has failed with unexpected error: TS003: Error, TS004: Unable to get access token.进程“C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\lybeojxv.4oe\TokenService\Microsoft.Asal.TokenService.exe”因意外错误而失败:TS003:错误,TS004:无法获取访问令牌。 'AADSTS50020: User account '{EmailHidden}' from identity provider 'live.com' does not exist in tenant 'Microsoft Services' and cannot access the application '872cd9fa-d31f-45e0-9eab-6e460a02d1f1'(Visual Studio) in that tenant. 'AADSTS50020:来自身份提供者'live.com'的用户帐户'{EmailHidden}'在租户'Microsoft Services'中不存在,无法访问该租户中的应用程序'872cd9fa-d31f-45e0-9eab-6e460a02d1f1'(Visual Studio) . The account needs to be added as an external user in the tenant first.需要先在租户中将账号添加为外部用户。 Sign out and sign in again with a different Azure Active Directory user account.注销并使用不同的 Azure Active Directory 用户帐户再次登录。 Trace ID: b90f1908-e45e-4679-aadc-64dbc7452600 Correlation ID: 62078fe0-4072-4e16-8ed7-6b5060844d88 Timestamp: 2022-02-09 07:51:08Z'.跟踪 ID:b90f1908-e45e-4679-aadc-64dbc7452600 相关 ID:62078fe0-4072-4e16-8ed7-6b5060844d88 时间戳:2022-02-09 07:51:08Z'。
  • Stored credentials not found.未找到存储的凭据。 Need to authenticate user in VSCode Azure Account.需要在 VSCode Azure 帐户中对用户进行身份验证。 See the troubleshooting guide for more information.有关详细信息,请参阅故障排除指南。 https://aka.ms/azsdk.net/identity/vscodecredential/troubleshoot https://aka.ms/azsdk.net/identity/vscodecredential/疑难解答
  • Please run 'az login' to set up account请运行“az login”来设置帐户
  • PowerShell is not installed. PowerShell 未安装。

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 filelaunchSettings.json文件中验证这些设置

启动设置.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.

相关问题 如何在 Visual Studio 中将 Key Vault 帐户更改为连接服务 - How to change Key Vault Account in Visual Studio as a Connected service 有没有办法通过 Visual Studio 上的托管标识在 localhost 中使用 Azure Key Vault? - Is there a way to work with Azure Key Vault in localhost with Managed Identity on Visual Studio? Web API与Azure Key Vault的集成测试 - Integration Tests for Web API with Azure Key Vault Mac 上的 Visual Studio 2022 Azure Devops 存储库 - Visual Studio 2022 on Mac Azure Devops Repository Azure Service Fabric持续集成在Visual Studio Team Services中失败(是VSO) - Azure Service Fabric continuous integration fails in Visual Studio Team Services (was VSO) 无法使用 Visual Studio 2022 中的 Timer Trigger 调试 Azure 函数 V4 - Not able to debug Azure function V4 with Timer Trigger from Visual studio 2022 如何从 Visual Studio 2022 运行 WcfTestClient? - How to run WcfTestClient from Visual Studio 2022? 从 Visual Studio 2022 生成 NuGet package - Generating NuGet package from Visual Studio 2022 从 azure 密钥保管库中检索秘密 - retrieve secret from azure key vault 未能从 Azure Key Vault 获取令牌 - Failure to get token from Azure Key Vault
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM