Skip to content

Commit 60a09e5

Browse files
committed
Add optionsTransformer
1 parent ce0fba3 commit 60a09e5

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

  • packages/javascript-sdk/src/fr-webauthn

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,17 @@ abstract class FRWebAuthn {
147147
* Automatically handles conditional UI if indicated by the server metadata.
148148
*
149149
* @param step The step that contains WebAuthn authentication data
150+
* @param optionsTransformer Augments the derived options with custom behaviour
150151
* @return The populated step
151152
*/
152-
public static async authenticate(step: FRStep): Promise<FRStep> {
153+
public static async authenticate(step: FRStep, optionsTransformer: Function = a => a): Promise<FRStep> {
153154
const { hiddenCallback, metadataCallback, textOutputCallback } = this.getCallbacks(step);
154155
if (hiddenCallback && (metadataCallback || textOutputCallback)) {
155156
let outcome: ReturnType<typeof this.getAuthenticationOutcome>;
156157
let credential: PublicKeyCredential | null = null;
158+
const options: CredentialRequestOptions = {};
157159

158160
try {
159-
let publicKey: PublicKeyCredentialRequestOptions;
160161

161162
if (metadataCallback) {
162163
const meta = metadataCallback.getOutputValue('data') as WebAuthnAuthenticationMetadata;
@@ -173,23 +174,18 @@ abstract class FRWebAuthn {
173174
}
174175
}
175176

176-
publicKey = this.createAuthenticationPublicKey(meta);
177+
options.publicKey = this.createAuthenticationPublicKey(meta);
178+
options.mediation = mediation;
177179

178-
credential = await this.getAuthenticationCredential({ publicKey, mediation });
179-
outcome = this.getAuthenticationOutcome(credential);
180180
} else if (textOutputCallback) {
181181
const metadata = this.extractMetadata(textOutputCallback.getMessage());
182-
183182
if (metadata) {
184-
publicKey = this.createAuthenticationPublicKey(
183+
options.publicKey = this.createAuthenticationPublicKey(
185184
metadata as WebAuthnAuthenticationMetadata,
186185
);
187186
} else {
188-
publicKey = parseWebAuthnAuthenticateText(textOutputCallback.getMessage());
187+
options.publicKey = parseWebAuthnAuthenticateText(textOutputCallback.getMessage());
189188
}
190-
191-
credential = await this.getAuthenticationCredential({ publicKey });
192-
outcome = this.getAuthenticationOutcome(credential);
193189
} else {
194190
throw new Error('No Credential found from Public Key');
195191
}
@@ -204,6 +200,9 @@ abstract class FRWebAuthn {
204200
throw error;
205201
}
206202

203+
credential = await this.getAuthenticationCredential(optionsTransformer(options));
204+
outcome = this.getAuthenticationOutcome(credential);
205+
207206
if (metadataCallback) {
208207
const meta = metadataCallback.getOutputValue('data') as WebAuthnAuthenticationMetadata;
209208
if (meta?.supportsJsonResponse && credential && 'authenticatorAttachment' in credential) {

0 commit comments

Comments
 (0)