PublicKeyCredential: thuộc tính id

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Thuộc tính chỉ đọc id của giao diện PublicKeyCredential là một chuỗi, kế thừa từ Credential, đại diện cho định danh của phiên bản PublicKeyCredential hiện tại.

Thuộc tính này là phiên bản được mã hóa base64url của PublicKeyCredential.rawId.

Note: Thuộc tính này chỉ có thể được sử dụng trong ngữ cảnh cấp cao nhất và sẽ không có sẵn trong một <iframe> chẳng hạn.

Giá trị

Một chuỗi là phiên bản được mã hóa base64url của PublicKeyCredential.rawId.

Ví dụ

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

Thông số kỹ thuật

Tính năng này dường như chưa được định nghĩa trong bất kỳ thông số kỹ thuật nào.

Tương thích trình duyệt

Xem thêm