MinimalPermissionsPlugin
检查应用是否使用最少的权限来调用 API。 使用指定本地文件夹中的 API 信息。
插件实例定义
{
"name": "MinimalPermissionsPlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
"configSection": "minimalPermissionsPlugin"
}
配置示例
{
"minimalPermissionsPlugin": {
"apiSpecsFolderPath": "./api-specs"
}
}
配置属性
properties | 说明 | 默认 |
---|---|---|
apiSpecsFolderPath |
具有 API 规范的文件夹的相对路径或绝对路径 | 无 |
命令行选项
无
注解
该 MinimalPermissionsPlugin
插件检查应用是否使用最少的权限来调用 API。 若要检查权限,插件使用有关位于指定本地文件夹中的 API 的信息。
定义 API 权限
该 MinimalPermissionsPlugin
插件支持检查使用 OAuth 保护的 API 的 OAuth 权限。 该插件使用提供的 API 规范中的信息计算调用应用中使用的 API 所需的最小权限。 然后,该插件将 JSON Web 令牌(JWT)令牌中使用的权限与开发代理记录的请求所需的最低范围进行比较。
若要定义 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
。