다음을 통해 공유


최소 권한 플러그인

지정된 API 작업을 수행하는 데 필요한 최소 권한을 검색합니다. 지정된 로컬 폴더의 API 정보를 사용합니다.

기록된 API 요청이 토큰을 최소 API 권한으로 사용하는지 여부를 확인하는 개발자 프록시를 보여 주는 명령줄의 스크린샷.

플러그 인 인스턴스 정의

{
  "name": "MinimalPermissionsPlugin",
  "enabled": true,
  "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
  "configSection": "minimalPermissionsPlugin"
}

구성 예

{
  "minimalPermissionsPlugin": {
    "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v1.0.0/minimalpermissionsplugin.schema.json",
    "apiSpecsFolderPath": "./api-specs"
  }
}

구성 속성

속성 설명 기본값
apiSpecsFolderPath API 사양이 있는 폴더에 대한 상대 또는 절대 경로 없음
schemeName 최소 사용 권한을 결정하는 데 사용되는 보안 체계 정의의 이름입니다. 지정하지 않으면 플러그 인은 사양의 첫 번째 oauth2 체계에서 정보를 읽습니다. 없음

명령줄 옵션

없음

설명

플러그 인은 MinimalPermissionsPlugin 앱이 최소 사용 권한을 사용하여 API를 호출하는지 확인합니다. 사용 권한을 확인하기 위해 플러그 인은 지정된 로컬 폴더에 있는 API에 대한 정보를 사용합니다.

API 권한 정의

플러그 인은 MinimalPermissionsPlugin OAuth로 보호되는 API에 대한 OAuth 권한 확인을 지원합니다. 플러그 인은 제공된 API 사양의 정보를 사용하여 앱에서 사용되는 API를 호출하는 데 필요한 최소 권한을 계산합니다.

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.22.0"
  }
}

관련 부분은 securitySchemes API에서 사용하는 OAuth 범위를 정의하는 섹션입니다. 그런 다음 각 작업에 필요한 범위를 섹션에 security 포함합니다.

API 사양의 변수 바꾸기

일부 API 사양은 서버 URL에 변수를 포함할 수 있습니다. 변수를 사용하는 것은 다양한 환경(예: 개발, 스테이징, 프로덕션), API 버전 또는 테넌트를 수용하는 일반적인 방법입니다. 변수가 있는 URL은 다음과 같습니다.

openapi: 3.0.4
info:
  title: SharePoint REST API
  description: SharePoint REST API
  version: v1.0
servers:
  - url: https://{tenant}.sharepoint.com
    variables:
      tenant:
        default: contoso

플러그 인은 MinimalPermissionsPlugin API 사양 콘텐츠의 변수 바꾸기를 지원합니다. 변수를 바꾸려면 Dev Proxy를 --env 옵션으로 시작하고 변수 이름과 값을 지정합니다. 예를 들어 변수를 tenantcontoso바꾸려면 다음 명령을 사용합니다.

devproxy --env tenant=northwind

이 명령은 API 사양의 변수를 값tenant으로 바꿉 northwind 니다. 플러그 인은 대체된 URL을 사용하여 앱이 최소 사용 권한을 사용하여 API를 호출하는지 확인합니다.

자세한 정보