summaryrefslogtreecommitdiffhomepage
path: root/example/public
diff options
context:
space:
mode:
Diffstat (limited to 'example/public')
-rw-r--r--example/public/index.html20
-rw-r--r--example/public/login/index.html58
-rw-r--r--example/public/register/index.html57
-rw-r--r--example/public/styles.css50
4 files changed, 185 insertions, 0 deletions
diff --git a/example/public/index.html b/example/public/index.html
new file mode 100644
index 0000000..4a42d55
--- /dev/null
+++ b/example/public/index.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link rel="stylesheet" href="./styles.css" />
+ <title>WebAuthntine Example Site</title>
+</head>
+<body>
+ <div class="container">
+ <h1>WebAuthntine Example Site</h1>
+ <p>
+ 🚪&nbsp;<a href="/register">Register</a>
+ </p>
+ <p>
+ 🔐&nbsp;<a href="/login">Login</a>
+ </p>
+ </div>
+</body>
+</html>
diff --git a/example/public/login/index.html b/example/public/login/index.html
new file mode 100644
index 0000000..094e3b4
--- /dev/null
+++ b/example/public/login/index.html
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<html lang="en">
+<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.2/dist/webauthntine-browser.min.js"></script>
+ <link rel="stylesheet" href="../styles.css" />
+ <title>WebAuthntine Example Site | Login</title>
+</head>
+<body>
+ <div class="container">
+ <p>
+ <span>⬅️&nbsp;<a href="/">Go Back</a></span>
+ </p>
+ <h1>🔐&nbsp;Login</h1>
+ <h2>(a.k.a. "Assertion")</h2>
+ <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?</a>&nbsp;🚪';
+ } else {
+ elemError.innerHTML = `Oh no, something went wrong! Response: <pre>${JSON.stringify(verificationJSON)}</pre>`;
+ }
+ }));
+ </script>
+</body>
+</html>
diff --git a/example/public/register/index.html b/example/public/register/index.html
new file mode 100644
index 0000000..2ddbd73
--- /dev/null
+++ b/example/public/register/index.html
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<html lang="en">
+<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.2/dist/webauthntine-browser.min.js"></script>
+ <link rel="stylesheet" href="../styles.css" />
+ <title>WebAuthntine Example Site | Register</title>
+</head>
+<body>
+ <div class="container">
+ <p>
+ <span>⬅️&nbsp;<a href="/">Go Back</a></span>
+ </p>
+ <h1>🚪&nbsp;Register</h1>
+ <h2>(a.k.a. "Attestation")</h2>
+ <button id="btnBegin">Begin Registration</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 { startAttestation } = WebAuthntineBrowser;
+
+ elemBegin.addEventListener('click', (async () => {
+ console.log('getting attestation options');
+ const resp = await fetch('/generate-attestation-options');
+
+ let attResp;
+ try {
+ attResp = await startAttestation(await resp.json());
+ } catch (error) {
+ elemError.innerText = error;
+ }
+
+ const verificationResp = await fetch('/verify-attestation', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify(attResp),
+ });
+
+ const verificationJSON = await verificationResp.json();
+
+ if (verificationJSON && verificationJSON.verified) {
+ elemSuccess.innerHTML = 'Success! <a href="/login">Now try to log in</a>&nbsp;🔐';
+ } else {
+ elemError.innerHTML = `Oh no, something went wrong! Response: <pre>${JSON.stringify(verificationJSON)}</pre>`;
+ }
+ }));
+ </script>
+</body>
+</html>
diff --git a/example/public/styles.css b/example/public/styles.css
new file mode 100644
index 0000000..3eeeb7b
--- /dev/null
+++ b/example/public/styles.css
@@ -0,0 +1,50 @@
+* {
+ font-size: 16px;
+ font-family: 'Courier New', Courier, monospace;
+}
+
+body {
+ margin: 0;
+ padding: 0;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ height: 100vh;
+ background: #F7F7F7;
+}
+
+h1 {
+ font-size: 2.25rem;
+}
+
+h2 {
+ font-size: 1.75rem;
+}
+
+button {
+ padding: 0.5rem;
+ background: white;
+ border-radius: 0.25rem;
+}
+
+button:active {
+ background: #EEEEEE;
+}
+
+button:hover {
+ background: #EFEFEF;
+}
+
+.container {
+ max-width: 70rem;
+ margin: auto;
+ text-align: center;
+}
+
+#error {
+ color: red;
+}
+
+#success {
+ color: #11A000;
+}