-
Notifications
You must be signed in to change notification settings - Fork 1
/
webauthn_test.html
65 lines (62 loc) · 1.72 KB
/
webauthn_test.html
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
<html>
<script>
async function registerCredential(options = {}) {
options = Object.assign({
authenticatorSelection: {
requireResidentKey: false,
},
rp: {
id: "sadym-chromium.github.io",
name: "ChromeDriver Test",
},
challenge: Uint8Array.from("challenge"),
pubKeyCredParams: [
{type: "public-key", alg: -7},
],
user: {
name: "name",
displayName: "displayName",
id: Uint8Array.from([1]),
},
}, options);
try {
const credential = await navigator.credentials.create({publicKey: options});
return {
status: "OK",
credential: {
id: credential.id,
rawId: Array.from(new Uint8Array(credential.rawId)),
transports: credential.response.getTransports(),
},
extensions: credential.getClientExtensionResults(),
};
} catch (error) {
return {status: error.toString()};
}
}
async function getCredential(credential, options = {}) {
options = Object.assign({
challenge: Uint8Array.from("Winter is Coming"),
rpId: "sadym-chromium.github.io",
allowCredentials: [credential],
userVerification: "preferred",
}, options);
try {
const attestation = await navigator.credentials.get({publicKey: options});
let result = {
status: "OK",
attestation,
extensions: attestation.getClientExtensionResults(),
};
if (attestation.getClientExtensionResults()?.largeBlob?.blob) {
result.blob = new TextDecoder().decode(
attestation.getClientExtensionResults().largeBlob.blob);
}
return result;
} catch (error) {
return {status: error.toString()};
}
}
</script>
<button onclick="console.log(registerCredential())">registerCredential()</button>
</html>