次の方法で共有


ApiCenterMinimalPermissionsPlugin

アプリが最小限のアクセス許可を使用して API を呼び出すかどうかを確認します。 指定した Azure API Center インスタンスの API 情報を使用します。

記録された API 要求でトークンの最小限の API アクセス許可が使用されているかどうかを確認する開発プロキシを示すコマンド プロンプトのスクリーンショット。

プラグイン インスタンスの定義

{
  "name": "ApiCenterMinimalPermissionsPlugin",
  "enabled": true,
  "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
  "configSection": "apiCenterMinimalPermissionsPlugin"
}

構成の例

{
  "apiCenterMinimalPermissionsPlugin": {
    "subscriptionId": "cdae2297-7aa6-4195-bbb1-dcd89153cc72",
    "resourceGroupName": "resource-group-name",
    "serviceName": "apic-instance",
    "workspaceName": "default"
  }
}

構成プロパティ

プロパティ 説明 Default
resourceGroupName Azure API Center が配置されているリソース グループの名前。 なし
serviceName アプリで使用される API が登録されているかどうかを確認するためにデベロッパー プロキシが使用する必要がある Azure API センター インスタンスの名前。 なし
subscriptionId Azure API Center インスタンスが配置されている Azure サブスクリプションの ID。 なし
workspace 使用する Azure API Center ワークスペースの名前。 default

コマンドライン オプション

なし

解説

このプラグインは ApiCenterMinimalPermissionsPlugin 、アプリが最小限のアクセス許可を使用して API を呼び出しているかどうかを確認します。 アクセス許可を確認するために、プラグインは、指定された Azure API Center インスタンスに登録されている API に関する情報を使用します。

Azure API Center に接続する

Azure API Center に接続するために、プラグインは (この順序で) Azure 資格情報を使用します。

  • Environment
  • ワークロード ID
  • マネージド ID
  • Visual Studio
  • Visual Studio Code
  • Azure CLI
  • Azure PowerShell
  • Azure Developer CLI

プラグインが Azure にアクセスするためのアクセス トークンを取得できない場合は、エラーが表示され、Dev Proxy によって無効になります。 これらのツールのいずれかを使用して Azure にサインインし、開発プロキシを再起動してプラグインを ApiCenterMinimalPermissionsPlugin 使用します。

CI/CD パイプラインで開発プロキシを使用する場合は、環境変数として 、、serviceNameresourceGroupNameおよびプロパティの値subscriptionIdworkspaceName渡すことができます。 環境変数を使用するには、値 @の名前の前に次の例を付けます。

{
  "apiCenterMinimalPermissionsPlugin": {
    "subscriptionId": "@AZURE_SUBSCRIPTION_ID",
    "resourceGroupName": "@AZURE_RESOURCE_GROUP_NAME",
    "serviceName": "@AZURE_APIC_INSTANCE_NAME",
    "workspaceName": "@AZURE_APIC_WORKSPACE_NAME"
  }
}

この例では、プラグインはApiCenterMinimalPermissionsPlugin、それぞれ 、、resourceGroupName、、serviceNameworkspaceNameおよび環境変数の AZURE_APIC_INSTANCE_NAMEAZURE_SUBSCRIPTION_IDAZURE_APIC_WORKSPACE_NAMEAZURE_RESOURCE_GROUP_NAME値にプロパティを設定subscriptionIdします。

API のアクセス許可を定義する

このプラグインでは ApiCenterMinimalPermissionsPlugin 、Azure API Center に登録されている OAuth で保護された API の OAuth アクセス許可の確認がサポートされています。 このプラグインは、API Center からの情報を使用して、アプリで使用される API を呼び出すために必要な最小限のアクセス許可を計算します。 次に、プラグインは、JSON Web トークン (JWT) トークンで使用されるアクセス許可を、Dev Proxy が記録した要求に必要な最小限のスコープと比較します。

API のアクセス許可を定義するには、API の OpenAPI 定義に含めます。 次の例は、OpenAPI 定義で API のアクセス許可を定義する方法を示しています。

{
  "openapi": "3.0.1",
  "info": {
    "title": "Northwind API",
    "description": "Northwind API",
    "version": "v1.0"
  },
  "servers": [
    {
      "url": "https://api.northwind.com"
    }
  ],
  "components": {
    "securitySchemes": {
      "OAuth2": {
        "type": "oauth2",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://login.microsoftonline.com/common/oauth2/authorize",
            "tokenUrl": "https://login.microsoftonline.com/common/oauth2/token",
            "scopes": {
              "customer.read": "Grants access to ready customer info",
              "customer.readwrite": "Grants access to read and write customer info"
            }
          }
        }
      }
    },
    "schemas": {
      "Customer": {
        "type": "object",
        // [...] trimmed for brevity
      }
    }
  },
  "paths": {
    "/customers/{customers-id}": {
      "description": "Provides operations to manage a customer",
      "get": {
        "summary": "Get customer by ID",
        "operationId": "getCustomerById",
        "security": [
          {
            "OAuth2": [
              "customer.read"
            ]
          },
          {
            "OAuth2": [
              "customer.readwrite"
            ]
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json; charset=utf-8": {
                "schema": {
                  "$ref": "#/components/schemas/Customer"
                }
              }
            }
          }
        }
      },
      "patch": {
        "summary": "Update customer by ID",
        "operationId": "updateCustomerById",
        "security": [
          {
            "OAuth2": [
              "customer.readwrite"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Customer"
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "No Content"
          }
        }
      },
      "parameters": [
        {
          "name": "customers-id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ]
    }
  },
  "x-ms-generated-by": {
    "toolName": "Dev Proxy",
    "toolVersion": "0.19.0"
  }
}

関連する部分は securitySchemes 、API で使用する OAuth スコープを定義するセクションです。 次に、操作ごとに、セクションに必要なスコープを security 含めます。

詳細