-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathkba-create-callback.ts
More file actions
68 lines (58 loc) · 1.74 KB
/
kba-create-callback.ts
File metadata and controls
68 lines (58 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Copyright (c) 2020 - 2025 Ping Identity Corporation. All rights reserved.
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
import type { Callback } from '@forgerock/sdk-types';
import { BaseCallback } from './base-callback.js';
/**
* Represents a callback used to collect KBA-style security questions and answers.
*/
export class KbaCreateCallback extends BaseCallback {
/**
* @param payload The raw payload returned by OpenAM
*/
constructor(public override payload: Callback) {
super(payload);
}
/**
* Gets the callback prompt.
*/
public getPrompt(): string {
return this.getOutputByName<string>('prompt', '');
}
/**
* Gets the callback's list of pre-defined security questions.
*/
public getPredefinedQuestions(): string[] {
return this.getOutputByName<string[]>('predefinedQuestions', []);
}
/**
* Gets whether the user can define questions.
*/
public isAllowedUserDefinedQuestions(): boolean {
return this.getOutputByName<boolean>('allowUserDefinedQuestions', false);
}
/**
* Sets the callback's security question.
*/
public setQuestion(question: string): void {
this.setValue('question', question);
}
/**
* Sets the callback's security question answer.
*/
public setAnswer(answer: string): void {
this.setValue('answer', answer);
}
private setValue(type: 'question' | 'answer', value: string): void {
if (!this.payload.input) {
throw new Error('KBA payload is missing input');
}
const input = this.payload.input.find((x) => x.name.endsWith(type));
if (!input) {
throw new Error(`No input has name ending in "${type}"`);
}
input.value = value;
}
}