MinimalPermissionsPlugin
檢查應用程式是否使用最少的許可權來呼叫 API。 使用來自指定本機資料夾的 API 資訊。
外掛程式實例定義
{
"name": "MinimalPermissionsPlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
"configSection": "minimalPermissionsPlugin"
}
設定範例
{
"minimalPermissionsPlugin": {
"apiSpecsFolderPath": "./api-specs"
}
}
設定屬性
屬性 | 說明 | 預設 |
---|---|---|
apiSpecsFolderPath |
具有 API 規格之資料夾的相對或絕對路徑 | 無 |
命令列選項
None
備註
外掛程式 MinimalPermissionsPlugin
會檢查應用程式是否使用最少的許可權來呼叫 API。 若要檢查許可權,外掛程式會使用位於指定本機資料夾中之 API 的相關信息。
定義 API 許可權
外掛程式 MinimalPermissionsPlugin
支援檢查使用 OAuth 保護之 API 的 OAuth 許可權。 外掛程式會使用提供的 API 規格中的資訊,計算呼叫應用程式中使用的 API 所需的最小許可權。 然後,外掛程式會將 JSON Web 令牌 (JWT) 令牌中使用的許可權與開發 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.22.0"
}
}
相關部分是 securitySchemes
區段,您可以在其中定義 API 所使用的 OAuth 範圍。 然後,針對每個作業,您會在 security
區段中包含必要的範圍。