PublicKeyCredential: authenticatorAttachment 屬性

Baseline 2023
新推出

自 ⁨2023 年 11 月⁩ 起,此功能可在最新的裝置和瀏覽器版本中執行。此功能可能不適用於較舊的裝置或瀏覽器。

安全上下文: 此功能僅在安全上下文(HTTPS)中可用,且支援此功能的瀏覽器數量有限。

PublicKeyCredential 介面的只讀屬性 authenticatorAttachment 是一個字串,用於指示在關聯的 navigator.credentials.create()navigator.credentials.get() 呼叫期間使用的認證器的通用類別。

一個字串,其值將是以下值之一:

"platform"

認證器是 WebAuthn 執行的裝置的一部分(稱為平臺認證器),因此 WebAuthn 將使用該平臺可用的傳輸與其通訊,例如特定於平臺的 API。繫結到平臺認證器的公鑰憑證稱為平臺憑證

"cross-platform"

認證器不是 WebAuthn 執行的裝置的一部分(稱為漫遊認證器,因為它可以在不同裝置之間漫遊),因此 WebAuthn 將使用跨平臺傳輸協議(如藍牙或 NFC)與其通訊。繫結到漫遊認證器的公鑰憑證稱為漫遊憑證

示例

js
const options = {
  challenge: new Uint8Array(26) /* from the server */,
  rp: {
    name: "Example CORP",
    id: "login.example.com",
  },
  user: {
    id: new Uint8Array(26) /* To be changed for each user */,
    name: "canand@example.com",
    displayName: "Carina Anand",
  },
  pubKeyCredParams: [
    {
      type: "public-key",
      alg: -7,
    },
  ],
};

navigator.credentials
  .create({ publicKey: options })
  .then((pubKeyCredential) => {
    const attachment = pubKeyCredential.authenticatorAttachment;
    // Do something with authenticatorAttachment
  })
  .catch((err) => {
    // Deal with any error
  });

規範

規範
Web Authentication:訪問公鑰憑證的 API - 第 3 級
# dom-publickeycredential-authenticatorattachment

瀏覽器相容性