AuthenticatorResponse.clientDataJSON - Web APIs 编辑

Secure context

This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The clientDataJSON property of the AuthenticatorResponse interface stores a JSON string in an ArrayBuffer, representing the client data that was passed to CredentialsContainer.create() or CredentialsContainer.get(). This property is only accessed on one of the child objects of AuthenticatorResponse, specifically AuthenticatorAttestationResponse or AuthenticatorAssertionResponse.

Syntax

var arrayBuffer = AuthenticatorAttestationResponse.clientDataJSON;
var arrayBuffer = AuthenticatorAssertionResponse.clientDataJSON;

Value

An ArrayBuffer.

Properties

After the clientDataJSON object is converted from an ArrayBuffer to a JavaScript object, it will have the following properties:

type
A string which is either "webauthn.get" when an existing credential is retrieved or "webauthn.create" when a new credential is created.
challenge
The base64url encoded version of the cryptographic challenge sent from the relying party's server. The original value is passed via PublicKeyCredentialRequestOptions.challenge or PublicKeyCredentialCreationOptions.challenge.
origin
The fully qualified origin of the requester which has been given by the client/browser to the authenticator. We should expect the relying party's id to be a suffix of this value.
tokenBindingId Optional

An object describing the state of the token binding protocol for the communication with the relying party. It has two properties:

  • status: A string which is either "supported" which indicates the client support token binding but did not negotiate with the relying party or "present" when token binding was used already
  • id: A DOMString which is the base64url encoding of the token binding ID which was used for the communication.

Should this property be absent, it would indicate that the client does not support token binding.

Examples

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
var clientDataStr = arrayBufferToStr(pk.clientDataJSON);
var 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

Specifications

SpecificationStatusComment
Web Authentication: An API for accessing Public Key Credentials Level 1
The definition of 'clientDataJSON' in that specification.
RecommendationInitial definition.

Browser compatibility

BCD tables only load in the browser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:106 次

字数:5452

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文