c# - 无法从 Azure Key Vault 获取 token

标签 c# azure asp.net-identity blazor blazor-webassembly

我有一个使用 Identity 进行身份验证的 Blazor WASM 应用程序,该应用程序在周五运行良好。昨晚我去进行更改,在 Azure 中运行的应用程序和在我的计算机上本地运行的应用程序在启动后都开始出现异常。从一切正常到现在,环境或代码库没有任何变化。

应用程序运行,重定向到登录页面,获取在服务器上处理得很好,但在 .cshtml 文件中的第一行标记上引发异常(假设因为此时无法加密内容) :

An unhandled exception occurred while processing the request. CredentialUnavailableException: EnvironmentCredential authentication unavailable. Environment variables are not fully configured. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/environmentcredential/troubleshoot Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow(Exception ex, string additionalMessage)

AggregateException: Multiple exceptions were encountered while attempting to authenticate. (EnvironmentCredential authentication unavailable. Environment variables are not fully configured. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/environmentcredential/troubleshoot) (ManagedIdentityCredential authentication unavailable. 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. 'AADSTS50020: User account '{EmailHidden}' from identity provider 'live.com' does not exist in tenant 'Microsoft Services' and cannot access the application '{IDREDACTED}'(Visual Studio) in that tenant. 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. Trace ID: {IDREDACTED} Correlation ID: {IDREDACTED} Timestamp: 2021-12-20 19:46:59Z'.) (Stored credentials not found. Need to authenticate user in VSCode Azure Account. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/vscodecredential/troubleshoot) (Azure CLI not installed) (PowerShell is not installed.) Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow(Exception ex, string additionalMessage)

CredentialUnavailableException: DefaultAzureCredential failed to retrieve a token from the included credentials. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/defaultazurecredential/troubleshoot

  • EnvironmentCredential authentication unavailable. Environment variables are not fully configured. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/environmentcredential/troubleshoot
  • ManagedIdentityCredential authentication unavailable. 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. 'AADSTS50020: User account '{EmailHidden}' from identity provider 'live.com' does not exist in tenant 'Microsoft Services' and cannot access the application '{IDREDACTED}'(Visual Studio) in that tenant. 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. Trace ID: {IDREDACTED} Correlation ID: {IDREDACTED} Timestamp: 2021-12-20 19:46:59Z'.
  • Stored credentials not found. Need to authenticate user in VSCode Azure Account. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/vscodecredential/troubleshoot
  • Azure CLI not installed
  • PowerShell is not installed. Azure.Identity.DefaultAzureCredential.GetTokenFromSourcesAsync(TokenCredential[] sources, TokenRequestContext requestContext, bool async, CancellationToken cancellationToken)

CryptographicException: An error occurred while trying to encrypt the provided data. Refer to the inner exception for more information. Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Protect(byte[] plaintext)

我在相关文档和故障排除指南中找不到与我的设置和问题相关的任何内容。我觉得我必须遗漏一些简单的东西,比如某些凭据的过期或更改,但我找不到任何看起来是罪魁祸首的东西,并且代码库的任何部分都没有更改,Azure 环境也没有更改从我知道它起作用到开始,任何人都感动过它。

最佳答案

哎呀,在我折腾了两天之后,我通过在我的计算机上安装 Azure CLI 并从 PowerShell 窗口运行“az login”命令解决了这个问题。就这样。希望这可以节省其他人很多时间。

关于c# - 无法从 Azure Key Vault 获取 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70427351/

相关文章:

Azure CLI 与 Python SDK

azure - 部署azure函数应用程序时出现ARM模板错误

sql - Azure Multi-Tenancy 安全性 - Azure 联合 SQL、证书等

c# - 检查 URL 是否是有效的 Feed

C# 正则表达式匹配特殊字符

asp.net-core - Jwt 声明名称

c# - 播种 asp.net 核心身份角色

c# - UserManager.CreateAsync 挂起从单元测试而不是 Postman 执行

c# - 使用 AAD 帐户以外的 ms live 帐户时,Azure AD 身份验证失败

c# - 以编程方式 (C#) 将 Excel 转换为图像