问题描述
在本地windows环境中,安装了azd(Azure Developer CLI)最新版后,遇见无法登录Azure中国区。报错和之前在devops的pipeline上错误一样(DevOps上的报错文章请参考:https://www.cnblogs.com/lulight/p/19149913)。
执行命令:
#配置azd命令执行环境为中国区Azure azd config set cloud.name AzureChinaCloud# 登录 azd up
报错信息:
ERROR: failed to authenticate: unable to resolve an endpoint: ResolveEndpoints(): TenantDiscoveryResponse: issuer from OIDC discovery 'https://login.partner.microsoftonline.cn/{tenantid}/v2.0' does not match authority 'https://login.chinacloudapi.cn/organizations/' or a known pattern
错误截图:

解决方法
最直接的办法是通过命令安装旧版本,比如1.19.0 。在测试使用命令 winget install microsoft.azd --version 1.19.0 安装失败。

最后,通过公网搜索的方式,找到老版本的azd 下载文档地址:Release azure-dev-cli_1.19.0 · Azure/azure-dev

下载msi安装文件,本地安装后。再次使用azd up,就可以正常登录到中国区Azure
注:需要先执行 uninstall 命令卸载最新版本。 执行命令: winget uninstall microsoft.azd
登录成功!

参考资料
使用Azure Developer CLI (azd)部署项目时候遇见无法登录中国区Azure的报错 : https://www.cnblogs.com/lulight/p/19149913
Install or update the Azure Developer CLI: https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/install-azd?tabs=winget-windows%2Cbrew-mac%2Cscript-linux&pivots=os-windows
azure-dev-cli_1.19.0 : https://github.com/Azure/azure-dev/releases/tag/azure-dev-cli_1.19.0