Skip to content

Commit

Permalink
Update Example to v10.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterKale committed Apr 13, 2024
1 parent 81d9e49 commit b299b51
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 29 deletions.
7 changes: 2 additions & 5 deletions example/fido-conformance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
verifyAuthenticationResponse,
verifyRegistrationResponse,
} from '@simplewebauthn/server';
import { isoBase64URL, isoUint8Array } from '@simplewebauthn/server/helpers';
import { AuthenticationResponseJSON, RegistrationResponseJSON } from '@simplewebauthn/types';

import { expectedOrigin, rpID } from './index';
Expand Down Expand Up @@ -234,6 +233,7 @@ fidoConformanceRouter.post('/assertion/options', async (req, res) => {
const { devices } = user;

const opts = await generateAuthenticationOptions({
rpID,
extensions,
userVerification,
allowCredentials: devices.map((dev) => ({
Expand Down Expand Up @@ -269,10 +269,7 @@ fidoConformanceRouter.post('/assertion/result', async (req, res) => {
return res.status(400).send({ errorMessage: msg });
}

const credIDBuffer = isoBase64URL.toBuffer(id);
const existingDevice = user.devices.find((device) =>
isoUint8Array.areEqual(device.credentialID, credIDBuffer)
);
const existingDevice = user.devices.find((device) => device.credentialID === id);

if (!existingDevice) {
const msg = `Could not find device matching ${id}`;
Expand Down
9 changes: 2 additions & 7 deletions example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
verifyAuthenticationResponse,
verifyRegistrationResponse,
} from '@simplewebauthn/server';
import { isoBase64URL, isoUint8Array } from '@simplewebauthn/server/helpers';
import type {
GenerateAuthenticationOptionsOpts,
GenerateRegistrationOptionsOpts,
Expand Down Expand Up @@ -126,7 +125,6 @@ app.get('/generate-registration-options', async (req, res) => {
const opts: GenerateRegistrationOptionsOpts = {
rpName: 'SimpleWebAuthn Example',
rpID,
userID: loggedInUserId,
userName: username,
timeout: 60000,
attestationType: 'none',
Expand Down Expand Up @@ -195,9 +193,7 @@ app.post('/verify-registration', async (req, res) => {
if (verified && registrationInfo) {
const { credentialPublicKey, credentialID, counter } = registrationInfo;

const existingDevice = user.devices.find((device) =>
isoUint8Array.areEqual(device.credentialID, credentialID)
);
const existingDevice = user.devices.find((device) => device.credentialID === credentialID);

if (!existingDevice) {
/**
Expand Down Expand Up @@ -260,10 +256,9 @@ app.post('/verify-authentication', async (req, res) => {
const expectedChallenge = req.session.currentChallenge;

let dbAuthenticator;
const bodyCredIDBuffer = isoBase64URL.toBuffer(body.rawId);
// "Query the DB" here for an authenticator matching `credentialID`
for (const dev of user.devices) {
if (isoUint8Array.areEqual(dev.credentialID, bodyCredIDBuffer)) {
if (dev.credentialID === body.id) {
dbAuthenticator = dev;
break;
}
Expand Down
32 changes: 16 additions & 16 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@simplewebauthn/server": "9.0.3",
"@simplewebauthn/server": "10.0.0",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"express-session": "^1.17.3",
Expand Down

0 comments on commit b299b51

Please sign in to comment.