PublicKeyCredential: phương thức getClientExtensionResults()

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.

Phương thức getClientExtensionResults() của giao diện PublicKeyCredential trả về một đối tượng ánh xạ các định danh của tiện ích mở rộng được yêu cầu trong quá trình tạo hoặc xác thực thông tin xác thực, và kết quả xử lý của chúng bởi user agent.

Trong quá trình tạo hoặc tìm nạp PublicKeyCredential (qua navigator.credentials.create()navigator.credentials.get() tương ứng), có thể yêu cầu xử lý "tùy chỉnh" bởi client cho các tiện ích mở rộng khác nhau, được chỉ định trong thuộc tính extensions của tùy chọn publicKey. Bạn có thể tìm thêm thông tin về việc yêu cầu các tiện ích mở rộng khác nhau trong Web Authentication extensions.

Note: getClientExtensionResults() chỉ trả về kết quả từ các tiện ích mở rộng được xử lý bởi user agent (client). Kết quả từ các tiện ích mở rộng được xử lý bởi thiết bị xác thực có thể được tìm thấy trong authenticator data có sẵn trong AuthenticatorAssertionResponse.authenticatorData.

Cú pháp

js
getClientExtensionResults()

Tham số

Không có.

Giá trị trả về

Một đối tượng trong đó mỗi mục nhập là chuỗi định danh của tiện ích mở rộng làm khóa, và đầu ra từ việc xử lý tiện ích mở rộng bởi client làm giá trị.

Ngoại lệ

SecurityError DOMException

Miền RP không hợp lệ.

Ví dụ

js
const publicKey = {
  // Here are the extension "inputs"
  extensions: {
    appid: "https://accounts.example.com",
  },
  allowCredentials: {
    id: "fgrt46jfgd...",
    transports: ["usb", "nfc"],
    type: "public-key",
  },
  challenge: new Uint8Array(16) /* from the server */,
};

navigator.credentials
  .get({ publicKey })
  .then((publicKeyCred) => {
    const myResults = publicKeyCred.getClientExtensionResults();
    // myResults will contain the output of processing the "appid" extension
  })
  .catch((err) => {
    console.error(err);
  });

Thông số kỹ thuật

Thông số kỹ thuật
Web Authentication: An API for accessing Public Key Credentials - Level 3
# dom-publickeycredential-getclientextensionresults

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

Note: Các tiện ích mở rộng là tùy chọn và các trình duyệt khác nhau có thể nhận ra các tiện ích mở rộng khác nhau. Việc xử lý tiện ích mở rộng luôn là tùy chọn cho client: nếu một trình duyệt không nhận ra một tiện ích mở rộng nhất định, nó sẽ bỏ qua nó. Để biết thông tin về tiện ích mở rộng nào được các trình duyệt hỗ trợ, xem Web Authentication extensions.

Xem thêm