次要使用者驗證

次要使用者驗證可讓您為語音指令新增雙重安全防護機制。這樣一來,您就能針對特定動作 (例如關閉監視攝影機或開啟門) 多添一層防護。次要使用者驗證不會與特定裝置特性建立關聯,因此您可以決定何時要發出 Google Assistant 驗證問題。舉例來說,您可以選擇為安全相機發出 OnOff 特徵驗證,但不針對光源的 OnOff 特徵發出挑戰。在特定情況下,相同操作也可能會發生 Assistant 問題驗證。例如,您可以要求 Assistant 發出驗證要求,要求在非鄰近該門的附近使用 NFC 鍵盤,但如果鑰匙檔案存在,則不發出驗證要求。

Assistant 可發出兩種驗證問題:明確確認或個人識別碼 (PIN)。這會將挑戰區塊新增到從 Assistant 傳送的 QUERYEXECUTE 意圖回您的動作,並且接受 challengeNeeded 錯誤回應。接著,Assistant 會使用驗證區塊中的挑戰資料,將意圖要求傳回動作。接著,您可以驗證驗證資料,判斷使用者是否提供了正確的安全性回應。

Assistant 會使用對話方塊來發出驗證問題,但如果您在非語音介面上使用 Assistant,則請在螢幕上完成 PIN 碼和確認動作。

支援的裝置類型

所有裝置類型都支援次要使用者驗證。

支援的裝置 traits

所有裝置特徵都支援次要使用者驗證。

支援的驗證類型

系統支援的次要使用者驗證驗證類型如下:

  • 無驗證問題 - 未使用次要使用者驗證挑戰的要求和回應。
  • ackNeeded:需要明確確認 (是或否) 的次要使用者驗證,且能使用特徵狀態做為回應意見回饋。此驗證類型不建議用於安全性裝置和特徵。
  • pinNeeded - 需要個人識別碼 (PIN) 的次要使用者驗證,最適合用於安全性裝置和特徵。

無挑戰

這個範例顯示成功的 EXECUTE 要求和回應,但沒有開啟燈具的問題。

User 開燈。
Google Assistant 好的,打開 3 盞燈。
要求
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "inputs": [{
    "intent": "action.devices.EXECUTE",
    "payload": {
      "commands": [{
        "devices": [{
          "id": "123"
        }],
        "execution": [{
          "command": "action.devices.commands.OnOff",
          "params": {
            "on": true
          }
        }]
      }]
    }
  }]
}
回應
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "payload": {
    "commands": [{
      "ids": ["123"],
      "status": "SUCCESS",
      "states": {
        "on": true,
        "online": true
      }
    }]
  }
}

ackNeeded

次要使用者確認驗證,可為特徵或簡易確認驗證使用多個狀態。

以下為 ackNeeded 驗證類型:

確認需求 (簡易)

這個範例顯示一個簡單的要求和回應,其中包含用於調暗燈光的 ackNeeded 驗證,以及用來調暗燈光的確認訊息。

User 將客廳的燈光調暗。
Google Assistant 正在調暗客廳的燈您確定嗎?
User 有的
Google Assistant 正在調暗客廳的燈
要求 1
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "inputs": [{
    "intent": "action.devices.EXECUTE",
    "payload": {
      "commands": [{
        "devices": [{
          "id": "123"
        }],
        "execution": [{
          "command": "action.devices.commands.BrightnessAbsolute",
          "params": {
            "brightness": 12
          }
        }]
      }]
    }
  }]
}
回應 1
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "payload": {
    "commands": [{
      "ids": ["123"],
      "status": "ERROR",
      "errorCode": "challengeNeeded",
      "challengeNeeded": {
        "type": "ackNeeded"
      }
    }]
  }
}
要求 2
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "inputs": [{
    "intent": "action.devices.EXECUTE",
    "payload": {
      "commands": [{
        "devices": [{
          "id": "123"
        }],
        "execution": [{
          "command": "action.devices.commands.BrightnessAbsolute",
          "params": {
            "brightness": 12
          },
          "challenge": {
            "ack": true
          }
        }]
      }]
    }
  }]
}
回應 2
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "payload": {
    "commands": [{
      "ids": ["123"],
      "status": "SUCCESS"
    }]
  }
}

某些特徵狀態已確認

可使用特徵狀態的次要使用者確認驗證。舉例來說,如果使用 TemperatureSetting 特徵,且同時設定了 thermostatModethermostatTemperatureSetpointAssistant 可以詢問「是否確定要將空調的暖氣設為 28 度嗎?」

您也可以在回應中加入狀態,讓 Assistant 根據指定的要求執行特定動作。

下列特徵和狀態支援直向狀態的 ackNeeded。列出特定特徵代表支援其所有狀態。

這個範例顯示了使用特徵狀態的 ackNeeded 挑戰的要求和回應。這個模式會將空調模式變更為暖氣,並將溫度設為 28 度。然後,Assistant 會要求使用者確認開啟暖氣,並將溫度設為 28 度,因為 28thermostatTemperatureSetpoint 會在回應中傳回為狀態。

