我正在研究将API网关从另一种解决方案更改为Azure API管理。这适用于现有应用程序,在我们无法控制的最终用户设备上拥有数百万个现有用户/安装。
要使现有的应用程序版本对用户有效,这意味着我需要为API密钥以及自定义API密钥值使用自定义标头。
我可以在API管理门户中更改API密钥标头的名称,但是我没有找到一种方法来设置具有现有API密钥值的订阅,而不是使用新的Azure生成的API密钥。
有没有办法做到这一点?我们不能强迫现有用户升级应用程序,并且完全禁用API密钥也不是一个好主意。
答案 0 :(得分:2)
您可以使用Set-AzureRmApiManagementSubscription设置订阅的主键和辅助键。
$apimContext = New-AzureRmApiManagementContext -ResourceGroupName "{resource group name}" -ServiceName "{your APIM name}"
Set-AzureRmApiManagementSubscription -Context $apimContext -SubscriptionId "{subscription id}" -PrimaryKey "{an existing API key}" -SecondaryKey "{an existing API key}" -State "Active"
首先可以使用Get-AzureRmApiManagementSubscription来获取订阅ID 。
请注意,在将现有键值设置为主键或辅助键之前,应将其从原始订阅中删除/删除具有现有键的订阅。换句话说,密钥是唯一的,您不能在不同的订阅中保留相同的密钥。
答案 1 :(得分:0)
对于那些不使用 AzureRm
(过时)而是使用 Az
powershell 的人,这里是命令
$apimContext = New-AzApiManagementContext -ResourceGroupName "{resource group name}" -ServiceName "{your APIM name}"
Set-AzApiManagementSubscription -Context $apimContext -SubscriptionId -"SubscriptionId" -PrimaryKey "{key1}" -SecondaryKey "{key2}" -State "Active"
获取订阅列表:
Get-AzApiManagementSubscription -Context $apimContext