PublicKeyCredential: response 属性
PublicKeyCredential 接口中只读的 response 属性是一个 AuthenticatorResponse 对象,它由验证器发送给用户代理,用于创建/获取凭据。此响应中包含的信息将由依赖方服务器用于验证请求的合法性。
AuthenticatorResponse 要么是
- 一个
AuthenticatorAttestationResponse(当PublicKeyCredential通过CredentialsContainer.create()创建时) - 一个
AuthenticatorAssertionResponse(当PublicKeyCredential通过CredentialsContainer.get()获取时)。
为了验证凭据的创建,依赖方服务器需要
- 此响应
- 客户端的扩展(由
PublicKeyCredential.getClientExtensionResults()提供)来验证请求。
注意: 在验证现有凭据的获取时,依赖方服务器需要整个 PublicKeyCredential 对象以及客户端扩展。
注意: 此属性只能用于顶级上下文,在 <iframe> 中不可用。
值
一个 AuthenticatorResponse 对象,其中包含依赖方脚本将接收到的数据,这些数据应发送到依赖方服务器以验证创建或获取请求。此对象包含来自客户端(AuthenticatorResponse/clientDataJSON)和来自验证器的数据。
示例
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
});
规范
| 规范 |
|---|
| Web Authentication:访问公钥凭证的 API - 第 3 级 # dom-publickeycredential-response |
浏览器兼容性
加载中…