aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/authenticatorresponse/clientdatajson/index.html
blob: f884c53486bc6a3f4e52dc63e6ce9bbc2a819602 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
title: AuthenticatorResponse.clientDataJSON
slug: Web/API/AuthenticatorResponse/clientDataJSON
translation_of: Web/API/AuthenticatorResponse/clientDataJSON
---
<p>{{APIRef("Web Authentication API")}}{{securecontext_header}}</p>

<p>The <strong><code>clientDataJSON</code></strong> property of the {{domxref("AuthenticatorResponse")}} interface stores a <a href="/en-US/docs/Learn/JavaScript/Objects/JSON">JSON</a> string in an {{domxref("ArrayBuffer")}}, representing the client data that was passed to {{domxref("CredentialsContainer.create()")}} or {{domxref("CredentialsContainer.get()")}}. This property is only accessed on one of the child objects of <code>AuthenticatorResponse</code>, specifically {{domxref("AuthenticatorAttestationResponse")}} or {{domxref("AuthenticatorAssertionResponse")}}.</p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox notranslate">var arrayBuffer = AuthenticatorAttestationResponse.clientDataJSON;
var arrayBuffer = AuthenticatorAssertionResponse.clientDataJSON;
</pre>

<h3 id="Value">Value</h3>

<p>An {{jsxref("ArrayBuffer")}}.</p>

<h2 id="属性">属性</h2>

<p>After the <code>clientDataJSON</code> object is converted from an <code>ArrayBuffer</code> to a JavaScript object, it will have the following properties:</p>

<dl>
 <dt><code>type</code></dt>
 <dd>A string which is either <code>"webauthn.get"</code> when an existing credential is retrieved or <code>"webauthn.create"</code> when a new credential is created.</dd>
 <dt><code>challenge</code></dt>
 <dd>The <a href="/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding">base64url</a> encoded version of the cryptographic challenge sent from the relying party's server. The original value is passed via {{domxref("PublicKeyCredentialRequestOptions.challenge")}} or {{domxref("PublicKeyCredentialCreationOptions.challenge")}}.</dd>
 <dt><code>origin</code></dt>
 <dd>The fully qualified origin of the requester which has been given by the client/browser to the authenticator. We should expect the <a href="/en-US/docs/Web/API/PublicKeyCredentialRequestOptions/rpId">relying party's id</a> to be a suffix of this value.</dd>
 <dt><code>tokenBindingId</code> {{optional_inline}}</dt>
 <dd>
 <p>An object describing the state of <a href="https://tools.ietf.org/html/rfc8471">the token binding protocol</a> for the communication with the relying party. It has two properties:</p>

 <ul>
  <li><code>status</code>: A string which is either <code>"supported"</code> which indicates the client support token binding but did not negotiate with the relying party or <code>"present"</code> when token binding was used already</li>
  <li><code>id</code>: A {{domxref("DOMString")}} which is the <a href="/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding">base64url</a> encoding of the token binding ID which was used for the communication.</li>
 </ul>

 <p>Should this property be absent, it would indicate that the client does not support token binding.</p>
 </dd>
</dl>

<h2 id="示例">示例</h2>

<pre class="brush: js notranslate">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
</pre>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('WebAuthn','#dom-authenticatorresponse-clientdatajson', 'clientDataJSON')}}</td>
   <td>{{Spec2('WebAuthn')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>



<p>{{Compat("api.AuthenticatorResponse.clientDataJSON")}}</p>