PublicKeyCredential: id 屬性

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

idPublicKeyCredential 介面的一個只讀屬性,它繼承自 Credential,表示當前 PublicKeyCredential 例項的識別符號。

此屬性是 PublicKeyCredential.rawIdbase64url 編碼版本。

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

一個字串,它是 PublicKeyCredential.rawIdbase64url 編碼版本。

示例

js
const publicKey = {
  challenge: new Uint8Array(26) /* this actually is given 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 })
  .then((newCredentialInfo) => {
    const id = newCredentialInfo.id;
    // Do something with the id

    // send attestation response and client extensions
    // to the server to proceed with the registration
    // of the credential
  })
  .catch((err) => {
    console.error(err);
  });

規範

此特性似乎未在任何規範中定義。

瀏覽器相容性

另見