Azure AD应用注册Web重定向URI批量更新失败求助
解决Azure AD应用注册重定向URI更新失败问题
问题原因分析
方法1失败原因
使用--web-redirect-uris传入多个URI时报错,大概率是现有URI的格式处理错误:你通过--output tsv获取的现有URI是制表符分隔,而非空格分隔,直接拼接后会导致CLI识别到无效格式。另外如果应用从未设置过web重定向URI,空值拼接也可能引发参数错误。
方法2失败原因
提示找不到web属性,说明你的应用注册尚未初始化web对象(之前从未配置过web类型的重定向URI),直接设置web.redirectUris会因为父对象不存在而失败。
正确解决方案
方案1:使用--web-redirect-uris参数(推荐,适合大多数场景)
正确获取并转换现有URI格式
# 获取现有web重定向URI,制表符分隔 existing_urls=$(az ad app show --id '<client-id>' --query "web.redirectUris" --output tsv) # 转换为空格分隔(符合--web-redirect-uris参数要求) existing_urls_space=$(echo "$existing_urls" | tr '\t' ' ')拼接新URI并执行更新
new_uri="https://hostname.com/callbacky" # 合并现有与新URI,自动忽略空值 all_uris="$existing_urls_space $new_uri" # 执行更新 az ad app update --id '<client-id>' --web-redirect-uris "$all_uris"注:如果是首次设置,直接传入多个空格分隔的URI即可,无需处理现有值。
方案2:使用--set参数(适合需要精确控制JSON结构的场景)
场景A:首次设置web重定向URI
需要先初始化web对象:
az ad app update --id '<client-id>' --set "web={redirectUris:['https://hostname.com/callbackx', 'https://hostname.com/callbacky']}"
场景B:已有web属性,添加新URI
借助jq工具处理数组(需提前安装jq):
# 获取现有URI的JSON数组 existing_array=$(az ad app show --id '<client-id>' --query "web.redirectUris" --output json) new_uri="https://hostname.com/callbacky" # 追加新URI到数组 updated_array=$(echo "$existing_array" | jq --arg new "$new_uri" '. += [$new]') # 执行更新 az ad app update --id '<client-id>' --set "web.redirectUris=$updated_array"
额外注意事项
- 确保Azure CLI是最新版本,旧版本可能存在参数兼容问题:执行
az upgrade升级。 - URI必须符合Azure AD的格式要求(比如必须是HTTPS,localhost除外),否则会提示无效值。
内容的提问来源于stack exchange,提问作者milorad
相关产品推荐
相关产品推荐

