次要使用者驗證

次要使用者驗證可讓您為語音指令增添雙重安全性。這可讓您為特定動作提供額外的安全防護,例如關閉監視攝影機或開門。次要使用者驗證並未與特定裝置特徵建立關聯,因此可讓您決定何時要發出 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"
      }
    }]
  }
}

錯誤回應

下列是可能會與您的回應一併傳回的錯誤代碼:

  • challengeFailedNotSetup這項操作需要安全碼,但你裝置的應用程式尚未設定安全碼。
  • tooManyFailedAttempts - 很抱歉,嘗試失敗次數過多。請前往裝置的應用程式完成這項操作。
  • pinIncorrect - 很抱歉,安全碼有誤。
  • userCancelled - 好的

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