-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhybrid-webauthn-test.html
More file actions
298 lines (271 loc) Β· 11.7 KB
/
hybrid-webauthn-test.html
File metadata and controls
298 lines (271 loc) Β· 11.7 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hybrid WebAuthn Test - QR Code + Security Key</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
max-width: 800px;
margin: 40px auto;
padding: 20px;
background: #f5f5f5;
}
.container {
background: white;
padding: 30px;
border-radius: 12px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #333;
text-align: center;
margin-bottom: 30px;
}
.feature-box {
background: #e8f4ff;
border: 2px solid #007bff;
border-radius: 8px;
padding: 20px;
margin: 20px 0;
}
.test-section {
margin: 30px 0;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
background: #fafafa;
}
input[type="text"] {
width: 100%;
padding: 12px;
margin: 10px 0;
border: 2px solid #ddd;
border-radius: 6px;
font-size: 16px;
}
button {
background: #007bff;
color: white;
border: none;
padding: 12px 24px;
border-radius: 6px;
cursor: pointer;
font-size: 16px;
margin: 5px;
}
button:hover { background: #0056b3; }
button:disabled { background: #ccc; cursor: not-allowed; }
.status {
margin: 15px 0;
padding: 10px;
border-radius: 6px;
font-weight: 500;
}
.status.info { background: #cce5ff; color: #004085; }
.status.success { background: #d4edda; color: #155724; }
.status.error { background: #f8d7da; color: #721c24; }
.log {
background: #f8f9fa;
border: 1px solid #dee2e6;
border-radius: 6px;
padding: 15px;
margin: 15px 0;
font-family: monospace;
font-size: 14px;
max-height: 300px;
overflow-y: auto;
}
.highlight {
background: #fff3cd;
padding: 15px;
border-radius: 6px;
margin: 15px 0;
border-left: 4px solid #ffc107;
}
</style>
</head>
<body>
<div class="container">
<h1>π Hybrid WebAuthn Test</h1>
<div class="feature-box">
<h3>β¨ What's New: Hybrid WebAuthn Support</h3>
<p><strong>This implementation supports BOTH options simultaneously:</strong></p>
<ul>
<li>π± <strong>QR Code/Phone Passkey</strong> - Scan QR code to use your phone as authenticator</li>
<li>π <strong>Security Key</strong> - Insert USB/NFC security key (YubiKey, etc.)</li>
<li>π» <strong>Platform Authenticators</strong> - Touch ID, Face ID, Windows Hello</li>
</ul>
<p><em>Chrome will present all available options - choose what works best for you!</em></p>
</div>
<div class="test-section">
<h3>π§ͺ Test Registration (Hybrid Mode)</h3>
<input type="text" id="regUsername" placeholder="Enter username" value="testuser">
<button onclick="testHybridRegistration()">Register with Hybrid WebAuthn</button>
<div id="regStatus" class="status" style="display: none;"></div>
</div>
<div class="test-section">
<h3>π Test Authentication (Hybrid Mode)</h3>
<input type="text" id="authUsername" placeholder="Enter username (optional for usernameless)" value="testuser">
<button onclick="testHybridAuthentication()">Authenticate with Hybrid WebAuthn</button>
<div id="authStatus" class="status" style="display: none;"></div>
</div>
<div class="highlight">
<h4>π― Expected Chrome Behavior:</h4>
<p>When you click register/authenticate, Chrome should show a dialog with multiple options:</p>
<ul>
<li><strong>"Use your phone"</strong> - Shows QR code to scan with your phone</li>
<li><strong>"Use a security key"</strong> - For USB/NFC security keys</li>
<li><strong>Platform options</strong> - Touch ID (Mac), Windows Hello, etc.</li>
</ul>
</div>
<div class="test-section">
<h3>π Debug Log</h3>
<button onclick="clearLog()">Clear Log</button>
<div id="debugLog" class="log"></div>
</div>
</div>
<script src="/static/hybrid-webauthn.js"></script>
<script>
const webauthn = new HybridWebAuthnClient();
function log(message) {
const logDiv = document.getElementById('debugLog');
const timestamp = new Date().toLocaleTimeString();
logDiv.innerHTML += `[${timestamp}] ${message}\n`;
logDiv.scrollTop = logDiv.scrollHeight;
console.log(message);
}
function clearLog() {
document.getElementById('debugLog').innerHTML = '';
}
function showStatus(elementId, message, type) {
const statusDiv = document.getElementById(elementId);
statusDiv.textContent = message;
statusDiv.className = `status ${type}`;
statusDiv.style.display = 'block';
log(`Status (${type}): ${message}`);
}
async function testHybridRegistration() {
const username = document.getElementById('regUsername').value.trim();
if (!username) {
showStatus('regStatus', 'Please enter a username', 'error');
return;
}
log(`π Starting hybrid registration for: ${username}`);
try {
const result = await webauthn.register(username, 'π§ͺ', {
onStatus: (message, type) => {
showStatus('regStatus', message, type);
},
onSuccess: (data) => {
log(`β
Hybrid registration successful!`);
log(`Username: ${data.username}, Emoji: ${data.emoji}`);
showStatus('regStatus', 'Hybrid registration successful!', 'success');
},
onError: (error) => {
log(`β Hybrid registration error: ${error}`);
showStatus('regStatus', `Error: ${error}`, 'error');
}
});
if (result.success) {
log(`π Registration completed successfully!`);
}
} catch (error) {
log(`β Registration failed: ${error.message}`);
showStatus('regStatus', `β Registration failed: ${error.message}`, 'error');
}
}
async function testHybridAuthentication() {
const username = document.getElementById('authUsername').value.trim();
log(`π Starting hybrid authentication for: ${username || 'usernameless'}`);
try {
const result = await webauthn.authenticate(username || null, {
onStatus: (message, type) => {
showStatus('authStatus', message, type);
},
onSuccess: (data) => {
log(`β
Hybrid authentication successful!`);
log(`User: ${data.username || 'usernameless'}`);
showStatus('authStatus', 'Hybrid authentication successful!', 'success');
},
onError: (error) => {
log(`β Hybrid authentication error: ${error}`);
showStatus('authStatus', `Error: ${error}`, 'error');
}
});
if (result.success) {
log(`π Authentication completed successfully!`);
}
} catch (error) {
log(`β Authentication failed: ${error.message}`);
showStatus('authStatus', `β Authentication failed: ${error.message}`, 'error');
}
}
// Helper functions for base64 conversion
function base64ToArrayBuffer(base64) {
const binaryString = atob(base64);
const bytes = new Uint8Array(binaryString.length);
for (let i = 0; i < binaryString.length; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
return bytes.buffer;
}
function arrayBufferToBase64(buffer) {
const bytes = new Uint8Array(buffer);
let binary = '';
for (let i = 0; i < bytes.byteLength; i++) {
binary += String.fromCharCode(bytes[i]);
}
return btoa(binary);
}
// Initialize
log('π Hybrid WebAuthn Test Page Loaded');
log(`Browser: ${navigator.userAgent}`);
log(`Platform: ${navigator.platform}`);
log(`WebAuthn Support: ${webauthn.isSupported()}`);
// Check for specific browser capabilities
log(`Chrome: ${webauthn.isChrome()}`);
log(`Firefox: ${webauthn.isFirefox()}`);
log(`Mac: ${webauthn.isMac()}`);
log(`Windows: ${webauthn.isWindows()}`);
log(`Linux: ${webauthn.isLinux()}`);
// Check for platform authenticator availability
if (typeof PublicKeyCredential !== 'undefined' && PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable) {
PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable().then(available => {
log(`Platform Authenticator Available: ${available}`);
if (available && webauthn.isMac()) {
log('π Touch ID may be available - this might affect Chrome behavior');
}
});
}
if (webauthn.isSupported()) {
log('β
WebAuthn is supported in this browser');
} else {
log('β WebAuthn is NOT supported in this browser');
}
// Test hybrid endpoint directly
log('π§ͺ Testing hybrid endpoint directly...');
fetch('/webauthn/register/begin/hybrid', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username: 'debug-test-user' })
}).then(response => response.json()).then(options => {
log('π Direct hybrid endpoint test - Server Options:');
log(JSON.stringify(options, null, 2));
// Check for key hybrid characteristics
if (options.publicKey && options.publicKey.authenticatorSelection) {
const authSel = options.publicKey.authenticatorSelection;
if ('authenticatorAttachment' in authSel) {
log(`β οΈ authenticatorAttachment is present: ${authSel.authenticatorAttachment}`);
log('β This may prevent hybrid mode from working properly');
} else {
log('β
authenticatorAttachment is missing - good for hybrid mode');
}
}
}).catch(error => {
log(`β Failed to test hybrid endpoint: ${error}`);
});
</script>
</body>
</html>