-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathauthenticator-webauthn-enroll.mustache
96 lines (79 loc) · 3.45 KB
/
authenticator-webauthn-enroll.mustache
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
<!DOCTYPE html>
<html>
<head>
{{>head}}
<script src="/okta-auth-js.min.js" type="text/javascript"></script>
</head>
<body id="samples">
{{>menu}}
<div class="okta-sign-in-form ui center aligned relaxed grid">
<div class="row">
<div id="page-title-header" class="ui header">
<h2>{{title}}</h2>
</div>
</div>
<div class="row">
{{>formMessages}}
</div>
{{#activationData}}
<div class="row">
<form id="challenge-authenticator-form" class="ui large form" action="{{action}}" method="POST">
<input id="credentials-id" type="hidden" name="id" autoComplete="off" required />
<input id="credentials-clientData" type="hidden" name="clientData" autoComplete="off" required />
<input id="credentials-attestation" type="hidden" name="attestation" autoComplete="off" required />
<div class="row">
<div id="credentials-error" class="ui negative message"></div>
</div>
<div class="row">
<button id="retry-button" class="ui fluid large button" onclick="askCredentials()" type="button">
Retry
</button>
<button id="submit-button" class="ui fluid large primary submit button" type="submit">
Continue
</button>
</div>
</form>
</div>
<script type="text/javascript">
const activationData = {{{activationData}}};
const authenticatorEnrollments = {{{authenticatorEnrollments}}};
const askCredentials = async () => {
try {
// https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API
const options = OktaAuth.webauthn.buildCredentialCreationOptions(activationData, authenticatorEnrollments);
const credential = await navigator.credentials.create(options);
const res = OktaAuth.webauthn.getAttestation(credential);
onSuccess(res);
} catch(e) {
onError(e);
}
};
const onInit = () => {
document.getElementById('credentials-error').hidden = true;
document.getElementById('retry-button').style.display = 'none';
document.getElementById('submit-button').style.display = 'none';
};
const onSuccess = (res) => {
document.getElementById('credentials-clientData').value = res.clientData;
document.getElementById('credentials-attestation').value = res.attestation;
document.getElementById('credentials-id').value = res.id;
document.getElementById('credentials-error').innerText = '';
document.getElementById('credentials-error').hidden = true;
document.getElementById('submit-button').style.display = null;
document.getElementById('retry-button').style.display = 'none';
};
const onError = (e) => {
document.getElementById('credentials-error').innerText = `${e.name}: ${e.message}`;
document.getElementById('credentials-error').hidden = false;
document.getElementById('retry-button').style.display = null;
};
document.addEventListener('DOMContentLoaded', () => {
onInit();
askCredentials();
});
</script>
{{/activationData}}
{{>cancel}}
</div>
</body>
</html>