次要使用者驗證

雙重使用者驗證可為語音指令新增第二重安全防護。這項功能可為特定動作 (例如關閉監視攝影機或開門) 增添額外安全防護。雙重使用者驗證與特定裝置特徵無關,因此你可以決定何時讓 Google Assistant 發出驗證問題。舉例來說,您可以選擇對監視攝影機的 OnOff 特性發出驗證問題,但不要對燈具的 OnOff 特性發出驗證問題。您也可以讓 Assistant 針對相同動作在特定情況下發出驗證。舉例來說,您可以要求 Assistant 在 NFC 鑰匙圈不在門附近時,發出開門驗證要求,但如果鑰匙圈在附近,則不發出驗證要求。

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

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

雙重使用者驗證的使用時機

你可以為任何裝置類型或特性啟用雙重使用者驗證。 不過,您必須為某些安全性敏感的裝置類型和特徵導入雙重使用者驗證,才能通過整合認證。

下列特質和裝置類型組合必須使用 pinNeeded 驗證類型進行雙重使用者驗證:

  • 如果裝置類型為 CAMERA,則為 OnOff 特性。
  • 如果裝置類型為 DOOR、GARAGE、GATE 或 WINDOW,則為 OpenClose 特性。
  • 解鎖時的 LockUnlock 特性。
  • 解除或取消解除保全時的 ArmDisarm 特性。
  • 如果裝置類型為 NETWORK 或 ROUTER,則為 Reboot、SoftwareUpdate 或 NetworkControl 特性。

如果裝置類型為 AC_UNIT,且整合位於日本,則 TemperatureSetting 特徵必須使用 ackNeeded 驗證類型。

支援的驗證類型

支援的雙重使用者驗證問題類型如下:

  • 不驗證:不使用雙重使用者驗證的要求和回應。
  • ackNeeded:需要明確確認 (是或否) 的雙重使用者驗證,也可以使用特質狀態做為回應。不建議將這類驗證用於安全裝置和特質。
  • pinNeeded:需要個人識別碼 (PIN) 的雙重使用者驗證,適合用於安全裝置和特性。

沒有驗證問題

以下範例顯示成功的 EXECUTE 要求和回應,不需驗證即可開燈。

使用者 開燈。
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 simple

以下範例顯示簡單的要求和回應,其中包含調暗燈光的 ackNeeded 驗證,以及調暗燈光的確認。

使用者 調暗客廳的燈。
Google Assistant 我這就調暗客廳的燈。您確定嗎?
使用者 是。
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"
    }]
  }
}

ackNeeded 與特徵狀態

雙重使用者確認驗證,可使用特性的狀態。舉例來說,如果您使用 TemperatureSetting 特性,且同時設定 thermostatMode 和 thermostatTemperatureSetpoint,Assistant 可能會詢問「確定要將空調的暖氣設為 28 度嗎?」。

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

下列特徵和狀態支援 ackNeeded 搭配特徵狀態。如果列出特定特徵,表示支援該特徵的所有狀態。

  • ArmDisarm
    • 使用 ackNeeded 驗證類型啟動或取消啟動裝置,但如要解除或取消解除裝置,則必須使用 pinNeeded 驗證類型。
  • Fill
  • LockUnlock
    • 使用 ackNeeded 驗證類型鎖定裝置,並使用 pinNeeded 驗證類型解鎖。
  • OnOff
    • on
    • 請使用 ackNeeded 挑戰類型。這項特性與 CAMERA 裝置搭配使用時,必須提供 pinNeeded 驗證類型。
  • OpenClose
    • 請使用 ackNeeded 挑戰類型。如果這項特質與 DOOR、GARAGE、GATE 或 WINDOW 裝置搭配使用,則必須提供 pinNeeded 驗證類型。
  • Scene
  • TemperatureSetting
    • thermostatMode
    • thermostatTemperatureSetpoint
    • thermostatTemperatureSetpointHigh
    • thermostatTemperatureSetpointLow

以下範例顯示使用特徵狀態的 ackNeeded 驗證要求和回應。將空調模式切換為暖氣,並將溫度設為 28 度。接著,Assistant 會要求使用者確認是否要開啟暖氣並將溫度設為 28 度,因為回應中傳回的 thermostatTemperatureSetpoint 為 28。

使用者 將空調設為暖氣模式。
Google Assistant 確定要將空調的暖氣設為 28 度嗎?
使用者 是。
Google Assistant 正在將空調的暖氣設為 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 碼不正確或有效時的要求和回應範例:

使用者 解鎖門。
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 錯誤回應。請參閱「錯誤回應」。

使用者 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 碼的要求和回應。

使用者 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
      }
    }]
  }
}
使用者 調暗客廳的燈。
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 - Ok

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