PublicKeyCredential: rawId 屬性

Baseline 已廣泛支援

此功能已成熟,並可在多種裝置和瀏覽器版本上執行。自 2021 年 9 月起,所有瀏覽器均已支援此功能。

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

rawIdPublicKeyCredential 介面的一個只讀屬性,它是一個 ArrayBuffer 物件,包含憑據的識別符號。

PublicKeyCredential.id 屬性是此識別符號的 base64url 編碼版本。

注意: 此屬性只能用於頂級上下文,在 <iframe> 中不可用。

一個 ArrayBuffer,包含憑據的識別符號。該識別符號預計是全域性唯一的,並分配給當前的 PublicKeyCredential 及其相關的 AuthenticatorAssertionResponse

示例

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 rawId = pubKeyCredential.rawId;
    // Do something with rawId
  })
  .catch((err) => {
    // Deal with any error
  });

規範

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

瀏覽器相容性