Skip to content

Commit 200a408

Browse files
committed
Upgrade to latest webauthn-server-core
1 parent 2f23c64 commit 200a408

File tree

2 files changed

+39
-25
lines changed

2 files changed

+39
-25
lines changed

build/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<dependency>
1616
<groupId>com.yubico</groupId>
1717
<artifactId>webauthn-server-core</artifactId>
18-
<version>2.5.2</version>
18+
<version>2.6.0</version>
1919
<scope>compile</scope>
2020
</dependency>
2121
</dependencies>

includes/passkeys.js

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -288,40 +288,54 @@ const passkeys = {
288288
const publicKeyCredential = await webauthnJSON.create(credentialCreateOptions);
289289

290290
// Return encoded PublicKeyCredential to server
291-
await fetch("/cbsecurity/passkeys/registration", {
291+
const registrationResponse = await fetch("/cbsecurity/passkeys/registration", {
292292
method: "POST",
293293
headers: {
294294
"Content-Type": "application/json"
295295
},
296296
body: JSON.stringify({
297297
"publicKeyCredentialJson": JSON.stringify(publicKeyCredential)
298298
})
299-
})
300-
window.location = redirectLocation;
299+
});
300+
301+
if (registrationResponse.ok) {
302+
window.location = redirectLocation;
303+
} else {
304+
console.error("cbsecurity-passkeys - Registration failed:", registrationResponse);
305+
}
301306
},
302-
async login(username, redirectLocation = "/") {
303-
// Make the call that returns the credentialGetJson above
304-
const credentialGetOptions = await fetch("/cbsecurity/passkeys/authentication/new?" + new URLSearchParams({
305-
"username": username
306-
}))
307-
.then(resp => resp.json())
308-
.then(json => JSON.parse(json));
307+
async login(username, redirectLocation = "/", additionalParams = {}) {
308+
if ( !username ) {
309+
username = "";
310+
}
311+
// Make the call that returns the credentialGetJson above
312+
const credentialGetOptions = await fetch("/cbsecurity/passkeys/authentication/new?" + new URLSearchParams({
313+
...additionalParams,
314+
"username": username,
315+
}))
316+
.then(resp => resp.json())
317+
.then(json => JSON.parse(json));
318+
319+
// Call WebAuthn ceremony using webauthn-json wrapper
320+
const publicKeyCredential = await webauthnJSON.get(credentialGetOptions);
309321

310-
// Call WebAuthn ceremony using webauthn-json wrapper
311-
const publicKeyCredential = await webauthnJSON.get(credentialGetOptions);
322+
// Return encoded PublicKeyCredential to server
323+
const authenticationResponse = await fetch("/cbsecurity/passkeys/authentication", {
324+
method: "POST",
325+
headers: {
326+
"Content-Type": "application/json"
327+
},
328+
body: JSON.stringify({
329+
...additionalParams,
330+
"publicKeyCredentialJson": JSON.stringify(publicKeyCredential)
331+
})
332+
});
312333

313-
// Return encoded PublicKeyCredential to server
314-
await fetch("/cbsecurity/passkeys/authentication", {
315-
method: "POST",
316-
headers: {
317-
"Content-Type": "application/json"
318-
},
319-
body: JSON.stringify({
320-
"publicKeyCredentialJson": JSON.stringify(publicKeyCredential)
321-
})
322-
}).then( () => {
323-
window.location = redirectLocation;
324-
});
334+
if (authenticationResponse.ok) {
335+
window.location = redirectLocation;
336+
} else {
337+
console.error("cbsecurity-passkeys - Authentication failed:", authenticationResponse);
338+
}
325339
},
326340
};
327341

0 commit comments

Comments
 (0)