Skip to content

Commit 9adfdf3

Browse files
authored
Merge pull request #564 from ForgeRock/SDKS-4284-fix-kba
fix(javascript-sdk): add support for KBA allowUserDefinedQuestions flag
2 parents 97ff4db + 0ddd28f commit 9adfdf3

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

.changeset/wild-gifts-move.md

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+
Add support for KBA `allowUserDefinedQuestions` flag

e2e/autoscript-apps/src/register-basic/autoscript.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,19 @@ function autoscript() {
8989
console.log(`Predefined Question1: ${pdq1}`);
9090
console.log(`Predefined Question 2: ${pdq2}`);
9191

92-
kbCb1.setQuestion('What is your favorite color?');
92+
const isAllowedUserDefinedQuestions1 = kbCb1.isAllowedUserDefinedQuestions();
93+
const isAllowedUserDefinedQuestions2 = kbCb2.isAllowedUserDefinedQuestions();
94+
console.log(`kbCb1 is allowed user defined questions: ${isAllowedUserDefinedQuestions1}`);
95+
console.log(`kbCb2 is allowed user defined questions: ${isAllowedUserDefinedQuestions2}`);
96+
97+
kbCb1.setQuestion(pdq1);
9398
kbCb1.setAnswer('Red');
9499

95-
kbCb2.setQuestion('Who was your first employer?');
96-
kbCb2.setAnswer('AAA Engineering');
100+
kbCb2.setQuestion('Who was your first pet?');
101+
kbCb2.setAnswer('Fluffy');
102+
103+
const customQuestion = kbCb2.getInputValue();
104+
console.log(`Custom Question from kbCb2: ${customQuestion}`);
97105

98106
console.log('Handle TermsAndConditionsCallback');
99107
const tcCb = step.getCallbackOfType('TermsAndConditionsCallback');

e2e/autoscript-suites/src/suites/register-basic.lc.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ test.describe('Test basic registration flow', () => {
1616
const un = v4();
1717
const email = `${un}@me.com`;
1818

19-
test(`should register user successfully and then log ou`, async ({ page, browserName }) => {
19+
test(`should register user successfully and then log out`, async ({ page, browserName }) => {
2020
const { messageArray } = await setupAndGo(page, browserName, 'register-basic/', {
2121
un,
2222
email,
@@ -33,6 +33,8 @@ test.describe('Test basic registration flow', () => {
3333
// expect(messageArray.includes('Prompt 6: Age')).toBe(true);
3434
expect(messageArray.includes('Prompt 7: Select a security question')).toBe(true);
3535
expect(messageArray.includes(`Predefined Question1: What's your favorite color?`)).toBe(true);
36+
expect(messageArray.includes(`kbCb2 is allowed user defined questions: true`)).toBe(true);
37+
expect(messageArray.includes(`Custom Question from kbCb2: Who was your first pet?`)).toBe(true);
3638
expect(messageArray.includes('Terms version: 0.0')).toBe(true);
3739
expect(
3840
messageArray.includes(

e2e/mock-api/src/app/response.registration.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ export default {
181181
name: 'predefinedQuestions',
182182
value: [`What's your favorite color?`, 'Who was your first employer?'],
183183
},
184+
{
185+
name: 'allowUserDefinedQuestions',
186+
value: true,
187+
},
184188
],
185189
input: [
186190
{ name: 'IDToken8question', value: '' },
@@ -196,6 +200,10 @@ export default {
196200
name: 'predefinedQuestions',
197201
value: [`What's your favorite color?`, 'Who was your first employer?'],
198202
},
203+
{
204+
name: 'allowUserDefinedQuestions',
205+
value: true,
206+
},
199207
],
200208
input: [
201209
{ name: 'IDToken9question', value: '' },

packages/javascript-sdk/src/fr-auth/callbacks/kba-create-callback.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ class KbaCreateCallback extends FRCallback {
3636
return this.getOutputByName<string[]>('predefinedQuestions', []);
3737
}
3838

39+
/**
40+
* Gets whether the user can define questions.
41+
*/
42+
public isAllowedUserDefinedQuestions(): boolean {
43+
return this.getOutputByName<boolean>('allowUserDefinedQuestions', false);
44+
}
45+
3946
/**
4047
* Sets the callback's security question.
4148
*/

0 commit comments

Comments
 (0)