Skip to content

Commit 48cb4fa

Browse files
committed
fix: retrieve WebAuthn credentials inside try/catch OPENAM-26284
1 parent 60e6ffb commit 48cb4fa

2 files changed

Lines changed: 25 additions & 21 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@forgerock/javascript-sdk': patch
3+
---
4+
5+
fix: move getAuthenticationCredential back inside try/catch so that WebAuthn cancellation errors (e.g. NotAllowedError) are written to the HiddenValueCallback before re-throwing

packages/javascript-sdk/src/fr-webauthn/index.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,26 @@ abstract class FRWebAuthn {
199199
} else {
200200
throw new Error('No Credential found from Public Key');
201201
}
202+
const credential: PublicKeyCredential | null = await this.getAuthenticationCredential(
203+
optionsTransformer(options),
204+
);
205+
const outcome: ReturnType<typeof this.getAuthenticationOutcome> =
206+
this.getAuthenticationOutcome(credential);
207+
208+
if (metadataCallback) {
209+
const meta = metadataCallback.getOutputValue('data') as WebAuthnAuthenticationMetadata;
210+
if (meta?.supportsJsonResponse && credential && 'authenticatorAttachment' in credential) {
211+
hiddenCallback.setInputValue(
212+
JSON.stringify({
213+
authenticatorAttachment: credential.authenticatorAttachment,
214+
legacyData: outcome,
215+
}),
216+
);
217+
return step;
218+
}
219+
}
220+
hiddenCallback.setInputValue(outcome);
221+
return step;
202222
} catch (error) {
203223
if (!(error instanceof Error)) throw error;
204224
// NotSupportedError is a special case
@@ -209,27 +229,6 @@ abstract class FRWebAuthn {
209229
hiddenCallback.setInputValue(`${WebAuthnOutcome.Error}::${error.name}:${error.message}`);
210230
throw error;
211231
}
212-
213-
const credential: PublicKeyCredential | null = await this.getAuthenticationCredential(
214-
optionsTransformer(options),
215-
);
216-
const outcome: ReturnType<typeof this.getAuthenticationOutcome> =
217-
this.getAuthenticationOutcome(credential);
218-
219-
if (metadataCallback) {
220-
const meta = metadataCallback.getOutputValue('data') as WebAuthnAuthenticationMetadata;
221-
if (meta?.supportsJsonResponse && credential && 'authenticatorAttachment' in credential) {
222-
hiddenCallback.setInputValue(
223-
JSON.stringify({
224-
authenticatorAttachment: credential.authenticatorAttachment,
225-
legacyData: outcome,
226-
}),
227-
);
228-
return step;
229-
}
230-
}
231-
hiddenCallback.setInputValue(outcome);
232-
return step;
233232
} else {
234233
const e = new Error('Incorrect callbacks for WebAuthn authentication');
235234
e.name = WebAuthnOutcomeType.DataError;

0 commit comments

Comments
 (0)