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);
  });

规范

此特性似乎未在任何规范中定义。

浏览器兼容性

另见