Azure API 管理:如何使用 PowerShell 或 Azure CLI 在 Azure API 管理中添加授权连接或凭据提供程序?

问题描述 投票:0回答:1

我想使用 PowerShell 或 Azure CLI 在 Azure API 管理中创建授权或凭据提供程序。因此,我已使用 Azure 管理 REST API 进行AuthorizationProvider - 创建或更新,使用Invoke-AzRestMethod,如下所述

function Add-Authorizaztion {
    [CmdletBinding()]
    param (
        [string]$managementURL,
        [string]$subscriptionId,
        [string]$tenantId,
        [string]$environment,
        [string]$tenantName,
        [string]$accessToken
    )

    $apiManagementURL = "$managementURL/subscriptions/$subscriptionId/resourceGroups/test-rg-$environment/providers/Microsoft.ApiManagement/service/apim-test-$environment-xyz/authorizationProviders/testdevhealthcarewsxyz-$($tenantName)?api-version=2022-08-01"
    $body = @"
    {
     "properties":{
        "displayName":"testdevhealthcarewsxyz-$tenantName",
        "identityProvider":"aad",
        "oauth2":{
           "redirectUrl":"https://authorization-manager.consent.azure-apim.net/redirect/apim/apim-test-$environment-xyz",
           "grantTypes":{
              "clientCredentials":{
                 "loginUri":"",
                 "resourceUri":"https://dicom.healthcareapis.azure.com",
                 "tenantId":"$tenantId"
              }
           }
        }
     }
  }
"@

    $response = Invoke-Rest -accessToken $accessToken -url $apiManagementURL -body $body -method "PUT"

    return $response
}

正如预期的那样,在 Azure API 管理中创建了授权或凭据提供程序

但是,我没有看到任何添加连接的选项

有没有办法使用 PowerShell 或 Azure CLI 在授权中添加连接或在 Azure API 管理中添加凭据提供程序

azure powershell azure-api-management
1个回答
0
投票

解决需求后,我发现 Azure API 管理凭据管理器中没有与连接相关的 PowerShell / CLI 命令。特别是对于连接,添加它的唯一可能的方法是通过 Azure 门户界面。

可以使用

ARM/Bicep/Terraform
模板启用 credential provider,但无法在其中添加连接。

我尝试使用二头肌代码创建一个凭据提供程序,如下所示,并且能够成功实现。

param apiexists string = 'APIWebAppapi10June'
resource apiservice 'Microsoft.ApiManagement/service@2023-03-01-preview' existing = {
  name: apiexists
}
resource apiconnect 'Microsoft.ApiManagement/service/authorizationProviders@2023-03-01-preview' = {
  name: 'newjprovider'
  parent: apiservice
  properties: {
    displayName: 'newjprovider'
    identityProvider: 'aad'
    oauth2: {
      grantTypes: {
        authorizationCode: {
          clientID: 'xxxx'
        }
        clientCredentials: {
          
        }
      }
      redirectUrl: 'https://authorization-manager.consent.azure-apim.net/redirect/apim/${apiexists}'
    }
  }
}

输出

enter image description here

enter image description here

现在,如果我想添加连接,我需要在部署后通过门户本身来完成。

为此,请转到

Credential provider >> Create a connection
,并提供如图所示的所需详细信息。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.