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

浏览器兼容性

另见