summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2020-05-22 17:16:55 -0700
committerMatthew Miller <matthew@millerti.me>2020-05-22 17:16:55 -0700
commit137617490185aa55c32e6549e80e55cd81e4a347 (patch)
tree62ce7abc5eb1de2f5003c9031d946da45e43ed36
parent8940df7dd71d562ca9a52bc8e17a677dd9679e85 (diff)
Wire up Login page to perform assertion
-rw-r--r--example/public/login/index.html38
1 files changed, 37 insertions, 1 deletions
diff --git a/example/public/login/index.html b/example/public/login/index.html
index e0cb602..98d124b 100644
--- a/example/public/login/index.html
+++ b/example/public/login/index.html
@@ -3,7 +3,8 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
- <script src="https://unpkg.com/@webauthntine/browser@0.1.1/dist/webauthntine-browser.min.js"></script>
+ <!-- <script src="https://unpkg.com/@webauthntine/browser@0.1.1/dist/webauthntine-browser.min.js"></script> -->
+ <script src="/webauthntine-browser.min.js"></script>
<link rel="stylesheet" href="../styles.css" />
<title>WebAuthntine Example Site | Login</title>
</head>
@@ -14,9 +15,44 @@
<span>⬅️&nbsp;<a href="/">Go Back</a></span>
</p>
<button id="btnBegin">Begin Login</button>
+ <p id="success"></p>
+ <p id="error"></p>
</div>
<script>
+ const elemBegin = document.getElementById('btnBegin');
+ const elemSuccess = document.getElementById('success');
+ const elemError = document.getElementById('error');
+ const { startAssertion } = WebAuthntineBrowser;
+
+ elemBegin.addEventListener('click', (async () => {
+ const resp = await fetch('/generate-assertion-options');
+
+ let asseResp;
+ try {
+ const opts = await resp.json();
+ asseResp = await startAssertion(opts);
+ } catch (error) {
+ elemError.innerText = error;
+ throw new Error(error);
+ }
+
+ const verificationResp = await fetch('/verify-assertion', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify(asseResp),
+ });
+
+ const verificationJSON = await verificationResp.json();
+
+ if (verificationJSON && verificationJSON.verified) {
+ elemSuccess.innerHTML = 'Success! <a href="/register">Try to register again?&nbsp;🚪</a>';
+ } else {
+ elemError.innerHTML = `Oh no, something went wrong! Response: <pre>${JSON.stringify(verificationJSON)}</pre>`;
+ }
+ }));
</script>
</body>
</html>