Skip to content

Commit 1693e28

Browse files
progress commit
1 parent a3aa3d8 commit 1693e28

File tree

7 files changed

+102
-11
lines changed

7 files changed

+102
-11
lines changed

lib/idx/remediate.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ export async function remediate(
150150
`);
151151
}
152152

153-
// Return next step to the caller
154-
if (!remediator.canRemediate()) {
153+
// always attempt remediation if `opts.step` is provided
154+
if (!options.step && !remediator.canRemediate()) {
155+
// Return next step to the caller
155156
const nextStep = getNextStep(authClient, remediator, idxResponse);
156157
return {
157158
idxResponse,

lib/idx/remediators/Base/SelectAuthenticator.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,13 @@ export class SelectAuthenticator<T extends SelectAuthenticatorValues = SelectAut
8989

9090
const { options } = remediationValue;
9191
const selectedOption = findMatchedOption(authenticators, options);
92-
this.selectedAuthenticator = selectedOption.relatesTo; // track the selected authenticator
93-
this.selectedOption = selectedOption;
94-
return {
95-
id: selectedOption?.value.form.value.find(({ name }) => name === 'id').value
96-
};
92+
if (selectedOption) {
93+
this.selectedAuthenticator = selectedOption.relatesTo; // track the selected authenticator
94+
this.selectedOption = selectedOption;
95+
return {
96+
id: selectedOption?.value.form.value.find(({ name }) => name === 'id').value
97+
};
98+
}
9799
}
98100

99101
getInputAuthenticator(remediation) {

lib/idx/remediators/SelectAuthenticatorUnlockAccount.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@ export class SelectAuthenticatorUnlockAccount extends SelectAuthenticator<Select
3838
const authenticatorMap = super.mapAuthenticator(remediationValue);
3939
const methodTypeOption = this.selectedOption?.value.form.value.find(({ name }) => name === 'methodType');
4040

41+
const isSingleValue = () => {
42+
if (Array.isArray(methodTypeOption?.options) && methodTypeOption?.options?.length === 1) {
43+
return methodTypeOption?.options?.[0]?.value as string;
44+
}
45+
}
46+
4147
// defaults to 'manually defined' value
4248
// 2nd: option may have pre-defined value, like stateHandle
4349
// 3rd: if only a single OV option is available, default to that option
44-
const methodTypeValue = this.values.methodType ||
45-
methodTypeOption?.value as string || methodTypeOption?.options?.[0]?.value as string;
50+
const methodTypeValue = this.values.methodType || methodTypeOption?.value as string || isSingleValue();
4651

4752
if (methodTypeValue) {
4853
return {

samples/generated/react-embedded-auth-with-sdk/src/App.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ function App() {
5656
history.replace('/terminal');
5757
setTransaction(null);
5858
} else if (status === IdxStatus.FAILURE) {
59+
console.log('ERROR STATUS?')
5960
history.replace('/error');
6061
setTransaction(null);
6162
} else if (status === IdxStatus.CANCELED) {

samples/generated/react-embedded-auth-with-sdk/src/components/GeneralForm.jsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,42 @@ const GeneralForm = () => {
4646
}
4747
};
4848

49+
const handleReselect = async e => {
50+
e.preventDefault();
51+
let newTransaction = transaction;
52+
53+
setProcessing(true);
54+
try {
55+
newTransaction = await oktaAuth.idx.proceed({ step: 'select-authenticator-authenticate' });
56+
setTransaction(newTransaction);
57+
setInputValues({});
58+
}
59+
catch (err) {
60+
console.log('proceed threw');
61+
console.log(err);
62+
}
63+
finally {
64+
setProcessing(false);
65+
}
66+
};
67+
68+
const handleReselectPhone = async e => {
69+
e.preventDefault();
70+
71+
setProcessing(true);
72+
try {
73+
const newTransaction = await oktaAuth.idx.proceed({ step: 'select-authenticator-authenticate', authenticator: 'phone_number' });
74+
setTransaction(newTransaction);
75+
setInputValues({});
76+
}
77+
catch (err) {
78+
console.log(err);
79+
}
80+
finally {
81+
setProcessing(false);
82+
}
83+
};
84+
4985
const handleSkip = async () => {
5086
const newTransaction = await oktaAuth.idx.proceed({ skip: true });
5187
setTransaction(newTransaction);
@@ -120,6 +156,12 @@ const GeneralForm = () => {
120156
<Box paddingTop="s" paddingBottom="s">
121157
<Button wide type="submit" disabled={processing}>Submit</Button>
122158
</Box>
159+
<Box paddingTop="s" paddingBottom="s">
160+
<Button wide variant="secondary" disabled={processing} onClick={handleReselect}>Re-Select</Button>
161+
</Box>
162+
<Box paddingTop="s" paddingBottom="s">
163+
<Button wide variant="secondary" disabled={processing} onClick={handleReselectPhone}>Re-Select Phone</Button>
164+
</Box>
123165
{canRecoverPassword && (
124166
<Box paddingTop="s" paddingBottom="s">
125167
<Link href="#" name="forgotPassword" onClick={handleRecoverPassword}>Forgot password</Link>

samples/generated/react-embedded-auth-with-sdk/src/components/HomePage/HomePage.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export default function Home() {
6666
<Box display="flex" margin="s">
6767
<Button name="signin" variant="primary" onClick={startIdxFlow('default')}>Sign In</Button>
6868
<Button name="signup" variant="secondary" onClick={startIdxFlow('register')}>Sign Up</Button>
69+
<Button name="unlock" variant="secondary" onClick={startIdxFlow('unlockAccount')}>Unlock</Button>
6970
</Box>
7071
</Box>
7172
)}

test/spec/idx/remediators/SelectAuthenticator.ts

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { SelectAuthenticatorAuthenticate, SelectAuthenticatorEnroll } from '../../../../lib/idx/remediators';
1+
import {
2+
SelectAuthenticatorAuthenticate,
3+
SelectAuthenticatorEnroll,
4+
SelectAuthenticatorUnlockAccount
5+
} from '../../../../lib/idx/remediators';
26
import {
37
SelectAuthenticatorEnrollRemediationFactory,
48
SelectAuthenticatorAuthenticateRemediationFactory,
@@ -7,7 +11,10 @@ import {
711
EmailAuthenticatorOptionFactory,
812
IdxContextFactory,
913
PhoneAuthenticatorFactory,
10-
EmailAuthenticatorFactory
14+
EmailAuthenticatorFactory,
15+
SelectAuthenticatorUnlockAccountRemediationFactory,
16+
SecurityQuestionAuthenticatorOptionFactory,
17+
IdxValueFactory,
1118
} from '@okta/test.support/idx';
1219

1320
describe('remediators/Base/SelectAuthenticator', () => {
@@ -122,3 +129,35 @@ describe('remediators/SelectAuthenticatorAuthenticate', () => {
122129
});
123130
});
124131
});
132+
133+
describe('remediators/SelectAuthenticatorUnlockAccount', () => {
134+
describe('mapAuthenticator', () => {
135+
// TODO: return methodType 1
136+
137+
// TODO: return methodType 2
138+
139+
// TODO: return methodType 3
140+
141+
// TODO: return no methodType
142+
fit('should not return a methodType value', () => {
143+
const phoneAuthenticatorValue = AuthenticatorValueFactory.build({
144+
options: [
145+
PhoneAuthenticatorOptionFactory.build(),
146+
]
147+
});
148+
149+
const remediation = SelectAuthenticatorUnlockAccountRemediationFactory.build({
150+
value: [
151+
phoneAuthenticatorValue
152+
]
153+
});
154+
155+
console.log(phoneAuthenticatorValue);
156+
console.log('##########')
157+
console.log(remediation);
158+
159+
const r = new SelectAuthenticatorUnlockAccount(remediation);
160+
expect(r.mapAuthenticator(phoneAuthenticatorValue)).toBe(false);
161+
});
162+
});
163+
});

0 commit comments

Comments
 (0)