简体   繁体   English

在生产中使用 InteractiveBrowserCredential 对 Azure Key Vault 进行身份验证将不起作用

[英]Using InteractiveBrowserCredential to authenticate to Azure Key Vault on production won't work

I want to read a secret from Azure Key Vault from my ASP.NET web application.我想从我的 ASP.NET web 应用程序中读取 Azure Key Vault 的秘密。 In order to do that I don't want to authenticate the application (service principal), but the individual users (user principal).为此,我不想对应用程序(服务主体)进行身份验证,而是对单个用户(用户主体)进行身份验证。 From all the possible credential types, I've concluded the best one to achieve this is InteractiveBrowserCredential:从所有可能的凭证类型中,我总结出最好的一种是 InteractiveBrowserCredential:

DefaultAzureCredential ManagedIdentityCredential DefaultAzureCredential ManagedIdentityCredential
EnvironmentCredential环境证书
ClientSecretCredential ClientSecretCredential
CertificateCredential证书凭证
UserPasswordCredential用户密码凭据
DeviceCodeCredential设备代码凭据
InteractiveBrowserCredential InteractiveBrowserCredential

Here's my code:这是我的代码:

var client = new SecretClient(new Uri(keyVaultUrl), new InteractiveBrowserCredential();
KeyVaultSecret secret = client.GetSecret(secretName);
string password = secret.Value;

This works well on localhost - I get prompted for my Azure AD user and password, and I have access to the vault.这在 localhost 上运行良好 - 系统提示我输入 Azure AD 用户和密码,并且我可以访问保管库。 However, I notice this is not my default browser but a IIS Express worker process instead.但是,我注意到这不是我的默认浏览器,而是 IIS Express 工作进程。

1 1

When running this same code on production, I get the following error:在生产中运行相同的代码时,我收到以下错误:

Azure.Identity.AuthenticationFailedException: InteractiveBrowserCredential authentication failed: Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Azure.Identity.AuthenticationFailedException:InteractiveBrowserCredential 身份验证失败:当应用程序未在 UserInteractive 模式下运行时显示模式对话框或表单不是有效操作。 Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.指定 ServiceNotification 或 DefaultDesktopOnly 样式以显示来自服务应用程序的通知。 ---> System.InvalidOperationException ---> System.InvalidOperationException

Afaik it should be opening a browser, not a modal dialog. Afaik 它应该打开浏览器,而不是模式对话框。 Can someone help my understand what's going on here?有人可以帮助我了解这里发生了什么吗?

According to the error, your hosting environment does not support UserInteractive model and it cannot open a modal dialog box or form automatically.根据错误,您的托管环境不支持UserInteractive model 并且无法自动打开模式对话框或表单。 But when we use the InteractiveBrowserCredential to do auth, the running environment should be able to open a modal dialog box or form automatically then we can do auth.但是当我们使用InteractiveBrowserCredential进行鉴权时,运行环境应该能够自动打开一个模态对话框或表单,然后我们就可以进行鉴权了。 For more details, please refer to here .更多详情,请参阅此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM