From 0ddd28f8404401dbe4d379154cfb01c4a1314fbe Mon Sep 17 00:00:00 2001 From: AJ Ancheta <7781450+ancheetah@users.noreply.github.com> Date: Fri, 21 Nov 2025 13:25:34 -0800 Subject: [PATCH] fix(javascript-sdk): add support for KBA allowUserDefinedQuestions flag --- .changeset/wild-gifts-move.md | 5 +++++ .../src/register-basic/autoscript.ts | 14 +++++++++++--- .../src/suites/register-basic.lc.test.ts | 4 +++- e2e/mock-api/src/app/response.registration.js | 8 ++++++++ .../src/fr-auth/callbacks/kba-create-callback.ts | 7 +++++++ 5 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 .changeset/wild-gifts-move.md diff --git a/.changeset/wild-gifts-move.md b/.changeset/wild-gifts-move.md new file mode 100644 index 00000000..777bab73 --- /dev/null +++ b/.changeset/wild-gifts-move.md @@ -0,0 +1,5 @@ +--- +'@forgerock/javascript-sdk': patch +--- + +Add support for KBA `allowUserDefinedQuestions` flag diff --git a/e2e/autoscript-apps/src/register-basic/autoscript.ts b/e2e/autoscript-apps/src/register-basic/autoscript.ts index 6254ddc0..1db5195d 100644 --- a/e2e/autoscript-apps/src/register-basic/autoscript.ts +++ b/e2e/autoscript-apps/src/register-basic/autoscript.ts @@ -89,11 +89,19 @@ function autoscript() { console.log(`Predefined Question1: ${pdq1}`); console.log(`Predefined Question 2: ${pdq2}`); - kbCb1.setQuestion('What is your favorite color?'); + const isAllowedUserDefinedQuestions1 = kbCb1.isAllowedUserDefinedQuestions(); + const isAllowedUserDefinedQuestions2 = kbCb2.isAllowedUserDefinedQuestions(); + console.log(`kbCb1 is allowed user defined questions: ${isAllowedUserDefinedQuestions1}`); + console.log(`kbCb2 is allowed user defined questions: ${isAllowedUserDefinedQuestions2}`); + + kbCb1.setQuestion(pdq1); kbCb1.setAnswer('Red'); - kbCb2.setQuestion('Who was your first employer?'); - kbCb2.setAnswer('AAA Engineering'); + kbCb2.setQuestion('Who was your first pet?'); + kbCb2.setAnswer('Fluffy'); + + const customQuestion = kbCb2.getInputValue(); + console.log(`Custom Question from kbCb2: ${customQuestion}`); console.log('Handle TermsAndConditionsCallback'); const tcCb = step.getCallbackOfType('TermsAndConditionsCallback'); diff --git a/e2e/autoscript-suites/src/suites/register-basic.lc.test.ts b/e2e/autoscript-suites/src/suites/register-basic.lc.test.ts index 1725d55d..20292a0e 100644 --- a/e2e/autoscript-suites/src/suites/register-basic.lc.test.ts +++ b/e2e/autoscript-suites/src/suites/register-basic.lc.test.ts @@ -16,7 +16,7 @@ test.describe('Test basic registration flow', () => { const un = v4(); const email = `${un}@me.com`; - test(`should register user successfully and then log ou`, async ({ page, browserName }) => { + test(`should register user successfully and then log out`, async ({ page, browserName }) => { const { messageArray } = await setupAndGo(page, browserName, 'register-basic/', { un, email, @@ -33,6 +33,8 @@ test.describe('Test basic registration flow', () => { // expect(messageArray.includes('Prompt 6: Age')).toBe(true); expect(messageArray.includes('Prompt 7: Select a security question')).toBe(true); expect(messageArray.includes(`Predefined Question1: What's your favorite color?`)).toBe(true); + expect(messageArray.includes(`kbCb2 is allowed user defined questions: true`)).toBe(true); + expect(messageArray.includes(`Custom Question from kbCb2: Who was your first pet?`)).toBe(true); expect(messageArray.includes('Terms version: 0.0')).toBe(true); expect( messageArray.includes( diff --git a/e2e/mock-api/src/app/response.registration.js b/e2e/mock-api/src/app/response.registration.js index 52714737..a986ffad 100644 --- a/e2e/mock-api/src/app/response.registration.js +++ b/e2e/mock-api/src/app/response.registration.js @@ -181,6 +181,10 @@ export default { name: 'predefinedQuestions', value: [`What's your favorite color?`, 'Who was your first employer?'], }, + { + name: 'allowUserDefinedQuestions', + value: true, + }, ], input: [ { name: 'IDToken8question', value: '' }, @@ -196,6 +200,10 @@ export default { name: 'predefinedQuestions', value: [`What's your favorite color?`, 'Who was your first employer?'], }, + { + name: 'allowUserDefinedQuestions', + value: true, + }, ], input: [ { name: 'IDToken9question', value: '' }, diff --git a/packages/javascript-sdk/src/fr-auth/callbacks/kba-create-callback.ts b/packages/javascript-sdk/src/fr-auth/callbacks/kba-create-callback.ts index f10c9edc..25443493 100644 --- a/packages/javascript-sdk/src/fr-auth/callbacks/kba-create-callback.ts +++ b/packages/javascript-sdk/src/fr-auth/callbacks/kba-create-callback.ts @@ -36,6 +36,13 @@ class KbaCreateCallback extends FRCallback { return this.getOutputByName('predefinedQuestions', []); } + /** + * Gets whether the user can define questions. + */ + public isAllowedUserDefinedQuestions(): boolean { + return this.getOutputByName('allowUserDefinedQuestions', false); + } + /** * Sets the callback's security question. */