认证插件

使用 API 密钥或 OAuth2 模拟身份验证和授权。

命令提示符的屏幕截图,其中开发人员代理使用本地运行的 Azure 函数上的 API 密钥模拟身份验证。

配置示例:API 密钥

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v3.3.1/rc.schema.json",
  "plugins": [
    {
      "name": "AuthPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
      "configSection": "auth"
    }
  ],
  "auth": {
    "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v3.3.1/authplugin.schema.json",
    "type": "apiKey",
    "apiKey": {
      "parameters": [
        {
          "in": "header",
          "name": "x-api-key"
        },
        {
          "in": "query",
          "name": "code"
        }
      ],
      "allowedKeys": [
        "1234"
      ]
    }
  }
}

配置示例:OAuth2

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v3.3.1/rc.schema.json",
  "plugins": [
    {
      "name": "AuthPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
      "configSection": "auth"
    }
  ],
  "auth": {
    "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v3.3.1/authplugin.schema.json",
    "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 否

命令行选项

无