AuthPlugin
使用 API 密钥或 OAuth2 模拟身份验证和授权。
插件实例定义
{
"name": "AuthPlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
"configSection": "auth"
}
配置示例:API 密钥
{
"auth": {
"type": "apiKey",
"apiKey": {
"parameters": [
{
"in": "header",
"name": "x-api-key"
},
{
"in": "query",
"name": "code"
}
],
"allowedKeys": [
"1234"
]
}
}
}
配置示例:OAuth2
{
"auth": {
"type": "oauth2",
"oauth2": {
"metadataUrl": "https://login.microsoftonline.com/organizations/v2.0/.well-known/openid-configuration",
"allowedApplications": [
"00000000-0000-0000-0000-000000000000"
],
"allowedAudiences": [
"00000000-0000-0000-0000-000000000000"
],
"allowedPrincipals": [
"00000000-0000-0000-0000-000000000000"
],
"allowedTenants":[
"00000000-0000-0000-0000-000000000000"
],
"issuer": "https://login.microsoftonline.com/ffffffff-eeee-dddd-cccc-bbbbbbbbbbb0/v2.0",
"scopes": [
"Posts.Read"
],
"validateLifetime": true,
"validateSigningKey": true
}
}
}
配置属性
properties |
描述 |
必须 |
type |
开发代理应使用的身份验证和授权类型。 允许的值:apiKey 、oauth2 |
是 |
apiKey |
API 密钥身份验证和授权的配置。 |
是的,何时 type 为 apiKey |
oauth2 |
OAuth2 身份验证和授权的配置。 |
是的,何时 type 为 oauth2 |
API 密钥配置属性
properties |
描述 |
必须 |
allowedKeys |
允许的 API 密钥列表。 |
是 |
parameters |
包含 API 密钥的参数列表。 |
是 |
参数配置属性
properties |
描述 |
必须 |
in |
应在其中找到参数的位置。 允许的值:header 、query 、cookie |
是 |
name |
参数的名称。 |
是 |
OAuth2 配置属性
properties |
描述 |
必须 |
metadataUrl |
OpenID Connect 元数据文档的 URL。 |
是 |
allowedApplications |
允许的应用程序 ID 的列表。 保留空以不验证为其颁发令牌的应用程序(appid 或 azp 声明)。 |
否 |
allowedAudiences |
允许访问群体的列表。 留空以不验证颁发令牌的受众(aud 声明)。 |
否 |
allowedPrincipals |
允许的主体列表。 留空以不验证颁发令牌的主体(oid 声明)。 |
否 |
allowedTenants |
允许的租户列表。 留空以不验证颁发令牌的租户(tid 声明)。 |
否 |
issuer |
允许的令牌颁发者。 留空以不验证令牌颁发者。 |
否 |
roles |
允许的角色列表。 保留为空,以不验证令牌上的角色(roles 声明)。 |
否 |
scopes |
允许的范围列表。 保留空以不验证令牌上的作用域(scp 声明)。 |
否 |
validateLifetime |
设置为 false 禁用验证令牌生存期。 默认为 true 。 |
否 |
validateSigningKey |
false 设置为禁用验证令牌签名。 违约 true |
否 |
命令行选项
无