aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/authenticatorresponse/index.html
blob: d682aa678bb4232c9dfe3f4911521882f77bd0cf (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
---
title: AuthenticatorResponse
slug: Web/API/AuthenticatorResponse
translation_of: Web/API/AuthenticatorResponse
---
<div>{{APIRef("Web Authentication API")}}{{securecontext_header}}</div>

<p>The <code><strong>AuthenticatorResponse</strong></code> interface of the <a href="/en-US/docs/Web/API/Web_Authentication_API">Web Authentication API</a> is the base interface for interfaces that provide a cryptographic root of trust for a key pair. The child interfaces include information from the browser such as the challenge origin and either may be returned from {{domxref("PublicKeyCredential.response")}}.</p>

<h2 id="Interfaces_based_on_AuthenticatorResponse">Interfaces based on AuthenticatorResponse</h2>

<p>Below is a list of interfaces based on the AuthenticatorResponse interface.</p>

<div class="index">
<ul>
 <li>{{domxref("AuthenticatorAssertionResponse")}}</li>
 <li>{{domxref("AuthenticatorAttestationResponse")}}</li>
</ul>
</div>

<h2 id="Properties">Properties</h2>

<dl>
 <dt>{{domxref("AuthenticatorResponse.clientDataJSON")}}</dt>
 <dd>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()")}}.</dd>
</dl>

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

<p></p>

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

<h3 id="Getting_an_AuthenticatorAssertionResponse">Getting an AuthenticatorAssertionResponse</h3>

<pre class="brush: js notranslate">var options = {
  challenge: new Uint8Array([/* bytes sent from the server */])
};

navigator.credentials.get({ "publicKey": options })
    .then(function (credentialInfoAssertion) {
    var assertionResponse = credentialInfoAssertion.response;
    // send assertion response back to the server
    // to proceed with the control of the credential
}).catch(function (err) {
     console.error(err);
});

</pre>

<h3 id="Getting_an_AuthenticatorAttestationResponse">Getting an AuthenticatorAttestationResponse</h3>

<pre class="brush: js notranslate">var publicKey = {
  challenge: /* from the server */,
  rp: {
    name: "Example CORP",
    id  : "login.example.com"
  },
  user: {
    id: new Uint8Array(16),
    name: "jdoe@example.com",
    displayName: "John Doe"
  },
  pubKeyCredParams: [
    {
      type: "public-key",
      alg: -7
    }
  ]
};

navigator.credentials.create({ publicKey })
  .then(function (newCredentialInfo) {
    var attestationResponse = newCredentialInfo.response;
  }).catch(function (err) {
     console.error(err);
  });</pre>

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

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

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



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

<h2 id="参见">参见</h2>

<ul>
 <li>{{domxref("AuthenticatorAttestationResponse")}}</li>
 <li>{{domxref("AuthenticatorAssertionResponse")}}</li>
 <li>{{domxref("PublicKeyCredential.response")}}</li>
</ul>