Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Samples: password recovery OKTA-382115 (#693)
OKTA-388545 <<<Jenkins Check-In of Tested SHA: 6842f2a for eng_productivity_ci_bot_okta@okta.com>>> Artifact: okta-auth-js Files changed count: 252
- Loading branch information
1 parent
a29968d
commit 58b6aec
Showing
46 changed files
with
934 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { AuthSdkError } from '../errors'; | ||
import { OktaAuth } from '..'; | ||
import {IdxTransactionMeta} from '../types'; | ||
|
||
export async function handleInteractionCodeRedirect( | ||
authClient: OktaAuth, | ||
url: string | ||
): Promise<void> { | ||
const { | ||
codeVerifier, | ||
state: savedState | ||
} = authClient.transactionManager.load() as IdxTransactionMeta; | ||
const { | ||
searchParams | ||
// URL API has been added to the polyfill | ||
// eslint-disable-next-line compat/compat | ||
} = new URL(url); | ||
const state = searchParams.get('state'); | ||
const interactionCode = searchParams.get('interaction_code'); | ||
|
||
// Error handling | ||
const error = searchParams.get('error'); | ||
if (error) { | ||
throw new AuthSdkError(error); | ||
} | ||
if (state !== savedState) { | ||
throw new AuthSdkError('State in redirect uri does not match with transaction state'); | ||
} | ||
if (!interactionCode) { | ||
throw new AuthSdkError('Unable to parse interaction_code from the url'); | ||
} | ||
|
||
// Save tokens to storage | ||
const { tokens } = await authClient.token.exchangeCodeForTokens({ interactionCode, codeVerifier }); | ||
authClient.tokenManager.setTokens(tokens); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from './authenticate'; | ||
export * from './interact'; | ||
export * from './introspect'; | ||
export * from './cancel'; | ||
export * from './register'; | ||
export * from './recoverPassword'; | ||
export * from './handleInteractionCodeRedirect'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { AuthTransaction } from '../tx'; | ||
import { | ||
OktaAuth, | ||
PasswordRecoveryOptions, | ||
RemediationFlow, | ||
} from '../types'; | ||
import { run } from './run'; | ||
import { | ||
Identify, | ||
SelectAuthenticator, | ||
EnrollOrChallengeAuthenticator, | ||
AuthenticatorVerificationData, | ||
} from './remediators'; | ||
|
||
const flow: RemediationFlow = { | ||
'identify-recovery': Identify, | ||
'select-authenticator-authenticate': SelectAuthenticator, | ||
'challenge-authenticator': EnrollOrChallengeAuthenticator, | ||
'authenticator-verification-data': AuthenticatorVerificationData, | ||
'reset-authenticator': EnrollOrChallengeAuthenticator, | ||
}; | ||
|
||
export async function recoverPassword( | ||
authClient: OktaAuth, options: PasswordRecoveryOptions | ||
): Promise<AuthTransaction> { | ||
return run(authClient, { | ||
...options, | ||
flow, | ||
needInteraction: true, | ||
actionPath: 'currentAuthenticator-recover', | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Base from './Base'; | ||
|
||
export default class AuthenticatorVerificationData extends Base { | ||
values: any; // TODO: add proper type | ||
|
||
map = { | ||
'authenticator': ['authenticator'] | ||
}; | ||
|
||
canRemediate() { | ||
// TODO: check if authenticator exist in values | ||
return this.remediation.value | ||
.some(({ name }) => name === 'authenticator'); | ||
} | ||
|
||
mapAuthenticator() { | ||
const authenticatorVal = this.remediation.value | ||
.find(({ name }) => name === 'authenticator').form.value; | ||
return { | ||
id: authenticatorVal | ||
.find(({ name }) => name === 'id').value, | ||
enrollmentId: authenticatorVal | ||
.find(({ name }) => name === 'enrollmentId').value, | ||
methodType: 'sms', | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../remediators/SelectAuthenticatorEnroll.ts → lib/idx/remediators/SelectAuthenticator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export { default as Base } from './Base'; | ||
export { default as EnrollOrChallengeAuthenticator } from './EnrollOrChallengeAuthenticator'; | ||
export { default as EnrollProfile } from './EnrollProfile'; | ||
export { default as Identify } from './Identify'; | ||
export { default as SelectAuthenticator } from './SelectAuthenticator'; | ||
export { default as SelectEnrollProfile } from './SelectEnrollProfile'; | ||
export { default as AuthenticatorVerificationData } from './AuthenticatorVerificationData'; |
Oops, something went wrong.