共用方式為


在自訂連接器上新增多重驗證

多重驗證 (multi-auth) 是一項功能,讓使用者可以選擇要用來建立連接的驗證方法 (相對於只限於一種驗證類型) 以建立連接。

對於連接器,會透過 apiProperties.json 檔案定義驗證類型的集合 connectionParameterSets

重要

在自訂連接器上,不支援在自訂連接器上啟用多個驗證。 請改用 Microsoft Power Platform 連接器 CLI 來建立具有多重驗證的自訂連接器。

如何啟用多重驗證

apiProperties.json 檔案中新增 connectionParameterSets,然後 connectionParameterSets.values根據需要為連接器填入集合 connectionParameters

注意

若要了解連接參數和驗證類型的相關詳細資訊,請造訪連接參數

以下是 connectionParameterSets 的結構:

"connectionParameterSets": {
  // uiDefinition for the parameter sets.
  "uiDefinition": {
    "displayname": "Select the authorization type",
    "description": "<<Enter here your description>>"
  },
  "values": [
    // Connection parameter set
    {
      "name": "<parameter set name>",
      // uiDefinition for this parameter set.
      "uiDefinition": {
        "displayname": "<display name>",
        "description": "<description text>"
      },
      "parameters": {
        // Schema matches existing "connectionParameters"
        "<parameter name>": {
          "type": "string | securestring | oauthsetting"
        },
        "<parameter name>:clientId": {
          "type": "string",
          "uiDefinition": {
            "schema": {
              // For string types, the description must be placed in
              // uiDefinition.schema.description to be shown in the description box
              "type": "string",
              "description": "<description text>"
            },
            "displayName": "<display name>",
          }
        }
      }
    },
    {
      "name": "<parameter set name 2>"
      // ...
    }
  ]
}

範例

設定與 API 金鑰和基本驗證

"connectionParameterSets": {
    "uiDefinition": {
        "displayName": "Authentication Type",
        "description": "Type of authentication to be used."
    },
    "values": [
        {
            "name": "basic-auth",
            "uiDefinition": {
                "displayName": "Use your X credentials",
                "description": "Log in using your username and password for X."
            },
            "parameters": {
                "username": {
                    "type": "string",
                    "uiDefinition": {
                        "displayName": "X username",
                        "schema":{
                            "description": "The username for X",
                            "type": "string"
                        },
                        "tooltip": "Provide your X username",
                        "constraints": {
                            "required": "true"
                        }
                    }
                },
                "password": {
                    "type": "securestring",
                    "uiDefinition": {
                        "displayName": "X password",
                        "schema":{
                            "description": "The password for X",
                            "type": "securestring"
                        },
                        "tooltip": "Provide your X password",
                        "constraints": {
                            "required": "true"
                        }
                    }
                }
            }
        },
        {
            "name": "api-auth",
            "uiDefinition": {
                "displayName": "Use X API Key",
                "description": "Log in using X's API Key."
            },
            "parameters": {
                "api_key": {
                    "type": "securestring",
                    "uiDefinition": {
                        "constraints": {
                            "clearText": false,
                            "required": "true",
                            "tabIndex": 3
                        },
                        "schema":{
                            "description": "Enter your API Key for X",
                            "type": "securestring"
                        },
                        "displayName": "API Key generated in X"
                    }
                },
                "environment": {
                    "type": "string",
                    "uiDefinition": {
                        "displayName": "Environment",
                        "schema":{
                            "description": "The API environment to use; either production or sandbox",
                            "type": "string"
                        },
                        "tooltip": "Select an API environment to use",
                        "constraints": {
                            "required": "true",
                            "allowedValues": [
                                {
                                    "text": "Sandbox",
                                    "value": "YOUR_SANDBOX_VALUE_HERE"
                                },
                                {
                                    "text": "Production",
                                    "value": "YOUR_PROD_VALUE_HERE"
                                }
                            ]
                        }
                    }
                }
            }
        }
    ]
}

使用 Entra ID 和 OAUTH 2.0 的設定

可以有兩個使用相同類型的 connectionParameters。 在此案例中,兩種授權都使用 oauthSetting類型:一個允許使用者使用 Entra ID 建立連接,而另一個則是轉到自訂端點。

"connectionParameterSets": {
    "uiDefinition": {
        "displayName": "Authentication Type",
        "description": "Type of authentication to be used."
    },
    "values": [
        {
            "name": "aad-auth",
            "uiDefinition": {
                "displayName": "Use default shared application",
                "description": "Log in using the standard X app."
            },
            "parameters": {
                "token": {
                    "oAuthSettings": {
                        "clientId": "YOUR_AAD_APPLICATION_ID_HERE",
                        "customParameters": {
                            "loginUri": {
                                "value": "https://login.windows.net"
                            },
                            "resourceUri": {
                                "value": "https://graph.microsoft.com"
                            },
                            "tenantId": {
                                "value": "common"
                            }
                        },
                        "identityProvider": "aad",
                        "properties": {
                            "IsFirstParty": "False"
                        },
                        "redirectMode": "GlobalPerConnector",
                        "scopes": [
                            "Group.ReadWrite.All offline_access"
                        ]
                    },
                    "type": "oauthSetting"
                }
            }
        },
        {
            "name": "custom-app-auth",
            "uiDefinition": {
                "displayName": "Use the X authentication app",
                "description": "Log in using X app."
            },
            "parameters": {
                "token": {
                    "type": "oauthSetting",
                    "oAuthSettings": {
                        "clientId": "YOUR_CLIENT_ID_HERE",
                        "identityProvider": "oauth2",
                        "redirectMode": "GlobalPerConnector",
                        "customParameters": {
                            "authorizationUrl": {
                                "value": "https://login.dummy.net/request"
                            },
                            "refreshUrl": {
                                "value": "https://login.dummy.net/token"
                            },
                            "tokenUrl": {
                                "value": "https://login.dummy.net/token"
                            }
                        }
                    }
                }
            }
        }
    ]
}

請在此處查看 RescoCloud 連接器,取得如何實施多重驗證的最新範例。