Skip to content

Commit

Permalink
progress commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredperreault-okta committed Dec 18, 2023
1 parent a3b41a3 commit ac49b6a
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 11 deletions.
5 changes: 3 additions & 2 deletions lib/idx/remediate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ export async function remediate(
`);
}

// Return next step to the caller
if (!remediator.canRemediate()) {
// always attempt remediation if `opts.step` is provided
if (!options.step && !remediator.canRemediate()) {
// Return next step to the caller
const nextStep = getNextStep(authClient, remediator, idxResponse);
return {
idxResponse,
Expand Down
12 changes: 7 additions & 5 deletions lib/idx/remediators/Base/SelectAuthenticator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ export class SelectAuthenticator<T extends SelectAuthenticatorValues = SelectAut

const { options } = remediationValue;
const selectedOption = findMatchedOption(authenticators, options);
this.selectedAuthenticator = selectedOption.relatesTo; // track the selected authenticator
this.selectedOption = selectedOption;
return {
id: selectedOption?.value.form.value.find(({ name }) => name === 'id').value
};
if (selectedOption) {
this.selectedAuthenticator = selectedOption.relatesTo; // track the selected authenticator
this.selectedOption = selectedOption;
return {
id: selectedOption?.value.form.value.find(({ name }) => name === 'id').value
};
}
}

getInputAuthenticator(remediation) {
Expand Down
9 changes: 7 additions & 2 deletions lib/idx/remediators/SelectAuthenticatorUnlockAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ export class SelectAuthenticatorUnlockAccount extends SelectAuthenticator<Select
const authenticatorMap = super.mapAuthenticator(remediationValue);
const methodTypeOption = this.selectedOption?.value.form.value.find(({ name }) => name === 'methodType');

const isSingleValue = () => {
if (Array.isArray(methodTypeOption?.options) && methodTypeOption?.options?.length === 1) {
return methodTypeOption?.options?.[0]?.value as string;
}
}

// defaults to 'manually defined' value
// 2nd: option may have pre-defined value, like stateHandle
// 3rd: if only a single OV option is available, default to that option
const methodTypeValue = this.values.methodType ||
methodTypeOption?.value as string || methodTypeOption?.options?.[0]?.value as string;
const methodTypeValue = this.values.methodType || methodTypeOption?.value as string || isSingleValue();

if (methodTypeValue) {
return {
Expand Down
1 change: 1 addition & 0 deletions samples/generated/react-embedded-auth-with-sdk/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function App() {
history.replace('/terminal');
setTransaction(null);
} else if (status === IdxStatus.FAILURE) {
console.log('ERROR STATUS?')
history.replace('/error');
setTransaction(null);
} else if (status === IdxStatus.CANCELED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,42 @@ const GeneralForm = () => {
}
};

const handleReselect = async e => {
e.preventDefault();
let newTransaction = transaction;

setProcessing(true);
try {
newTransaction = await oktaAuth.idx.proceed({ step: 'select-authenticator-authenticate' });
setTransaction(newTransaction);
setInputValues({});
}
catch (err) {
console.log('proceed threw');
console.log(err);
}
finally {
setProcessing(false);
}
};

const handleReselectPhone = async e => {
e.preventDefault();

setProcessing(true);
try {
const newTransaction = await oktaAuth.idx.proceed({ step: 'select-authenticator-authenticate', authenticator: 'phone_number' });
setTransaction(newTransaction);
setInputValues({});
}
catch (err) {
console.log(err);
}
finally {
setProcessing(false);
}
};

const handleSkip = async () => {
const newTransaction = await oktaAuth.idx.proceed({ skip: true });
setTransaction(newTransaction);
Expand Down Expand Up @@ -120,6 +156,12 @@ const GeneralForm = () => {
<Box paddingTop="s" paddingBottom="s">
<Button wide type="submit" disabled={processing}>Submit</Button>
</Box>
<Box paddingTop="s" paddingBottom="s">
<Button wide variant="secondary" disabled={processing} onClick={handleReselect}>Re-Select</Button>
</Box>
<Box paddingTop="s" paddingBottom="s">
<Button wide variant="secondary" disabled={processing} onClick={handleReselectPhone}>Re-Select Phone</Button>
</Box>
{canRecoverPassword && (
<Box paddingTop="s" paddingBottom="s">
<Link href="#" name="forgotPassword" onClick={handleRecoverPassword}>Forgot password</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default function Home() {
<Box display="flex" margin="s">
<Button name="signin" variant="primary" onClick={startIdxFlow('default')}>Sign In</Button>
<Button name="signup" variant="secondary" onClick={startIdxFlow('register')}>Sign Up</Button>
<Button name="unlock" variant="secondary" onClick={startIdxFlow('unlockAccount')}>Unlock</Button>
</Box>
</Box>
)}
Expand Down
43 changes: 41 additions & 2 deletions test/spec/idx/remediators/SelectAuthenticator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { SelectAuthenticatorAuthenticate, SelectAuthenticatorEnroll } from '../../../../lib/idx/remediators';
import {
SelectAuthenticatorAuthenticate,
SelectAuthenticatorEnroll,
SelectAuthenticatorUnlockAccount
} from '../../../../lib/idx/remediators';
import {
SelectAuthenticatorEnrollRemediationFactory,
SelectAuthenticatorAuthenticateRemediationFactory,
Expand All @@ -7,7 +11,10 @@ import {
EmailAuthenticatorOptionFactory,
IdxContextFactory,
PhoneAuthenticatorFactory,
EmailAuthenticatorFactory
EmailAuthenticatorFactory,
SelectAuthenticatorUnlockAccountRemediationFactory,
SecurityQuestionAuthenticatorOptionFactory,
IdxValueFactory,
} from '@okta/test.support/idx';

describe('remediators/Base/SelectAuthenticator', () => {
Expand Down Expand Up @@ -122,3 +129,35 @@ describe('remediators/SelectAuthenticatorAuthenticate', () => {
});
});
});

describe('remediators/SelectAuthenticatorUnlockAccount', () => {
describe('mapAuthenticator', () => {
// TODO: return methodType 1

// TODO: return methodType 2

// TODO: return methodType 3

// TODO: return no methodType
fit('should not return a methodType value', () => {
const phoneAuthenticatorValue = AuthenticatorValueFactory.build({
options: [
PhoneAuthenticatorOptionFactory.build(),
]
});

const remediation = SelectAuthenticatorUnlockAccountRemediationFactory.build({
value: [
phoneAuthenticatorValue
]
});

console.log(phoneAuthenticatorValue);
console.log('##########')
console.log(remediation);

const r = new SelectAuthenticatorUnlockAccount(remediation);
expect(r.mapAuthenticator(phoneAuthenticatorValue)).toBe(false);
});
});
});

0 comments on commit ac49b6a

Please sign in to comment.