summaryrefslogtreecommitdiffhomepage
path: root/example
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2023-08-22 10:13:03 -0700
committerGitHub <noreply@github.com>2023-08-22 10:13:03 -0700
commitfefc95e4535e6ecf903f647124a492fba3fd11d6 (patch)
tree4c924d43d32fb12a780533302eaf5dee08875d75 /example
parent443c341bc2163f07b93a3ef84a43294d10b826f8 (diff)
parent2935857c76d458c26701842e500f8d97d17499c5 (diff)
Merge pull request #425 from MasterKale/feat/server-esm-take-2-dnt
feat/server-esm-take-2-dnt
Diffstat (limited to 'example')
-rw-r--r--example/README.md6
-rw-r--r--example/fido-conformance.ts67
-rw-r--r--example/index.ts37
3 files changed, 74 insertions, 36 deletions
diff --git a/example/README.md b/example/README.md
index 4439d78..573c275 100644
--- a/example/README.md
+++ b/example/README.md
@@ -1,5 +1,7 @@
# SimpleWebAuthn Example Project
-A fully-functional reference implementation of **@simplewebauthn/server** and **@simplewebauthn/browser**.
+A fully-functional reference implementation of **@simplewebauthn/server** and
+**@simplewebauthn/browser**.
-You can find an in-depth guide to the Example Project here: https://simplewebauthn.dev/docs/advanced/example-project
+You can find an in-depth guide to the Example Project here:
+https://simplewebauthn.dev/docs/advanced/example-project
diff --git a/example/fido-conformance.ts b/example/fido-conformance.ts
index 7d8e404..0e07291 100644
--- a/example/fido-conformance.ts
+++ b/example/fido-conformance.ts
@@ -1,24 +1,23 @@
-/* eslint-disable @typescript-eslint/no-var-requires */
import fs from 'fs';
import express from 'express';
import fetch from 'node-fetch';
import {
- generateRegistrationOptions,
- verifyRegistrationResponse,
generateAuthenticationOptions,
- verifyAuthenticationResponse,
+ generateRegistrationOptions,
MetadataService,
MetadataStatement,
SettingsService,
+ verifyAuthenticationResponse,
+ verifyRegistrationResponse,
} from '@simplewebauthn/server';
import { isoBase64URL, isoUint8Array } from '@simplewebauthn/server/helpers';
import {
- RegistrationResponseJSON,
AuthenticationResponseJSON,
+ RegistrationResponseJSON,
} from '@simplewebauthn/typescript-types';
-import { rpID, expectedOrigin } from './index';
+import { expectedOrigin, rpID } from './index';
import { LoggedInUser } from './example-server';
interface LoggedInFIDOUser extends LoggedInUser {
@@ -46,7 +45,10 @@ try {
const conformanceMetadataFilenames = fs.readdirSync(conformanceMetadataPath);
for (const statementPath of conformanceMetadataFilenames) {
if (statementPath.endsWith('.json')) {
- const contents = fs.readFileSync(`${conformanceMetadataPath}/${statementPath}`, 'utf-8');
+ const contents = fs.readFileSync(
+ `${conformanceMetadataPath}/${statementPath}`,
+ 'utf-8',
+ );
statements.push(JSON.parse(contents));
}
}
@@ -64,8 +66,8 @@ fetch('https://mds3.fido.tools/getEndpoints', {
body: JSON.stringify({ endpoint: `${expectedOrigin}${fidoRouteSuffix}` }),
headers: { 'Content-Type': 'application/json' },
})
- .then(resp => resp.json())
- .then(json => {
+ .then((resp) => resp.json())
+ .then((json) => {
const mdsServers: string[] = json.result;
return MetadataService.initialize({
@@ -99,14 +101,32 @@ const inMemoryUserDeviceDB: { [username: string]: LoggedInFIDOUser } = {
// A cheap way of remembering who's "logged in" between the request for options and the response
let loggedInUsername: string | undefined = undefined;
-const supportedAlgorithmIDs = [-7, -8, -35, -36, -37, -38, -39, -257, -258, -259, -65535];
+const supportedAlgorithmIDs = [
+ -7,
+ -8,
+ -35,
+ -36,
+ -37,
+ -38,
+ -39,
+ -257,
+ -258,
+ -259,
+ -65535,
+];
/**
* [FIDO2] Server Tests > MakeCredential Request
*/
fidoConformanceRouter.post('/attestation/options', (req, res) => {
const { body } = req;
- const { username, displayName, authenticatorSelection, attestation, extensions } = body;
+ const {
+ username,
+ displayName,
+ authenticatorSelection,
+ attestation,
+ extensions,
+ } = body;
loggedInUsername = username;
@@ -133,7 +153,7 @@ fidoConformanceRouter.post('/attestation/options', (req, res) => {
attestationType: attestation,
authenticatorSelection,
extensions,
- excludeCredentials: devices.map(dev => ({
+ excludeCredentials: devices.map((dev) => ({
id: dev.credentialID,
type: 'public-key',
transports: ['usb', 'ble', 'nfc', 'internal'],
@@ -183,7 +203,7 @@ fidoConformanceRouter.post('/attestation/result', async (req, res) => {
if (verified && registrationInfo) {
const { credentialPublicKey, credentialID, counter } = registrationInfo;
- const existingDevice = user.devices.find(device => device.credentialID === credentialID);
+ const existingDevice = user.devices.find((device) => device.credentialID === credentialID);
if (!existingDevice) {
/**
@@ -219,7 +239,7 @@ fidoConformanceRouter.post('/assertion/options', (req, res) => {
const opts = generateAuthenticationOptions({
extensions,
userVerification,
- allowCredentials: devices.map(dev => ({
+ allowCredentials: devices.map((dev) => ({
id: dev.credentialID,
type: 'public-key',
transports: ['usb', 'ble', 'nfc', 'internal'],
@@ -253,7 +273,9 @@ fidoConformanceRouter.post('/assertion/result', async (req, res) => {
}
const credIDBuffer = isoBase64URL.toBuffer(id);
- const existingDevice = user.devices.find(device => isoUint8Array.areEqual(device.credentialID, credIDBuffer));
+ const existingDevice = user.devices.find((device) =>
+ isoUint8Array.areEqual(device.credentialID, credIDBuffer)
+ );
if (!existingDevice) {
const msg = `Could not find device matching ${id}`;
@@ -330,8 +352,17 @@ X2S5Ht8+e+EQnezLJBJXtnkRWY+Zt491wgt/AwSs5PHHMv5QgjELOuMxQBc=
`;
// Set above root cert for use by MetadataService
-SettingsService.setRootCertificates({ identifier: 'mds', certificates: [MDS3ROOT] });
+SettingsService.setRootCertificates({
+ identifier: 'mds',
+ certificates: [MDS3ROOT],
+});
// Reset preset root certificates
SettingsService.setRootCertificates({ identifier: 'apple', certificates: [] });
-SettingsService.setRootCertificates({ identifier: 'android-key', certificates: [] });
-SettingsService.setRootCertificates({ identifier: 'android-safetynet', certificates: [] });
+SettingsService.setRootCertificates({
+ identifier: 'android-key',
+ certificates: [],
+});
+SettingsService.setRootCertificates({
+ identifier: 'android-safetynet',
+ certificates: [],
+});
diff --git a/example/index.ts b/example/index.ts
index ba76c17..9f4204d 100644
--- a/example/index.ts
+++ b/example/index.ts
@@ -1,4 +1,3 @@
-/* eslint-disable @typescript-eslint/no-var-requires */
/**
* An example Express server showing off a simple integration of @simplewebauthn/server.
*
@@ -17,27 +16,27 @@ import dotenv from 'dotenv';
dotenv.config();
import {
- // Registration
- generateRegistrationOptions,
- verifyRegistrationResponse,
// Authentication
generateAuthenticationOptions,
+ // Registration
+ generateRegistrationOptions,
verifyAuthenticationResponse,
+ verifyRegistrationResponse,
} from '@simplewebauthn/server';
import { isoBase64URL, isoUint8Array } from '@simplewebauthn/server/helpers';
import type {
- GenerateRegistrationOptionsOpts,
GenerateAuthenticationOptionsOpts,
- VerifyRegistrationResponseOpts,
- VerifyAuthenticationResponseOpts,
- VerifiedRegistrationResponse,
+ GenerateRegistrationOptionsOpts,
VerifiedAuthenticationResponse,
+ VerifiedRegistrationResponse,
+ VerifyAuthenticationResponseOpts,
+ VerifyRegistrationResponseOpts,
} from '@simplewebauthn/server';
import type {
- RegistrationResponseJSON,
AuthenticationResponseJSON,
AuthenticatorDevice,
+ RegistrationResponseJSON,
} from '@simplewebauthn/typescript-types';
import { LoggedInUser } from './example-server';
@@ -75,9 +74,11 @@ app.use(
* interact with the Rely Party (a.k.a. "RP", a.k.a. "this server").
*/
if (ENABLE_CONFORMANCE === 'true') {
- import('./fido-conformance').then(({ fidoRouteSuffix, fidoConformanceRouter }) => {
- app.use(fidoRouteSuffix, fidoConformanceRouter);
- });
+ import('./fido-conformance').then(
+ ({ fidoRouteSuffix, fidoConformanceRouter }) => {
+ app.use(fidoRouteSuffix, fidoConformanceRouter);
+ },
+ );
}
/**
@@ -135,7 +136,7 @@ app.get('/generate-registration-options', (req, res) => {
* the browser if it's asked to perform registration when one of these ID's already resides
* on it.
*/
- excludeCredentials: devices.map(dev => ({
+ excludeCredentials: devices.map((dev) => ({
id: dev.credentialID,
type: 'public-key',
transports: dev.transports,
@@ -188,7 +189,9 @@ 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) =>
+ isoUint8Array.areEqual(device.credentialID, credentialID)
+ );
if (!existingDevice) {
/**
@@ -218,7 +221,7 @@ app.get('/generate-authentication-options', (req, res) => {
const opts: GenerateAuthenticationOptionsOpts = {
timeout: 60000,
- allowCredentials: user.devices.map(dev => ({
+ allowCredentials: user.devices.map((dev) => ({
id: dev.credentialID,
type: 'public-key',
transports: dev.transports,
@@ -256,7 +259,9 @@ app.post('/verify-authentication', async (req, res) => {
}
if (!dbAuthenticator) {
- return res.status(400).send({ error: 'Authenticator is not registered with this site' });
+ return res.status(400).send({
+ error: 'Authenticator is not registered with this site',
+ });
}
let verification: VerifiedAuthenticationResponse;