Skip to content

Commit 7834cde

Browse files
committed
fix(davinci-client): improve fido module error handling
1 parent dc6b18f commit 7834cde

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

.changeset/full-bikes-boil.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@forgerock/davinci-client': patch
3+
---
4+
5+
Improve FIDO module error handling when no options

e2e/davinci-app/components/fido.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
* This software may be modified and distributed under the terms
55
* of the MIT license. See the LICENSE file for details.
66
*/
7+
import { fido } from '@forgerock/davinci-client';
78
import type {
89
FidoRegistrationCollector,
910
FidoAuthenticationCollector,
1011
Updater,
11-
FidoClient,
1212
} from '@forgerock/davinci-client/types';
1313

1414
export default function fidoComponent(
1515
formEl: HTMLFormElement,
1616
collector: FidoRegistrationCollector | FidoAuthenticationCollector,
1717
updater: Updater<FidoRegistrationCollector | FidoAuthenticationCollector>,
18-
fidoApi: FidoClient,
1918
submitForm: () => Promise<void>,
2019
) {
20+
const fidoApi = fido();
2121
if (collector.type === 'FidoRegistrationCollector') {
2222
const button = document.createElement('button');
2323
button.type = 'button';

e2e/davinci-app/main.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import './style.css';
88

99
import { Config, FRUser, TokenManager } from '@forgerock/javascript-sdk';
10-
import { davinci, fido } from '@forgerock/davinci-client';
10+
import { davinci } from '@forgerock/davinci-client';
1111
import type {
1212
CustomLogger,
1313
DaVinciConfig,
@@ -83,7 +83,6 @@ const urlParams = new URLSearchParams(window.location.search);
8383
(async () => {
8484
const davinciClient: DavinciClient = await davinci({ config, logger, requestMiddleware });
8585
const protectApi = protect({ envId: '02fb4743-189a-4bc7-9d6c-a919edfe6447' });
86-
const fidoApi = fido();
8786
const continueToken = urlParams.get('continueToken');
8887
const formEl = document.getElementById('form') as HTMLFormElement;
8988
let resumed: InternalErrorResponse | NodeStates | undefined;
@@ -261,7 +260,6 @@ const urlParams = new URLSearchParams(window.location.search);
261260
formEl, // You can ignore this; it's just for rendering
262261
collector, // This is the plain object of the collector
263262
davinciClient.update(collector), // Returns an update function for this collector
264-
fidoApi, // FIDO module for interacting with WebAuthn API
265263
submitForm,
266264
);
267265
} else if (collector.type === 'FlowCollector') {

e2e/davinci-suites/src/fido.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ test.describe('FIDO/WebAuthn Tests', () => {
4949
await page.getByRole('button', { name: 'Sign On' }).click();
5050

5151
// Register WebAuthn credential
52-
const { credentials: intialCredentials } = await cdp.send('WebAuthn.getCredentials', {
52+
const { credentials: initialCredentials } = await cdp.send('WebAuthn.getCredentials', {
5353
authenticatorId,
5454
});
55-
await expect(intialCredentials).toHaveLength(0);
55+
await expect(initialCredentials).toHaveLength(0);
5656

5757
await page.getByRole('button', { name: 'DEVICE_REGISTRATION' }).click();
5858
await page.getByRole('button', { name: 'Biometrics/Security Key' }).click();
@@ -87,7 +87,9 @@ test.describe('FIDO/WebAuthn Tests', () => {
8787
await expect(page.getByText('FIDO2 Test Form')).toBeVisible();
8888
});
8989

90-
test('Register and authenticate with usernameless', async ({ page }) => {
90+
// Note: This test is currently not working due to a DaVinci issue where the authentication options
91+
// are not included in the response.
92+
test.skip('Register and authenticate with usernameless', async ({ page }) => {
9193
const { navigate } = asyncEvents(page);
9294

9395
await navigate(
@@ -104,10 +106,10 @@ test.describe('FIDO/WebAuthn Tests', () => {
104106
await page.getByRole('button', { name: 'Sign On' }).click();
105107

106108
// Register WebAuthn credential
107-
const { credentials: intialCredentials } = await cdp.send('WebAuthn.getCredentials', {
109+
const { credentials: initialCredentials } = await cdp.send('WebAuthn.getCredentials', {
108110
authenticatorId,
109111
});
110-
await expect(intialCredentials).toHaveLength(0);
112+
await expect(initialCredentials).toHaveLength(0);
111113

112114
await page.getByRole('button', { name: 'DEVICE_REGISTRATION' }).click();
113115
await page.getByRole('button', { name: 'Biometrics/Security Key' }).click();

packages/davinci-client/src/lib/fido/fido.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ export function fido(): FidoClient {
5555
register: async function register(
5656
options: FidoRegistrationOptions,
5757
): Promise<FidoRegistrationInputValue | GenericError> {
58+
if (!options) {
59+
return {
60+
error: 'registration_error',
61+
message: 'FIDO registration failed: No options available',
62+
type: 'fido_error',
63+
} as GenericError;
64+
}
65+
5866
const createCredentialµ = Micro.sync(() => transformRegistrationOptions(options)).pipe(
5967
Micro.flatMap((publicKeyCredentialCreationOptions) =>
6068
Micro.tryPromise({
@@ -108,6 +116,14 @@ export function fido(): FidoClient {
108116
authenticate: async function authenticate(
109117
options: FidoAuthenticationOptions,
110118
): Promise<FidoAuthenticationInputValue | GenericError> {
119+
if (!options) {
120+
return {
121+
error: 'authentication_error',
122+
message: 'FIDO authentication failed: No options available',
123+
type: 'fido_error',
124+
} as GenericError;
125+
}
126+
111127
const getAssertionµ = Micro.sync(() => transformAuthenticationOptions(options)).pipe(
112128
Micro.flatMap((publicKeyCredentialRequestOptions) =>
113129
Micro.tryPromise({

0 commit comments

Comments
 (0)