Azure API 管理订阅的自定义 API 密钥

Custom API key for Azure API management subscription

我正在考虑将 API 网关从另一个解决方案更改为 Azure API 管理。这是针对在我们无法控制的 end-user 设备上拥有数百万现有用户/安装的现有应用。

为了保持现有应用程序版本对用户有效,这意味着我需要为 API 键使用自定义 header 以及自定义 API 键值。

我可以在 API 管理门户中更改 API 密钥 header 的名称,但我还没有找到使用现有 API 键值而不是使用新的 Azure-generated API 键。

有办法吗?我们不能强迫现有用户升级应用程序,并且完全禁用 API 键似乎也不是一个好主意。

您可以使用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

请注意,在将现有键值设置为主键或辅助键之前,您应该将其从原始 subscription/delete 具有现有键的订阅中删除。换句话说,密钥是唯一的,你不能在不同的订阅中保留相同的密钥。

对于那些不使用 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