身份驗證插件

使用 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
    }
  }
}

設定屬性

屬性 描述 必要
type 開發 Proxy 應該使用的驗證和授權類型。 允許值︰apiKey 和 oauth2 是的
apiKey API 金鑰驗證和授權的設定。 是,當 type 為 apiKey
oauth2 OAuth2 驗證和授權的設定。 是,當 type 為 oauth2

API 金鑰組態屬性

屬性 描述 必要
allowedKeys 允許的 API 金鑰清單。 是的
parameters 包含 API 金鑰的參數清單。 是的

參陣組態屬性

屬性 描述 必要
in 預期會找到 參數的位置。 允許的值:header、、 querycookie 是的
name 參數的名稱。 是的

OAuth2 組態屬性

屬性 描述 必要
metadataUrl OpenID Connect 元數據檔的 URL。 是的
allowedApplications 允許的應用程式識別碼清單。 保留空白,以不驗證發出令牌的應用程式(appid 或 azp 宣告)。 否
allowedAudiences 允許的物件清單。 保留空白,以不驗證發出令牌的物件(aud 宣告)。 否
allowedPrincipals 允許的主體清單。 保留空白,以不驗證發出令牌的主體(oid 宣告)。 否
allowedTenants 允許的租用戶清單。 保留空白,以不驗證發出令牌的租使用者(tid 宣告)。 否
issuer 允許的令牌簽發者。 保留空白,以不驗證令牌簽發者。 否
roles 允許的角色清單。 保留空白,以不驗證令牌上的角色(roles 宣告)。 否
scopes 允許的範圍清單。 保留空白,以不驗證令牌上的範圍(scp 宣告)。 否
validateLifetime 設定為 以 false 停用驗證令牌存留期。 預設 true。 否
validateSigningKey 設定為 以 false 停用驗證令牌簽章。 違約 true 否

命令列選項

無