AuthenticatorResponse

Baseline 已廣泛支援

此功能已成熟,並可在多種裝置和瀏覽器版本上執行。自 2021 年 9 月起,所有瀏覽器均已支援此功能。

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

AuthenticatorResponse 介面屬於 Web Authentication API,它是為金鑰對提供加密信任根的介面的基礎介面。子介面包含來自瀏覽器(例如挑戰來源)的資訊,並且都可能由 PublicKeyCredential.response 返回。

基於 AuthenticatorResponse 的介面

以下是基於 AuthenticatorResponse 介面的介面列表。

例項屬性

AuthenticatorResponse.clientDataJSON

一個 ArrayBuffer 中的 JSON 字串,表示傳遞給 CredentialsContainer.create()CredentialsContainer.get() 的客戶端資料。

例項方法

無。

示例

獲取 AuthenticatorAssertionResponse

js
const options = {
  challenge: new Uint8Array([
    /* bytes sent from the server */
  ]),
};

navigator.credentials
  .get({ publicKey: options })
  .then((credentialInfoAssertion) => {
    const assertionResponse = credentialInfoAssertion.response;
    // send assertion response back to the server
    // to proceed with the control of the credential
  })
  .catch((err) => console.error(err));

獲取 AuthenticatorAttestationResponse

js
const publicKey = {
  challenge: new Uint8Array([
    21, 31, 105 /* 29 more random bytes generated by the server */,
  ]),
  rp: {
    name: "Example CORP",
    id: "login.example.com",
  },
  user: {
    id: new Uint8Array(16),
    name: "msanchez@example.com",
    displayName: "Maria Sanchez",
  },
  pubKeyCredParams: [
    {
      type: "public-key",
      alg: -7,
    },
  ],
};

navigator.credentials
  .create({ publicKey })
  .then((newCredentialInfo) => {
    const attestationResponse = newCredentialInfo.response;
  })
  .catch((err) => console.error(err));

規範

規範
Web Authentication:訪問公鑰憑證的 API - 第 3 級
# authenticatorresponse

瀏覽器相容性

另見