AuthenticatorResponse: clientDataJSON 属性
AuthenticatorResponse 接口的 clientDataJSON 属性以 ArrayBuffer 的形式存储一个 JSON 字符串,该字符串表示传递给 navigator.credentials.create() 或 navigator.credentials.get() 的客户端数据。此属性仅在 AuthenticatorResponse 的子对象上访问,具体是 AuthenticatorAttestationResponse 或 AuthenticatorAssertionResponse。
值
一个 ArrayBuffer。
实例属性
将 clientDataJSON 对象从 ArrayBuffer 转换为 JavaScript 对象后,它将具有以下属性:
challenge-
从依赖方服务器发送的加密挑战的 base64url 编码版本。原始值作为
challenge选项在CredentialsContainer.get()或CredentialsContainer.create()中传递。 crossOrigin可选-
一个布尔值。如果设置为
true,则表示调用上下文是一个与祖先帧不同源的<iframe>。 origin-
客户端/浏览器提供的依赖方的完全限定源。我们应该期望依赖方的 ID 是此值的后缀。
tokenBinding可选 已弃用-
一个描述与依赖方通信的 令牌绑定协议 状态的对象。它有两个属性:
status:一个字符串,可以是"supported"(表示客户端支持令牌绑定但未与依赖方协商)或"present"(表示已使用令牌绑定)。id:一个字符串,是用于通信的令牌绑定 ID 的 base64url 编码。
如果缺少此属性,则表示客户端不支持令牌绑定。
注意:根据规范的 Level 3,
tokenBinding已被弃用,但该字段被保留,以防将来用于其他目的。 topOrigin可选-
包含依赖方的完全限定顶级源。仅当
crossOrigin为true时设置。 type-
一个字符串,当检索现有凭证时为
"webauthn.get",当创建新凭证时为"webauthn.create"。
示例
js
function arrayBufferToStr(buf) {
return String.fromCharCode.apply(null, new Uint8Array(buf));
}
// pk is a PublicKeyCredential that is the result of a create() or get() Promise
const clientDataStr = arrayBufferToStr(pk.response.clientDataJSON);
const clientDataObj = JSON.parse(clientDataStr);
console.log(clientDataObj.type); // "webauthn.create" or "webauthn.get"
console.log(clientDataObj.challenge); // base64 encoded String containing the original challenge
console.log(clientDataObj.origin); // the window.origin
规范
| 规范 |
|---|
| Web Authentication:访问公钥凭证的 API - 第 3 级 # dom-authenticatorresponse-clientdatajson |
浏览器兼容性
加载中…