PublicKeyCredential: thuộc tính response

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2021.

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

Thuộc tính chỉ đọc response của giao diện PublicKeyCredential là một đối tượng AuthenticatorResponse được gửi từ thiết bị xác thực đến user agent cho việc tạo/tìm nạp thông tin xác thực. Thông tin trong phản hồi này sẽ được máy chủ của relying party sử dụng để xác minh rằng yêu cầu là hợp lệ.

Một AuthenticatorResponse có thể là:

Để xác thực việc tạo thông tin xác thực, máy chủ của relying party cần cả hai:

Note: Khi xác thực việc tìm nạp thông tin xác thực hiện có, toàn bộ đối tượng PublicKeyCredential và các tiện ích mở rộng client là cần thiết cho máy chủ của relying party.

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 đối tượng AuthenticatorResponse chứa dữ liệu mà script của relying party sẽ nhận và cần được gửi đến máy chủ của relying party để xác thực yêu cầu tạo hoặc tìm nạp. Đối tượng này chứa dữ liệu từ client (AuthenticatorResponse/clientDataJSON) và từ thiết bị xác thực.

Ví dụ

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

navigator.credentials
  .create({ publicKey: options })
  .then((pubKeyCredential) => {
    const response = pubKeyCredential.response;
    const clientExtResults = pubKeyCredential.getClientExtensionResults();
    // Send response and client extensions to the server so that it can validate
    // and create credentials
  })
  .catch((err) => {
    // Deal with any error
  });

Thông số kỹ thuật

Specification
Web Authentication: An API for accessing Public Key Credentials - Level 3
# dom-publickeycredential-response

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