User 將空調模式設為暖氣模式。
Google Assistant 確定要將空調的暖氣設為 28 度嗎?
User 有的
Google Assistantnt 正在將空調的暖氣設為 28 度
要求 1
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "inputs": [{
    "intent": "action.devices.EXECUTE",
    "payload": {
      "commands": [{
        "devices": [{
          "id": "123"
        }],
        "execution": [{
          "command": "action.devices.commands.TemperatureSetting",
          "params": {
            "thermostatMode": "heat"
          }
        }]
      }]
    }
  }]
}
回應 1
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "payload": {
    "commands": [{
      "ids": ["123"],
      "status": "ERROR",
      "states": {
        "thermostatMode": "heat",
        "thermostatTemperatureSetpoint": 28
      },
      "errorCode": "challengeNeeded",
      "challengeNeeded": {
        "type": "ackNeeded"
      }
    }]
  }
}
要求 2
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "inputs": [{
    "intent": "action.devices.EXECUTE",
    "payload": {
      "commands": [{
        "devices": [{
          "id": "123"
        }],
        "execution": [{
          "command": "action.devices.commands.TemperatureSetting",
          "params": {
            "thermostatMode": "heat"
          },
          "challenge": {
            "ack": true
          }
        }]
      }]
    }
  }]
}
回應 2
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "payload": {
    "commands": [{
      "ids": ["123"],
      "status": "SUCCESS",
      "states": {
        "thermostatMode": "heat",
        "thermostatTemperatureSetpoint": 28
      }
    }]
  }
}

pinNeeded

建議針對安全性裝置進行 pinNeeded 驗證。

以下範例顯示具有 pinNeeded 挑戰的初始要求和回應。這個範例會傳回包含 pinNeeded 挑戰的回應,因此 Assistant 要求提供 PIN 碼。此時,使用者可以提供錯誤或有效的 PIN 碼。

以下是錯誤或有效 PIN 碼的要求與回應範例:

User 將門解鎖。
Google Assistant 可以告訴我你的安全碼嗎?
要求
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "inputs": [{
    "intent": "action.devices.EXECUTE",
    "payload": {
      "commands": [{
        "devices": [{
          "id": "123"
        }],
        "execution": [{
          "command": "action.devices.commands.LockUnlock",
          "params": {
            "lock": false
          }
        }]
      }]
    }
  }]
}
回應
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "payload": {
    "commands": [{
      "ids": ["123"],
      "status": "ERROR",
      "errorCode": "challengeNeeded",
      "challengeNeeded": {
        "type": "pinNeeded"
      }
    }]
  }
}

PIN 不正確

以下範例顯示具有 challengeFailedPinNeeded 挑戰的要求和回應。應在初始 pinNeeded 驗證失敗後使用這項挑戰。

當傳回 challengeFailedPinNeeded 類型時,Assistant 會再次要求提供安全碼。如果使用者執行失敗的嘗試次數過多,您可以傳回 tooManyFailedAttempts 錯誤回應。請參閱錯誤回應

User 333222
Google Assistant 很抱歉,安全碼有誤。 可以告訴我你的安全碼嗎?
要求
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "inputs": [{
    "intent": "action.devices.EXECUTE",
    "payload": {
      "commands": [{
        "devices": [{
          "id": "123"
        }],
        "execution": [{
          "command": "action.devices.commands.LockUnlock",
          "params": {
            "lock": false
          },
          "challenge": {
            "pin": "333222"
          }
        }]
      }]
    }
  }]
}
回應
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "payload": {
    "commands": [{
      "ids": ["123"],
      "status": "ERROR",
      "errorCode": "challengeNeeded",
      "challengeNeeded": {
        "type": "challengeFailedPinNeeded"
      }
    }]
  }
}

有效的 PIN 碼

本範例顯示了有效 PIN 碼的要求和回應。

User 333444
Google Assistant 正在為門解鎖。
要求
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "inputs": [{
    "intent": "action.devices.EXECUTE",
    "payload": {
      "commands": [{
        "devices": [{
          "id": "123"
        }],
        "execution": [{
          "command": "action.devices.commands.LockUnlock",
          "params": {
            "lock": false
          },
          "challenge": {
            "pin": "333444"
          }
        }]
      }]
    }
  }]
}
回應
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "payload": {
    "commands": [{
      "ids": ["123"],
      "status": "SUCCESS",
      "states": {
        "isLocked": false,
        "isJammed": false
      }
    }]
  }
}
User 將客廳的燈光調暗。
Google Assistant 可以告訴我你的安全碼嗎?
要求
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "inputs": [{
    "intent": "action.devices.EXECUTE",
    "payload": {
      "commands": [{
        "devices": [{
          "id": "123"
        }],
        "execution": [{
          "command": "action.devices.commands.BrightnessAbsolute",
          "params": {
            "brightness": 12
          }
        }]
      }]
    }
  }]
}
回應
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "payload": {
    "commands": [{
      "ids": ["123"],
      "status": "ERROR",
      "errorCode": "challengeNeeded",
      "challengeNeeded": {
        "type": "pinNeeded"
      }
    }]
  }
}

錯誤回應

以下是一些可在回應中傳回的錯誤代碼:

  • tooManyFailedAttempts - 很抱歉,嘗試失敗次數過多。 請前往裝置的應用程式完成這項操作。
  • pinIncorrect - 很抱歉,安全碼不正確。
  • userCancelled - 確定

請參閱錯誤和例外狀況的完整清單。