@okta/okta-auth-js 5.9.1 → 5.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +12 -2
- package/cjs/OktaAuth.js +25 -12
- package/cjs/OktaAuth.js.map +1 -1
- package/cjs/OktaUserAgent.js +2 -2
- package/cjs/OktaUserAgent.js.map +1 -1
- package/cjs/TokenManager.js +24 -2
- package/cjs/TokenManager.js.map +1 -1
- package/cjs/idx/authenticator/Authenticator.js +14 -0
- package/cjs/idx/authenticator/Authenticator.js.map +1 -0
- package/cjs/idx/authenticator/OktaPassword.js +31 -0
- package/cjs/idx/authenticator/OktaPassword.js.map +1 -0
- package/cjs/idx/authenticator/OktaVerifyTotp.js +17 -0
- package/cjs/idx/authenticator/OktaVerifyTotp.js.map +1 -0
- package/cjs/idx/authenticator/SecurityQuestionEnrollment.js +50 -0
- package/cjs/idx/authenticator/SecurityQuestionEnrollment.js.map +1 -0
- package/cjs/idx/authenticator/SecurityQuestionVerification.js +31 -0
- package/cjs/idx/authenticator/SecurityQuestionVerification.js.map +1 -0
- package/cjs/idx/authenticator/VerificationCodeAuthenticator.js +34 -0
- package/cjs/idx/authenticator/VerificationCodeAuthenticator.js.map +1 -0
- package/cjs/idx/authenticator/getAuthenticator.js +42 -0
- package/cjs/idx/authenticator/getAuthenticator.js.map +1 -0
- package/cjs/idx/authenticator/index.js +80 -0
- package/cjs/idx/authenticator/index.js.map +1 -0
- package/cjs/idx/cancel.js +5 -0
- package/cjs/idx/cancel.js.map +1 -1
- package/cjs/idx/flow/AuthenticationFlow.js +2 -0
- package/cjs/idx/flow/AuthenticationFlow.js.map +1 -1
- package/cjs/idx/flow/FlowSpecification.js +1 -11
- package/cjs/idx/flow/FlowSpecification.js.map +1 -1
- package/cjs/idx/flow/RegistrationFlow.js +1 -0
- package/cjs/idx/flow/RegistrationFlow.js.map +1 -1
- package/cjs/idx/flow/index.js +0 -52
- package/cjs/idx/flow/index.js.map +1 -1
- package/cjs/idx/index.js +13 -0
- package/cjs/idx/index.js.map +1 -1
- package/cjs/idx/interact.js +8 -2
- package/cjs/idx/interact.js.map +1 -1
- package/cjs/idx/poll.js +59 -0
- package/cjs/idx/poll.js.map +1 -0
- package/cjs/idx/proceed.js.map +1 -1
- package/cjs/idx/register.js +14 -3
- package/cjs/idx/register.js.map +1 -1
- package/cjs/idx/remediate.js +37 -90
- package/cjs/idx/remediate.js.map +1 -1
- package/cjs/idx/remediators/AuthenticatorEnrollmentData.js +9 -12
- package/cjs/idx/remediators/AuthenticatorEnrollmentData.js.map +1 -1
- package/cjs/idx/remediators/AuthenticatorVerificationData.js +6 -9
- package/cjs/idx/remediators/AuthenticatorVerificationData.js.map +1 -1
- package/cjs/idx/remediators/Base/AuthenticatorData.js +43 -32
- package/cjs/idx/remediators/Base/AuthenticatorData.js.map +1 -1
- package/cjs/idx/remediators/Base/Remediator.js +51 -20
- package/cjs/idx/remediators/Base/Remediator.js.map +1 -1
- package/cjs/idx/remediators/Base/SelectAuthenticator.js +16 -16
- package/cjs/idx/remediators/Base/SelectAuthenticator.js.map +1 -1
- package/cjs/idx/remediators/Base/VerifyAuthenticator.js +8 -28
- package/cjs/idx/remediators/Base/VerifyAuthenticator.js.map +1 -1
- package/{lib/idx/flow/FlowMonitor.d.ts → cjs/idx/remediators/ChallengePoll.js} +16 -13
- package/cjs/idx/remediators/ChallengePoll.js.map +1 -0
- package/cjs/idx/remediators/EnrollPoll.js +56 -0
- package/cjs/idx/remediators/EnrollPoll.js.map +1 -0
- package/cjs/idx/remediators/Identify.js +2 -35
- package/cjs/idx/remediators/Identify.js.map +1 -1
- package/cjs/idx/remediators/SelectAuthenticatorAuthenticate.js +23 -2
- package/cjs/idx/remediators/SelectAuthenticatorAuthenticate.js.map +1 -1
- package/cjs/idx/remediators/Skip.js +7 -0
- package/cjs/idx/remediators/Skip.js.map +1 -1
- package/cjs/idx/remediators/index.js +26 -0
- package/cjs/idx/remediators/index.js.map +1 -1
- package/cjs/idx/run.js +0 -8
- package/cjs/idx/run.js.map +1 -1
- package/cjs/idx/types/idx-js.js.map +1 -1
- package/cjs/idx/types/index.js +2 -1
- package/cjs/idx/types/index.js.map +1 -1
- package/cjs/types/Token.js.map +1 -1
- package/dist/okta-auth-js.min.js +1 -1
- package/dist/okta-auth-js.min.js.map +1 -1
- package/dist/okta-auth-js.umd.js +1 -1
- package/dist/okta-auth-js.umd.js.map +1 -1
- package/esm/index.js +1409 -1197
- package/esm/index.js.map +1 -1
- package/lib/TokenManager.d.ts +2 -0
- package/lib/idx/authenticator/Authenticator.d.ts +12 -0
- package/lib/idx/authenticator/OktaPassword.d.ts +11 -0
- package/lib/idx/authenticator/OktaVerifyTotp.d.ts +9 -0
- package/lib/idx/authenticator/SecurityQuestionEnrollment.d.ts +28 -0
- package/lib/idx/authenticator/SecurityQuestionVerification.d.ts +14 -0
- package/lib/idx/authenticator/VerificationCodeAuthenticator.d.ts +10 -0
- package/lib/idx/authenticator/getAuthenticator.d.ts +3 -0
- package/lib/idx/authenticator/index.d.ts +6 -0
- package/lib/idx/flow/FlowSpecification.d.ts +0 -2
- package/lib/idx/flow/index.d.ts +0 -4
- package/lib/idx/index.d.ts +1 -0
- package/lib/idx/interact.d.ts +1 -0
- package/lib/idx/{flow/AuthenticationFlowMonitor.d.ts → poll.d.ts} +3 -5
- package/lib/idx/proceed.d.ts +2 -1
- package/lib/idx/register.d.ts +1 -1
- package/lib/idx/remediators/AuthenticatorEnrollmentData.d.ts +9 -5
- package/lib/idx/remediators/AuthenticatorVerificationData.d.ts +0 -1
- package/lib/idx/remediators/Base/AuthenticatorData.d.ts +8 -3
- package/lib/idx/remediators/Base/Remediator.d.ts +9 -6
- package/lib/idx/remediators/Base/SelectAuthenticator.d.ts +5 -4
- package/lib/idx/remediators/Base/VerifyAuthenticator.d.ts +8 -4
- package/lib/idx/{flow/RegistrationFlowMonitor.d.ts → remediators/ChallengePoll.d.ts} +3 -3
- package/lib/idx/{flow/PasswordRecoveryFlowMonitor.d.ts → remediators/EnrollPoll.d.ts} +12 -4
- package/lib/idx/remediators/Identify.d.ts +0 -3
- package/lib/idx/remediators/SelectAuthenticatorAuthenticate.d.ts +6 -2
- package/lib/idx/remediators/Skip.d.ts +3 -0
- package/lib/idx/remediators/index.d.ts +2 -0
- package/lib/idx/run.d.ts +1 -2
- package/lib/idx/types/idx-js.d.ts +49 -1
- package/lib/idx/types/index.d.ts +8 -2
- package/lib/types/OktaAuthOptions.d.ts +1 -0
- package/lib/types/Token.d.ts +1 -0
- package/lib/types/api.d.ts +4 -2
- package/package.json +6 -8
- package/cjs/idx/flow/AuthenticationFlowMonitor.js +0 -45
- package/cjs/idx/flow/AuthenticationFlowMonitor.js.map +0 -1
- package/cjs/idx/flow/FlowMonitor.js +0 -69
- package/cjs/idx/flow/FlowMonitor.js.map +0 -1
- package/cjs/idx/flow/PasswordRecoveryFlowMonitor.js +0 -55
- package/cjs/idx/flow/PasswordRecoveryFlowMonitor.js.map +0 -1
- package/cjs/idx/flow/RegistrationFlowMonitor.js +0 -35
- package/cjs/idx/flow/RegistrationFlowMonitor.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../lib/idx/flow/RegistrationFlow.ts"],"names":["RegistrationFlow","SelectEnrollProfile","EnrollProfile","AuthenticatorEnrollmentData","SelectAuthenticatorEnroll","EnrollAuthenticator","Skip"],"mappings":";;;;AAcA;;AAdA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;
|
|
1
|
+
{"version":3,"sources":["../../../../lib/idx/flow/RegistrationFlow.ts"],"names":["RegistrationFlow","SelectEnrollProfile","EnrollProfile","AuthenticatorEnrollmentData","SelectAuthenticatorEnroll","EnrollPoll","EnrollAuthenticator","Skip"],"mappings":";;;;AAcA;;AAdA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAcO,MAAMA,gBAAiC,GAAG;AAC/C,2BAAyBC,gCADsB;AAE/C,oBAAkBC,0BAF6B;AAG/C,mCAAiCC,wCAHc;AAI/C,iCAA+BC,sCAJgB;AAK/C,iBAAeC,uBALgC;AAM/C,0BAAwBC,gCANuB;AAO/C,UAAQC;AAPuC,CAA1C","sourcesContent":["/*!\n * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * \n * See the License for the specific language governing permissions and limitations under the License.\n */\n\n\nimport { RemediationFlow } from './RemediationFlow';\nimport { \n SelectEnrollProfile,\n EnrollPoll,\n EnrollProfile,\n SelectAuthenticatorEnroll,\n EnrollAuthenticator,\n AuthenticatorEnrollmentData,\n Skip,\n} from '../remediators';\n\nexport const RegistrationFlow: RemediationFlow = {\n 'select-enroll-profile': SelectEnrollProfile,\n 'enroll-profile': EnrollProfile,\n 'authenticator-enrollment-data': AuthenticatorEnrollmentData,\n 'select-authenticator-enroll': SelectAuthenticatorEnroll,\n 'enroll-poll': EnrollPoll,\n 'enroll-authenticator': EnrollAuthenticator,\n 'skip': Skip,\n};\n"],"file":"RegistrationFlow.js"}
|
package/cjs/idx/flow/index.js
CHANGED
|
@@ -13,32 +13,6 @@ Object.keys(_AuthenticationFlow).forEach(function (key) {
|
|
|
13
13
|
});
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
var _AuthenticationFlowMonitor = require("./AuthenticationFlowMonitor");
|
|
17
|
-
|
|
18
|
-
Object.keys(_AuthenticationFlowMonitor).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _AuthenticationFlowMonitor[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _AuthenticationFlowMonitor[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
var _FlowMonitor = require("./FlowMonitor");
|
|
30
|
-
|
|
31
|
-
Object.keys(_FlowMonitor).forEach(function (key) {
|
|
32
|
-
if (key === "default" || key === "__esModule") return;
|
|
33
|
-
if (key in exports && exports[key] === _FlowMonitor[key]) return;
|
|
34
|
-
Object.defineProperty(exports, key, {
|
|
35
|
-
enumerable: true,
|
|
36
|
-
get: function () {
|
|
37
|
-
return _FlowMonitor[key];
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
16
|
var _FlowSpecification = require("./FlowSpecification");
|
|
43
17
|
|
|
44
18
|
Object.keys(_FlowSpecification).forEach(function (key) {
|
|
@@ -65,19 +39,6 @@ Object.keys(_PasswordRecoveryFlow).forEach(function (key) {
|
|
|
65
39
|
});
|
|
66
40
|
});
|
|
67
41
|
|
|
68
|
-
var _PasswordRecoveryFlowMonitor = require("./PasswordRecoveryFlowMonitor");
|
|
69
|
-
|
|
70
|
-
Object.keys(_PasswordRecoveryFlowMonitor).forEach(function (key) {
|
|
71
|
-
if (key === "default" || key === "__esModule") return;
|
|
72
|
-
if (key in exports && exports[key] === _PasswordRecoveryFlowMonitor[key]) return;
|
|
73
|
-
Object.defineProperty(exports, key, {
|
|
74
|
-
enumerable: true,
|
|
75
|
-
get: function () {
|
|
76
|
-
return _PasswordRecoveryFlowMonitor[key];
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
42
|
var _RegistrationFlow = require("./RegistrationFlow");
|
|
82
43
|
|
|
83
44
|
Object.keys(_RegistrationFlow).forEach(function (key) {
|
|
@@ -91,19 +52,6 @@ Object.keys(_RegistrationFlow).forEach(function (key) {
|
|
|
91
52
|
});
|
|
92
53
|
});
|
|
93
54
|
|
|
94
|
-
var _RegistrationFlowMonitor = require("./RegistrationFlowMonitor");
|
|
95
|
-
|
|
96
|
-
Object.keys(_RegistrationFlowMonitor).forEach(function (key) {
|
|
97
|
-
if (key === "default" || key === "__esModule") return;
|
|
98
|
-
if (key in exports && exports[key] === _RegistrationFlowMonitor[key]) return;
|
|
99
|
-
Object.defineProperty(exports, key, {
|
|
100
|
-
enumerable: true,
|
|
101
|
-
get: function () {
|
|
102
|
-
return _RegistrationFlowMonitor[key];
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
55
|
var _RemediationFlow = require("./RemediationFlow");
|
|
108
56
|
|
|
109
57
|
Object.keys(_RemediationFlow).forEach(function (key) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../lib/idx/flow/index.ts"],"names":[],"mappings":";;AAYA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA
|
|
1
|
+
{"version":3,"sources":["../../../../lib/idx/flow/index.ts"],"names":[],"mappings":";;AAYA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["/*!\n * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * \n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nexport * from './AuthenticationFlow';\nexport * from './FlowSpecification';\nexport * from './PasswordRecoveryFlow';\nexport * from './RegistrationFlow';\nexport * from './RemediationFlow';\n"],"file":"index.js"}
|
package/cjs/idx/index.js
CHANGED
|
@@ -52,6 +52,19 @@ Object.keys(_introspect).forEach(function (key) {
|
|
|
52
52
|
});
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
+
var _poll = require("./poll");
|
|
56
|
+
|
|
57
|
+
Object.keys(_poll).forEach(function (key) {
|
|
58
|
+
if (key === "default" || key === "__esModule") return;
|
|
59
|
+
if (key in exports && exports[key] === _poll[key]) return;
|
|
60
|
+
Object.defineProperty(exports, key, {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _poll[key];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
55
68
|
var _proceed = require("./proceed");
|
|
56
69
|
|
|
57
70
|
Object.keys(_proceed).forEach(function (key) {
|
package/cjs/idx/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../lib/idx/index.ts"],"names":[],"mappings":";;AAaA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["/*!\n * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * \n * See the License for the specific language governing permissions and limitations under the License.\n */\n\n\nexport * from './authenticate';\nexport * from './cancel';\nexport * from './interact';\nexport * from './introspect';\nexport * from './proceed';\nexport * from './register';\nexport * from './recoverPassword';\nexport * from './handleInteractionCodeRedirect';\nexport * from './startTransaction';\nexport * from './transactionMeta';\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../../../lib/idx/index.ts"],"names":[],"mappings":";;AAaA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["/*!\n * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * \n * See the License for the specific language governing permissions and limitations under the License.\n */\n\n\nexport * from './authenticate';\nexport * from './cancel';\nexport * from './interact';\nexport * from './introspect';\nexport * from './poll';\nexport * from './proceed';\nexport * from './register';\nexport * from './recoverPassword';\nexport * from './handleInteractionCodeRedirect';\nexport * from './startTransaction';\nexport * from './transactionMeta';\n"],"file":"index.js"}
|
package/cjs/idx/interact.js
CHANGED
|
@@ -52,7 +52,11 @@ async function interact(authClient, options = {}) {
|
|
|
52
52
|
} = authClient.options; // These properties can be set in options, but also have a default value in global configuration.
|
|
53
53
|
|
|
54
54
|
state = state || meta.state;
|
|
55
|
-
const scopes = options.scopes || authClient.options.scopes || meta.scopes;
|
|
55
|
+
const scopes = options.scopes || authClient.options.scopes || meta.scopes; // These properties can be set in options
|
|
56
|
+
|
|
57
|
+
const {
|
|
58
|
+
activationToken
|
|
59
|
+
} = options;
|
|
56
60
|
const baseUrl = (0, _oidc.getOAuthBaseUrl)(authClient);
|
|
57
61
|
return _oktaIdxJs.default.interact({
|
|
58
62
|
// OAuth
|
|
@@ -63,7 +67,9 @@ async function interact(authClient, options = {}) {
|
|
|
63
67
|
redirectUri,
|
|
64
68
|
// PKCE
|
|
65
69
|
codeChallenge,
|
|
66
|
-
codeChallengeMethod
|
|
70
|
+
codeChallengeMethod,
|
|
71
|
+
// Magic Link
|
|
72
|
+
activationToken
|
|
67
73
|
}).then(interactionHandle => {
|
|
68
74
|
const newMeta = { ...meta,
|
|
69
75
|
interactionHandle,
|
package/cjs/idx/interact.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../lib/idx/interact.ts"],"names":["getResponse","meta","interactionHandle","state","interact","authClient","options","codeChallenge","codeChallengeMethod","clientId","redirectUri","scopes","baseUrl","idx","then","newMeta"],"mappings":";;;;;;AAYA;;AAEA;;AACA;;AAfA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;
|
|
1
|
+
{"version":3,"sources":["../../../lib/idx/interact.ts"],"names":["getResponse","meta","interactionHandle","state","interact","authClient","options","codeChallenge","codeChallengeMethod","clientId","redirectUri","scopes","activationToken","baseUrl","idx","then","newMeta"],"mappings":";;;;;;AAYA;;AAEA;;AACA;;AAfA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAmBA,SAASA,WAAT,CAAqBC,IAArB,EAAiE;AAC/D,SAAO;AACLA,IAAAA,IADK;AAELC,IAAAA,iBAAiB,EAAED,IAAI,CAACC,iBAFnB;AAGLC,IAAAA,KAAK,EAAEF,IAAI,CAACE;AAHP,GAAP;AAKD,C,CAED;;;AACO,eAAeC,QA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ApB,EAAgCW,OAAhC;AAEA,WAAOhB,WAAW,CAACgB,OAAD,CAAlB;AACD,GAzBM,CAAP;AA0BD","sourcesContent":["/*!\n * Copyright (c) 2021, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport idx from '@okta/okta-idx-js';\nimport { OktaAuth, IdxTransactionMeta } from '../types';\nimport { getTransactionMeta, saveTransactionMeta } from './transactionMeta';\nimport { getOAuthBaseUrl } from '../oidc';\n\nexport interface InteractOptions {\n state?: string;\n scopes?: string[];\n activationToken?: string;\n}\n\nexport interface InteractResponse {\n state?: string;\n interactionHandle: string;\n meta: IdxTransactionMeta;\n}\n\nfunction getResponse(meta: IdxTransactionMeta): InteractResponse {\n return {\n meta,\n interactionHandle: meta.interactionHandle,\n state: meta.state\n };\n}\n\n// Begin or resume a transaction. Returns an interaction handle\nexport async function interact (authClient: OktaAuth, options: InteractOptions = {}): Promise<InteractResponse> {\n let state = options.state || authClient.options.state;\n const meta = await getTransactionMeta(authClient, { state });\n\n // Saved transaction, return meta\n if (meta.interactionHandle) {\n return getResponse(meta);\n }\n\n // These properties are always loaded from meta (or calculated fresh)\n const { codeChallenge, codeChallengeMethod } = meta;\n\n // These properties are defined by global configuration\n const { clientId, redirectUri } = authClient.options;\n\n // These properties can be set in options, but also have a default value in global configuration.\n state = state || meta.state;\n const scopes = options.scopes || authClient.options.scopes || meta.scopes;\n\n // These properties can be set in options\n const { activationToken } = options;\n\n const baseUrl = getOAuthBaseUrl(authClient);\n return idx.interact({\n // OAuth\n clientId, \n baseUrl,\n scopes,\n state,\n redirectUri,\n\n // PKCE\n codeChallenge,\n codeChallengeMethod,\n \n // Magic Link\n activationToken\n }).then(interactionHandle => {\n const newMeta = {\n ...meta,\n interactionHandle,\n state,\n scopes\n };\n // Save transaction meta so it can be resumed\n saveTransactionMeta(authClient, newMeta);\n\n return getResponse(newMeta);\n });\n}\n"],"file":"interact.js"}
|
package/cjs/idx/poll.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.poll = poll;
|
|
4
|
+
|
|
5
|
+
var _proceed = require("./proceed");
|
|
6
|
+
|
|
7
|
+
var _transactionMeta = require("./transactionMeta");
|
|
8
|
+
|
|
9
|
+
var _util = require("../util");
|
|
10
|
+
|
|
11
|
+
/*!
|
|
12
|
+
* Copyright (c) 2021-present, Okta, Inc. and/or its affiliates. All rights reserved.
|
|
13
|
+
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
|
|
14
|
+
*
|
|
15
|
+
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
18
|
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
*
|
|
20
|
+
* See the License for the specific language governing permissions and limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
async function poll(authClient, options = {}) {
|
|
23
|
+
var _meta$remediations;
|
|
24
|
+
|
|
25
|
+
let transaction = await (0, _proceed.proceed)(authClient, {
|
|
26
|
+
startPolling: true
|
|
27
|
+
});
|
|
28
|
+
const meta = (0, _transactionMeta.getSavedTransactionMeta)(authClient);
|
|
29
|
+
let availablePollingRemeditaions = meta === null || meta === void 0 ? void 0 : (_meta$remediations = meta.remediations) === null || _meta$remediations === void 0 ? void 0 : _meta$remediations.find(remediation => remediation.includes('poll'));
|
|
30
|
+
|
|
31
|
+
if (!(availablePollingRemeditaions !== null && availablePollingRemeditaions !== void 0 && availablePollingRemeditaions.length)) {
|
|
32
|
+
(0, _util.warn)('No polling remediations available at the current IDX flow stage');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (Number.isInteger(options.refresh)) {
|
|
36
|
+
return new Promise(function (resolve, reject) {
|
|
37
|
+
setTimeout(async function () {
|
|
38
|
+
try {
|
|
39
|
+
var _transaction$nextStep, _transaction$nextStep2;
|
|
40
|
+
|
|
41
|
+
const refresh = (_transaction$nextStep = transaction.nextStep) === null || _transaction$nextStep === void 0 ? void 0 : (_transaction$nextStep2 = _transaction$nextStep.poll) === null || _transaction$nextStep2 === void 0 ? void 0 : _transaction$nextStep2.refresh;
|
|
42
|
+
|
|
43
|
+
if (refresh) {
|
|
44
|
+
resolve(poll(authClient, {
|
|
45
|
+
refresh
|
|
46
|
+
}));
|
|
47
|
+
} else {
|
|
48
|
+
resolve(transaction);
|
|
49
|
+
}
|
|
50
|
+
} catch (err) {
|
|
51
|
+
reject(err);
|
|
52
|
+
}
|
|
53
|
+
}, options.refresh);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return transaction;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=poll.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../lib/idx/poll.ts"],"names":["poll","authClient","options","transaction","startPolling","meta","availablePollingRemeditaions","remediations","find","remediation","includes","length","Number","isInteger","refresh","Promise","resolve","reject","setTimeout","nextStep","err"],"mappings":";;;;AAYA;;AAOA;;AACA;;AApBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAYO,eAAeA,IAAf,CAAoBC,UAApB,EAA0CC,OAAuB,GAAG,EAApE,EAAiG;AAAA;;AACtG,MAAIC,WAAW,GAAG,MAAM,sBAAQF,UAAR,EAAoB;AAC1CG,IAAAA,YAAY,EAAE;AAD4B,GAApB,CAAxB;AAIA,QAAMC,IAAI,GAAG,8CAAwBJ,UAAxB,CAAb;AACA,MAAIK,4BAA4B,GAAGD,IAAH,aAAGA,IAAH,6CAAGA,IAAI,CAAEE,YAAT,uDAAG,mBAAoBC,IAApB,CAAyBC,WAAW,IAAIA,WAAW,CAACC,QAAZ,CAAqB,MAArB,CAAxC,CAAnC;;AACA,MAAI,EAACJ,4BAAD,aAACA,4BAAD,eAACA,4BAA4B,CAAEK,MAA/B,CAAJ,EAA2C;AACzC,oBAAK,iEAAL;AACD;;AAED,MAAIC,MAAM,CAACC,SAAP,CAAiBX,OAAO,CAACY,OAAzB,CAAJ,EAAuC;AACrC,WAAO,IAAIC,OAAJ,CAAY,UAAUC,OAAV,EAAmBC,MAAnB,EAA2B;AAC5CC,MAAAA,UAAU,CAAC,kBAAkB;AAC3B,YAAI;AAAA;;AACF,gBAAMJ,OAAO,4BAAGX,WAAW,CAACgB,QAAf,oFAAG,sBAAsBnB,IAAzB,2DAAG,uBAA4Bc,OAA5C;;AACA,cAAIA,OAAJ,EAAa;AACXE,YAAAA,OAAO,CAAChB,IAAI,CAACC,UAAD,EAAa;AACvBa,cAAAA;AADuB,aAAb,CAAL,CAAP;AAGD,WAJD,MAIO;AACLE,YAAAA,OAAO,CAACb,WAAD,CAAP;AACD;AACF,SATD,CASE,OAAOiB,GAAP,EAAY;AACZH,UAAAA,MAAM,CAACG,GAAD,CAAN;AACD;AACF,OAbS,EAaPlB,OAAO,CAACY,OAbD,CAAV;AAcD,KAfM,CAAP;AAgBD;;AAED,SAAOX,WAAP;AACD","sourcesContent":["/*!\n * Copyright (c) 2021-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport { proceed } from './proceed';\n\nimport { \n IdxPollOptions,\n IdxTransaction,\n OktaAuth,\n} from '../types';\nimport { getSavedTransactionMeta } from './transactionMeta';\nimport { warn } from '../util';\n\nexport async function poll(authClient: OktaAuth, options: IdxPollOptions = {}): Promise<IdxTransaction> {\n let transaction = await proceed(authClient, {\n startPolling: true\n });\n\n const meta = getSavedTransactionMeta(authClient);\n let availablePollingRemeditaions = meta?.remediations?.find(remediation => remediation.includes('poll'));\n if (!availablePollingRemeditaions?.length) {\n warn('No polling remediations available at the current IDX flow stage');\n }\n\n if (Number.isInteger(options.refresh)) {\n return new Promise(function (resolve, reject) {\n setTimeout(async function () {\n try {\n const refresh = transaction.nextStep?.poll?.refresh;\n if (refresh) {\n resolve(poll(authClient, {\n refresh\n }));\n } else {\n resolve(transaction);\n }\n } catch (err) {\n reject(err);\n }\n }, options.refresh);\n });\n }\n\n return transaction;\n}\n"],"file":"poll.js"}
|
package/cjs/idx/proceed.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../lib/idx/proceed.ts"],"names":["canProceed","authClient","options","meta","proceed","stateTokenExternalId","state","AuthSdkError","flowSpec","flow"],"mappings":";;;;;AAiBA;;
|
|
1
|
+
{"version":3,"sources":["../../../lib/idx/proceed.ts"],"names":["canProceed","authClient","options","meta","proceed","stateTokenExternalId","state","AuthSdkError","flowSpec","flow"],"mappings":";;;;;AAiBA;;AAKA;;AACA;;AACA;;AAxBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAqBO,SAASA,UAAT,CAAoBC,UAApB,EAA0CC,OAA1C,EAAwE;AAC7E,QAAMC,IAAI,GAAG,8CAAwBF,UAAxB,EAAoCC,OAApC,CAAb;AACA,SAAO,CAAC,CAACC,IAAT;AACD;;AAEM,eAAeC,OAAf,CACLH,UADK,EAELC,OAAuB,GAAG,EAFrB,EAGoB;AACzB,QAAM;AAAEG,IAAAA,oBAAF;AAAwBC,IAAAA;AAAxB,MAAkCJ,OAAxC;AACA,QAAMC,IAAI,GAAG,8CAAwBF,UAAxB,EAAoC;AAAEK,IAAAA;AAAF,GAApC,CAAb,CAFyB,CAIzB;;AACA,MAAI,CAACH,IAAD,IAAS,CAACE,oBAAd,EAAoC;AAClC,UAAM,IAAIE,oBAAJ,CAAiB,0DAAjB,CAAN;AACD,GAPwB,CASzB;;;AACA,QAAMC,QAAQ,GAAG,gCAAqBP,UAArB,EAAiCE,IAAjC,aAAiCA,IAAjC,uBAAiCA,IAAI,CAAEM,IAAvC,CAAjB;AAEA,SAAO,cAAIR,UAAJ,EAAgB,EACrB,GAAGC,OADkB;AAErB,OAAGM;AAFkB,GAAhB,CAAP;AAID","sourcesContent":["/*!\n * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * \n * See the License for the specific language governing permissions and limitations under the License.\n */\n\n\nimport { \n OktaAuth,\n IdxTransaction,\n} from '../types';\nimport { run } from './run';\nimport { AuthenticationOptions } from './authenticate';\nimport { EnrollPollValues as EnrollPollOptions} from './remediators';\nimport { RegistrationOptions } from './register';\nimport { PasswordRecoveryOptions } from './recoverPassword';\nimport { getSavedTransactionMeta } from './transactionMeta';\nimport { getFlowSpecification } from './flow';\nimport { AuthSdkError } from '../errors';\n\nexport type ProceedOptions = AuthenticationOptions\n & RegistrationOptions\n & PasswordRecoveryOptions\n & EnrollPollOptions;\n\nexport function canProceed(authClient: OktaAuth, options?: { state?: string }) {\n const meta = getSavedTransactionMeta(authClient, options);\n return !!meta;\n}\n\nexport async function proceed(\n authClient: OktaAuth,\n options: ProceedOptions = {}\n): Promise<IdxTransaction> {\n const { stateTokenExternalId, state } = options;\n const meta = getSavedTransactionMeta(authClient, { state });\n\n // Proceed always needs saved transaction meta, except in the case of email verify callback\n if (!meta && !stateTokenExternalId) {\n throw new AuthSdkError('Unable to proceed: saved transaction could not be loaded');\n }\n\n // Determine the flow specification based on the saved flow\n const flowSpec = getFlowSpecification(authClient, meta?.flow);\n\n return run(authClient, { \n ...options, \n ...flowSpec\n });\n}\n"],"file":"proceed.js"}
|
package/cjs/idx/register.js
CHANGED
|
@@ -25,23 +25,34 @@ var _types = require("../types");
|
|
|
25
25
|
*
|
|
26
26
|
* See the License for the specific language governing permissions and limitations under the License.
|
|
27
27
|
*/
|
|
28
|
-
async function register(authClient, options) {
|
|
28
|
+
async function register(authClient, options = {}) {
|
|
29
29
|
// Only check at the beginning of the transaction
|
|
30
30
|
if (!(0, _transactionMeta.transactionMetaExist)(authClient)) {
|
|
31
31
|
const {
|
|
32
|
-
enabledFeatures
|
|
32
|
+
enabledFeatures,
|
|
33
|
+
availableSteps
|
|
33
34
|
} = await (0, _startTransaction.startTransaction)(authClient, {
|
|
34
35
|
flow: 'register',
|
|
35
36
|
...options
|
|
36
37
|
});
|
|
37
38
|
|
|
38
|
-
if (enabledFeatures && !enabledFeatures.includes(_types.IdxFeature.REGISTRATION)) {
|
|
39
|
+
if (!options.activationToken && enabledFeatures && !enabledFeatures.includes(_types.IdxFeature.REGISTRATION)) {
|
|
39
40
|
const error = new _errors.AuthSdkError('Registration is not supported based on your current org configuration.');
|
|
40
41
|
return {
|
|
41
42
|
status: _types.IdxStatus.FAILURE,
|
|
42
43
|
error
|
|
43
44
|
};
|
|
44
45
|
}
|
|
46
|
+
|
|
47
|
+
if (options.activationToken && availableSteps !== null && availableSteps !== void 0 && availableSteps.some(({
|
|
48
|
+
name
|
|
49
|
+
}) => name === 'identify')) {
|
|
50
|
+
const error = new _errors.AuthSdkError('activationToken is not supported based on your current org configuration.');
|
|
51
|
+
return {
|
|
52
|
+
status: _types.IdxStatus.FAILURE,
|
|
53
|
+
error
|
|
54
|
+
};
|
|
55
|
+
}
|
|
45
56
|
}
|
|
46
57
|
|
|
47
58
|
const flowSpec = (0, _flow.getFlowSpecification)(authClient, 'register');
|
package/cjs/idx/register.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../lib/idx/register.ts"],"names":["register","authClient","options","enabledFeatures","flow","includes","IdxFeature","REGISTRATION","error","AuthSdkError","status","IdxStatus","FAILURE","flowSpec"],"mappings":";;;;AAaA;;AACA;;AACA;;AAQA;;AACA;;AACA;;AAzBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AA8BO,eAAeA,QAAf,CACLC,UADK,EACiBC,
|
|
1
|
+
{"version":3,"sources":["../../../lib/idx/register.ts"],"names":["register","authClient","options","enabledFeatures","availableSteps","flow","activationToken","includes","IdxFeature","REGISTRATION","error","AuthSdkError","status","IdxStatus","FAILURE","some","name","flowSpec"],"mappings":";;;;AAaA;;AACA;;AACA;;AAQA;;AACA;;AACA;;AAzBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AA8BO,eAAeA,QAAf,CACLC,UADK,EACiBC,OAA4B,GAAG,EADhD,EAEoB;AACzB;AACA,MAAI,CAAC,2CAAqBD,UAArB,CAAL,EAAuC;AACrC,UAAM;AAAEE,MAAAA,eAAF;AAAmBC,MAAAA;AAAnB,QAAsC,MAAM,wCAAiBH,UAAjB,EAA6B;AAAEI,MAAAA,IAAI,EAAE,UAAR;AAAoB,SAAGH;AAAvB,KAA7B,CAAlD;;AACA,QAAI,CAACA,OAAO,CAACI,eAAT,IAA4BH,eAA5B,IAA+C,CAACA,eAAe,CAACI,QAAhB,CAAyBC,kBAAWC,YAApC,CAApD,EAAuG;AACrG,YAAMC,KAAK,GAAG,IAAIC,oBAAJ,CAAiB,wEAAjB,CAAd;AACA,aAAO;AAAEC,QAAAA,MAAM,EAAEC,iBAAUC,OAApB;AAA6BJ,QAAAA;AAA7B,OAAP;AACD;;AACD,QAAIR,OAAO,CAACI,eAAR,IAA2BF,cAA3B,aAA2BA,cAA3B,eAA2BA,cAAc,CAAEW,IAAhB,CAAqB,CAAC;AAAEC,MAAAA;AAAF,KAAD,KAAcA,IAAI,KAAK,UAA5C,CAA/B,EAAwF;AACtF,YAAMN,KAAK,GAAG,IAAIC,oBAAJ,CAAiB,2EAAjB,CAAd;AACA,aAAO;AAAEC,QAAAA,MAAM,EAAEC,iBAAUC,OAApB;AAA6BJ,QAAAA;AAA7B,OAAP;AACD;AACF;;AAED,QAAMO,QAAQ,GAAG,gCAAqBhB,UAArB,EAAiC,UAAjC,CAAjB;AACA,SAAO,cAAIA,UAAJ,EAAgB,EACrB,GAAGC,OADkB;AAErB,OAAGe;AAFkB,GAAhB,CAAP;AAID","sourcesContent":["/*!\n * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * \n * See the License for the specific language governing permissions and limitations under the License.\n */\n\n\nimport { run } from './run';\nimport { transactionMetaExist } from './transactionMeta';\nimport { startTransaction } from './startTransaction';\nimport { \n EnrollProfileValues,\n SelectAuthenticatorEnrollValues,\n EnrollAuthenticatorValues,\n AuthenticatorEnrollmentDataValues,\n SkipValues,\n} from './remediators';\nimport { getFlowSpecification } from './flow';\nimport { AuthSdkError } from '../errors';\nimport { \n IdxOptions, \n IdxTransaction, \n OktaAuth, \n IdxFeature,\n IdxStatus,\n} from '../types';\n\nexport type RegistrationOptions = IdxOptions \n & EnrollProfileValues \n & SelectAuthenticatorEnrollValues \n & EnrollAuthenticatorValues \n & AuthenticatorEnrollmentDataValues \n & SkipValues;\n\nexport async function register(\n authClient: OktaAuth, options: RegistrationOptions = {}\n): Promise<IdxTransaction> {\n // Only check at the beginning of the transaction\n if (!transactionMetaExist(authClient)) {\n const { enabledFeatures, availableSteps } = await startTransaction(authClient, { flow: 'register', ...options });\n if (!options.activationToken && enabledFeatures && !enabledFeatures.includes(IdxFeature.REGISTRATION)) {\n const error = new AuthSdkError('Registration is not supported based on your current org configuration.');\n return { status: IdxStatus.FAILURE, error };\n }\n if (options.activationToken && availableSteps?.some(({ name }) => name === 'identify')) {\n const error = new AuthSdkError('activationToken is not supported based on your current org configuration.');\n return { status: IdxStatus.FAILURE, error };\n }\n }\n\n const flowSpec = getFlowSpecification(authClient, 'register');\n return run(authClient, { \n ...options, \n ...flowSpec\n });\n}\n"],"file":"register.js"}
|
package/cjs/idx/remediate.js
CHANGED
|
@@ -5,6 +5,8 @@ exports.remediate = remediate;
|
|
|
5
5
|
|
|
6
6
|
var _errors = require("../errors");
|
|
7
7
|
|
|
8
|
+
var _remediators = require("./remediators");
|
|
9
|
+
|
|
8
10
|
var _idxJs = require("./types/idx-js");
|
|
9
11
|
|
|
10
12
|
/*!
|
|
@@ -23,8 +25,7 @@ var _idxJs = require("./types/idx-js");
|
|
|
23
25
|
// Return first match idxRemediation in allowed remediators
|
|
24
26
|
function getRemediator(idxRemediations, values, options) {
|
|
25
27
|
const {
|
|
26
|
-
remediators
|
|
27
|
-
flowMonitor
|
|
28
|
+
remediators
|
|
28
29
|
} = options;
|
|
29
30
|
let remediator;
|
|
30
31
|
const remediatorCandidates = [];
|
|
@@ -39,28 +40,15 @@ function getRemediator(idxRemediations, values, options) {
|
|
|
39
40
|
const T = remediators[remediation.name];
|
|
40
41
|
remediator = new T(remediation, values);
|
|
41
42
|
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
// maybe return for next step
|
|
48
|
-
|
|
43
|
+
if (remediator.canRemediate()) {
|
|
44
|
+
// found the remediator
|
|
45
|
+
return remediator;
|
|
46
|
+
} // remediator cannot handle the current values
|
|
47
|
+
// maybe return for next step
|
|
49
48
|
|
|
50
|
-
remediatorCandidates.push(remediator);
|
|
51
|
-
}
|
|
52
|
-
} // TODO: why is it a problem to have multiple remediations?
|
|
53
|
-
// JIRA: https://oktainc.atlassian.net/browse/OKTA-400758
|
|
54
|
-
// if (remediatorCandidates.length > 1) {
|
|
55
|
-
// const remediationNames = remediatorCandidates.reduce((acc, curr) => {
|
|
56
|
-
// const name = curr.getName();
|
|
57
|
-
// return acc ? `${acc}, ${name}` : name;
|
|
58
|
-
// }, '');
|
|
59
|
-
// throw new AuthSdkError(`
|
|
60
|
-
// More than one remediation can match the current input, remediations: ${remediationNames}
|
|
61
|
-
// `);
|
|
62
|
-
// }
|
|
63
49
|
|
|
50
|
+
remediatorCandidates.push(remediator);
|
|
51
|
+
}
|
|
64
52
|
|
|
65
53
|
return remediatorCandidates[0];
|
|
66
54
|
}
|
|
@@ -83,15 +71,10 @@ function canResendFn(idxResponse) {
|
|
|
83
71
|
return Object.keys(idxResponse.actions).some(actionName => actionName.includes('resend'));
|
|
84
72
|
}
|
|
85
73
|
|
|
86
|
-
function getIdxMessages(idxResponse
|
|
74
|
+
function getIdxMessages(idxResponse) {
|
|
87
75
|
var _rawIdxState$messages;
|
|
88
76
|
|
|
89
77
|
let messages = [];
|
|
90
|
-
|
|
91
|
-
if (!remediators) {
|
|
92
|
-
return messages;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
78
|
const {
|
|
96
79
|
rawIdxState,
|
|
97
80
|
neededToProceed
|
|
@@ -105,14 +88,7 @@ function getIdxMessages(idxResponse, remediators) {
|
|
|
105
88
|
|
|
106
89
|
|
|
107
90
|
for (let remediation of neededToProceed) {
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
if (!T) {
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const remediator = new T(remediation);
|
|
115
|
-
const fieldMessages = remediator.getMessages();
|
|
91
|
+
const fieldMessages = _remediators.Remediator.getMessages(remediation);
|
|
116
92
|
|
|
117
93
|
if (fieldMessages) {
|
|
118
94
|
messages = [...messages, ...fieldMessages];
|
|
@@ -123,7 +99,7 @@ function getIdxMessages(idxResponse, remediators) {
|
|
|
123
99
|
}
|
|
124
100
|
|
|
125
101
|
function getNextStep(remediator, idxResponse) {
|
|
126
|
-
const nextStep = remediator.getNextStep();
|
|
102
|
+
const nextStep = remediator.getNextStep(idxResponse.context);
|
|
127
103
|
const canSkip = canSkipFn(idxResponse);
|
|
128
104
|
const canResend = canResendFn(idxResponse);
|
|
129
105
|
return { ...nextStep,
|
|
@@ -136,7 +112,7 @@ function getNextStep(remediator, idxResponse) {
|
|
|
136
112
|
};
|
|
137
113
|
}
|
|
138
114
|
|
|
139
|
-
function handleIdxError(e,
|
|
115
|
+
function handleIdxError(e, remediator) {
|
|
140
116
|
// Handle idx messages
|
|
141
117
|
const idxState = (0, _idxJs.isIdxResponse)(e) ? e : null;
|
|
142
118
|
|
|
@@ -146,7 +122,7 @@ function handleIdxError(e, remediators, remediator) {
|
|
|
146
122
|
}
|
|
147
123
|
|
|
148
124
|
const terminal = isTerminalResponse(idxState);
|
|
149
|
-
const messages = getIdxMessages(idxState
|
|
125
|
+
const messages = getIdxMessages(idxState);
|
|
150
126
|
|
|
151
127
|
if (terminal) {
|
|
152
128
|
return {
|
|
@@ -182,8 +158,7 @@ async function remediate(idxResponse, values, options) {
|
|
|
182
158
|
interactionCode
|
|
183
159
|
} = idxResponse;
|
|
184
160
|
const {
|
|
185
|
-
remediators
|
|
186
|
-
flowMonitor
|
|
161
|
+
remediators
|
|
187
162
|
} = options; // If the response contains an interaction code, there is no need to remediate
|
|
188
163
|
|
|
189
164
|
if (interactionCode) {
|
|
@@ -194,13 +169,30 @@ async function remediate(idxResponse, values, options) {
|
|
|
194
169
|
|
|
195
170
|
|
|
196
171
|
const terminal = isTerminalResponse(idxResponse);
|
|
197
|
-
const messages = getIdxMessages(idxResponse
|
|
172
|
+
const messages = getIdxMessages(idxResponse);
|
|
198
173
|
|
|
199
174
|
if (terminal) {
|
|
200
175
|
return {
|
|
201
176
|
terminal,
|
|
202
177
|
messages
|
|
203
178
|
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const remediator = getRemediator(neededToProceed, values, options);
|
|
182
|
+
|
|
183
|
+
if (!remediator) {
|
|
184
|
+
throw new _errors.AuthSdkError(`
|
|
185
|
+
No remediation can match current flow, check policy settings in your org.
|
|
186
|
+
Remediations: [${neededToProceed.reduce((acc, curr) => acc ? acc + ' ,' + curr.name : curr.name, '')}]
|
|
187
|
+
`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (messages.length) {
|
|
191
|
+
const nextStep = getNextStep(remediator, idxResponse);
|
|
192
|
+
return {
|
|
193
|
+
nextStep,
|
|
194
|
+
messages
|
|
195
|
+
};
|
|
204
196
|
} // Try actions in idxResponse first
|
|
205
197
|
|
|
206
198
|
|
|
@@ -227,23 +219,7 @@ async function remediate(idxResponse, values, options) {
|
|
|
227
219
|
return remediate(idxResponse, valuesWithoutExecutedAction, options); // recursive call
|
|
228
220
|
}
|
|
229
221
|
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const remediator = getRemediator(neededToProceed, values, options);
|
|
233
|
-
|
|
234
|
-
if (!remediator) {
|
|
235
|
-
throw new _errors.AuthSdkError(`
|
|
236
|
-
No remediation can match current flow, check policy settings in your org.
|
|
237
|
-
Remediations: [${neededToProceed.reduce((acc, curr) => acc ? acc + ' ,' + curr.name : curr.name, '')}]
|
|
238
|
-
`);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
if (flowMonitor.loopDetected(remediator)) {
|
|
242
|
-
throw new _errors.AuthSdkError(`
|
|
243
|
-
Remediation run into loop, break!!! remediation: ${remediator.getName()}
|
|
244
|
-
`);
|
|
245
|
-
} // Recursive loop breaker
|
|
246
|
-
// Return next step to the caller
|
|
222
|
+
} // Return next step to the caller
|
|
247
223
|
|
|
248
224
|
|
|
249
225
|
if (!remediator.canRemediate()) {
|
|
@@ -258,42 +234,13 @@ async function remediate(idxResponse, values, options) {
|
|
|
258
234
|
const data = remediator.getData();
|
|
259
235
|
|
|
260
236
|
try {
|
|
261
|
-
idxResponse = await idxResponse.proceed(name, data); //
|
|
262
|
-
|
|
263
|
-
await flowMonitor.trackRemediations(name); // Successfully get interaction code
|
|
264
|
-
|
|
265
|
-
if (idxResponse.interactionCode) {
|
|
266
|
-
return {
|
|
267
|
-
idxResponse
|
|
268
|
-
};
|
|
269
|
-
} // Reach to terminal state
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
const terminal = isTerminalResponse(idxResponse);
|
|
273
|
-
const messages = getIdxMessages(idxResponse, remediators);
|
|
274
|
-
|
|
275
|
-
if (terminal) {
|
|
276
|
-
return {
|
|
277
|
-
terminal,
|
|
278
|
-
messages
|
|
279
|
-
};
|
|
280
|
-
} // Handle idx message in nextStep
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
if (messages.length) {
|
|
284
|
-
const nextStep = getNextStep(remediator, idxResponse);
|
|
285
|
-
return {
|
|
286
|
-
nextStep,
|
|
287
|
-
messages
|
|
288
|
-
};
|
|
289
|
-
} // We may want to trim the values bag for the next remediation
|
|
237
|
+
idxResponse = await idxResponse.proceed(name, data); // We may want to trim the values bag for the next remediation
|
|
290
238
|
// Let the remediator decide what the values should be (default to current values)
|
|
291
239
|
|
|
292
|
-
|
|
293
240
|
values = remediator.getValuesAfterProceed();
|
|
294
241
|
return remediate(idxResponse, values, options); // recursive call
|
|
295
242
|
} catch (e) {
|
|
296
|
-
return handleIdxError(e,
|
|
243
|
+
return handleIdxError(e, remediator);
|
|
297
244
|
}
|
|
298
245
|
}
|
|
299
246
|
//# sourceMappingURL=remediate.js.map
|
package/cjs/idx/remediate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../lib/idx/remediate.ts"],"names":["getRemediator","idxRemediations","values","options","remediators","flowMonitor","remediator","remediatorCandidates","remediation","isRemeditionInFlow","Object","keys","includes","name","T","isRemediatorCandidate","canRemediate","push","isTerminalResponse","idxResponse","neededToProceed","interactionCode","length","canSkipFn","some","canResendFn","actions","actionName","getIdxMessages","messages","rawIdxState","globalMessages","value","map","message","fieldMessages","getMessages","getNextStep","nextStep","canSkip","canResend","handleIdxError","e","idxState","terminal","getActionFromValues","find","action","resend","removeActionFromValues","undefined","remediate","actionFromValues","valuesWithoutExecutedAction","canceled","AuthSdkError","reduce","acc","curr","loopDetected","getName","data","getData","proceed","trackRemediations","getValuesAfterProceed"],"mappings":";;;;;AAcA;;AAKA;;AAnBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AAmBA;AACO,SAASA,aAAT,CACLC,eADK,EAELC,MAFK,EAGLC,OAHK,EAIO;AACZ,QAAM;AAAEC,IAAAA,WAAF;AAAeC,IAAAA;AAAf,MAA+BF,OAArC;AAEA,MAAIG,UAAJ;AACA,QAAMC,oBAAoB,GAAG,EAA7B;;AACA,OAAK,IAAIC,WAAT,IAAwBP,eAAxB,EAAyC;AACvC,UAAMQ,kBAAkB,GAAGC,MAAM,CAACC,IAAP,CAAYP,WAAZ,EAAyBQ,QAAzB,CAAkCJ,WAAW,CAACK,IAA9C,CAA3B;;AACA,QAAI,CAACJ,kBAAL,EAAyB;AACvB;AACD;;AAED,UAAMK,CAAC,GAAGV,WAAW,CAACI,WAAW,CAACK,IAAb,CAArB;AACAP,IAAAA,UAAU,GAAG,IAAIQ,CAAJ,CAAMN,WAAN,EAAmBN,MAAnB,CAAb;;AACA,QAAIG,WAAW,CAACU,qBAAZ,CAAkCT,UAAlC,EAA8CL,eAA9C,EAA+DC,MAA/D,CAAJ,EAA4E;AAC1E,UAAII,UAAU,CAACU,YAAX,EAAJ,EAA+B;AAC7B;AACA,eAAOV,UAAP;AACD,OAJyE,CAK1E;AACA;;;AACAC,MAAAA,oBAAoB,CAACU,IAArB,CAA0BX,UAA1B;AACD;A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,EAAaa,WAAb,CAA5B;AACA,WAAO;AAAEA,MAAAA,WAAF;AAAemB,MAAAA;AAAf,KAAP;AACD;;AAED,QAAMzB,IAAI,GAAGP,UAAU,CAACsD,OAAX,EAAb;AACA,QAAMC,IAAI,GAAGvD,UAAU,CAACwD,OAAX,EAAb;;AACA,MAAI;AACF3C,IAAAA,WAAW,GAAG,MAAMA,WAAW,CAAC4C,OAAZ,CAAoBlD,IAApB,EAA0BgD,IAA1B,CAApB,CADE,CAGF;;AACA,UAAMxD,WAAW,CAAC2D,iBAAZ,CAA8BnD,IAA9B,CAAN,CAJE,CAMF;;AACA,QAAIM,WAAW,CAACE,eAAhB,EAAiC;AAC/B,aAAO;AAAEF,QAAAA;AAAF,OAAP;AACD,KATC,CAWF;;;AACA,UAAMyB,QAAQ,GAAG1B,kBAAkB,CAACC,WAAD,CAAnC;AACA,UAAMU,QAAQ,GAAGD,cAAc,CAACT,WAAD,EAAcf,WAAd,CAA/B;;AACA,QAAIwC,QAAJ,EAAc;AACZ,aAAO;AAAEA,QAAAA,QAAF;AAAYf,QAAAA;AAAZ,OAAP;AACD,KAhBC,CAkBF;;;AACA,QAAIA,QAAQ,CAACP,MAAb,EAAqB;AACnB,YAAMgB,QAAQ,GAAGD,WAAW,CAAC/B,UAAD,EAAaa,WAAb,CAA5B;AACA,aAAO;AAAEmB,QAAAA,QAAF;AAAYT,QAAAA;AAAZ,OAAP;AACD,KAtBC,CAwBF;AACA;;;AACA3B,IAAAA,MAAM,GAAGI,UAAU,CAAC2D,qBAAX,EAAT;AACA,WAAOd,SAAS,CAAChC,WAAD,EAAcjB,MAAd,EAAsBC,OAAtB,CAAhB,CA3BE,CA2B8C;AACjD,GA5BD,CA4BE,OAAOuC,CAAP,EAAU;AACV,WAAOD,cAAc,CAACC,CAAD,EAAItC,WAAJ,EAAiBE,UAAjB,CAArB;AACD;AACF","sourcesContent":["/*!\n * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * \n * See the License for the specific language governing permissions and limitations under the License.\n */\n\n\n/* eslint-disable max-statements, max-depth, complexity */\nimport { AuthSdkError } from '../errors';\nimport { Remediator, RemediationValues } from './remediators';\nimport { RemediationFlow } from './flow';\nimport { RunOptions } from './run';\nimport { NextStep, IdxMessage } from './types';\nimport { \n IdxResponse, \n IdxRemediation,\n isIdxResponse, \n} from './types/idx-js';\n\ninterface RemediationResponse {\n idxResponse?: IdxResponse;\n nextStep?: NextStep;\n messages?: IdxMessage[];\n terminal?: boolean;\n canceled?: boolean;\n}\n// Return first match idxRemediation in allowed remediators\nexport function getRemediator(\n idxRemediations: IdxRemediation[],\n values: RemediationValues,\n options: RunOptions,\n): Remediator {\n const { remediators, flowMonitor } = options;\n\n let remediator;\n const remediatorCandidates = [];\n for (let remediation of idxRemediations) {\n const isRemeditionInFlow = Object.keys(remediators).includes(remediation.name);\n if (!isRemeditionInFlow) {\n continue;\n }\n \n const T = remediators[remediation.name];\n remediator = new T(remediation, values);\n if (flowMonitor.isRemediatorCandidate(remediator, idxRemediations, values)) {\n if (remediator.canRemediate()) {\n // found the remediator\n return remediator;\n }\n // remediator cannot handle the current values\n // maybe return for next step\n remediatorCandidates.push(remediator); \n }\n }\n \n // TODO: why is it a problem to have multiple remediations? \n // JIRA: https://oktainc.atlassian.net/browse/OKTA-400758\n // if (remediatorCandidates.length > 1) {\n // const remediationNames = remediatorCandidates.reduce((acc, curr) => {\n // const name = curr.getName();\n // return acc ? `${acc}, ${name}` : name;\n // }, '');\n // throw new AuthSdkError(`\n // More than one remediation can match the current input, remediations: ${remediationNames}\n // `);\n // }\n\n return remediatorCandidates[0];\n}\n\nfunction isTerminalResponse(idxResponse: IdxResponse) {\n const { neededToProceed, interactionCode } = idxResponse;\n return !neededToProceed.length && !interactionCode;\n}\n\nfunction canSkipFn(idxResponse: IdxResponse) {\n return idxResponse.neededToProceed.some(({ name }) => name === 'skip');\n}\n\nfunction canResendFn(idxResponse: IdxResponse) {\n return Object.keys(idxResponse.actions).some(actionName => actionName.includes('resend'));\n}\n\nfunction getIdxMessages(\n idxResponse: IdxResponse, remediators: RemediationFlow\n): IdxMessage[] {\n let messages = [];\n if (!remediators) {\n return messages;\n }\n\n const { rawIdxState, neededToProceed } = idxResponse;\n\n // Handle global messages\n const globalMessages = rawIdxState.messages?.value.map(message => message);\n if (globalMessages) {\n messages = [...messages, ...globalMessages];\n }\n\n // Handle field messages for current flow\n for (let remediation of neededToProceed) {\n const T = remediators[remediation.name];\n if (!T) {\n continue;\n }\n const remediator = new T(remediation);\n const fieldMessages = remediator.getMessages();\n if (fieldMessages) {\n messages = [...messages, ...fieldMessages];\n }\n }\n\n return messages;\n}\n\nfunction getNextStep(\n remediator: Remediator, idxResponse: IdxResponse\n): NextStep {\n const nextStep = remediator.getNextStep();\n const canSkip = canSkipFn(idxResponse);\n const canResend = canResendFn(idxResponse);\n return {\n ...nextStep,\n ...(canSkip && {canSkip}),\n ...(canResend && {canResend}),\n };\n}\n\nfunction handleIdxError(e, remediators, remediator?) {\n // Handle idx messages\n const idxState: IdxResponse = isIdxResponse(e) ? e : null;\n if (!idxState) {\n // Thrown error terminates the interaction with idx\n throw e;\n }\n const terminal = isTerminalResponse(idxState);\n const messages = getIdxMessages(idxState, remediators);\n if (terminal) {\n return { terminal, messages };\n } else {\n const nextStep = remediator && getNextStep(remediator, idxState);\n return { \n messages, \n ...(nextStep && { nextStep }) \n };\n }\n}\n\nfunction getActionFromValues(values, idxResponse: IdxResponse): string | undefined {\n // Currently support resend actions only\n return Object.keys(idxResponse.actions).find(action => !!values.resend && action.includes('-resend'));\n}\n\nfunction removeActionFromValues(values) {\n // Currently support resend actions only\n values.resend = undefined;\n return values;\n}\n\n// This function is called recursively until it reaches success or cannot be remediated\nexport async function remediate(\n idxResponse: IdxResponse,\n values: RemediationValues,\n options: RunOptions\n): Promise<RemediationResponse> {\n let { neededToProceed, interactionCode } = idxResponse;\n const { remediators, flowMonitor } = options;\n\n // If the response contains an interaction code, there is no need to remediate\n if (interactionCode) {\n return { idxResponse };\n }\n\n // Reach to terminal state\n const terminal = isTerminalResponse(idxResponse);\n const messages = getIdxMessages(idxResponse, remediators);\n if (terminal) {\n return { terminal, messages };\n }\n \n // Try actions in idxResponse first\n const actionFromValues = getActionFromValues(values, idxResponse);\n const actions = [\n ...options.actions || [],\n ...(actionFromValues && [actionFromValues] || []),\n ];\n if (actions) {\n for (let action of actions) {\n let valuesWithoutExecutedAction = removeActionFromValues(values);\n if (typeof idxResponse.actions[action] === 'function') {\n try {\n idxResponse = await idxResponse.actions[action]();\n } catch (e) {\n return handleIdxError(e, remediators);\n }\n if (action === 'cancel') {\n return { canceled: true };\n }\n return remediate(idxResponse, valuesWithoutExecutedAction, options); // recursive call\n }\n }\n }\n\n const remediator = getRemediator(neededToProceed, values, options);\n \n if (!remediator) {\n throw new AuthSdkError(`\n No remediation can match current flow, check policy settings in your org.\n Remediations: [${neededToProceed.reduce((acc, curr) => acc ? acc + ' ,' + curr.name : curr.name, '')}]\n `);\n }\n\n if (flowMonitor.loopDetected(remediator)) {\n throw new AuthSdkError(`\n Remediation run into loop, break!!! remediation: ${remediator.getName()}\n `);\n }\n\n // Recursive loop breaker\n // Return next step to the caller\n if (!remediator.canRemediate()) {\n const nextStep = getNextStep(remediator, idxResponse);\n return { idxResponse, nextStep };\n }\n\n const name = remediator.getName();\n const data = remediator.getData();\n try {\n idxResponse = await idxResponse.proceed(name, data);\n\n // Track succeed remediations in the current transaction\n await flowMonitor.trackRemediations(name);\n \n // Successfully get interaction code\n if (idxResponse.interactionCode) {\n return { idxResponse };\n }\n\n // Reach to terminal state\n const terminal = isTerminalResponse(idxResponse);\n const messages = getIdxMessages(idxResponse, remediators);\n if (terminal) {\n return { terminal, messages };\n }\n\n // Handle idx message in nextStep\n if (messages.length) {\n const nextStep = getNextStep(remediator, idxResponse);\n return { nextStep, messages };\n }\n \n // We may want to trim the values bag for the next remediation\n // Let the remediator decide what the values should be (default to current values)\n values = remediator.getValuesAfterProceed();\n return remediate(idxResponse, values, options); // recursive call\n } catch (e) {\n return handleIdxError(e, remediators, remediator);\n }\n}\n"],"file":"remediate.js"}
|
|
1
|
+
{"version":3,"sources":["../../../lib/idx/remediate.ts"],"names":["getRemediator","idxRemediations","values","options","remediators","remediator","remediatorCandidates","remediation","isRemeditionInFlow","Object","keys","includes","name","T","canRemediate","push","isTerminalResponse","idxResponse","neededToProceed","interactionCode","length","canSkipFn","some","canResendFn","actions","actionName","getIdxMessages","messages","rawIdxState","globalMessages","value","map","message","fieldMessages","Remediator","getMessages","getNextStep","nextStep","context","canSkip","canResend","handleIdxError","e","idxState","terminal","getActionFromValues","find","action","resend","removeActionFromValues","undefined","remediate","AuthSdkError","reduce","acc","curr","actionFromValues","valuesWithoutExecutedAction","canceled","getName","data","getData","proceed","getValuesAfterProceed"],"mappings":";;;;;AAcA;;AACA;;AAGA;;AAlBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AAkBA;AACO,SAASA,aAAT,CACLC,eADK,EAELC,MAFK,EAGLC,OAHK,EAIO;AACZ,QAAM;AAAEC,IAAAA;AAAF,MAAkBD,OAAxB;AAEA,MAAIE,UAAJ;AACA,QAAMC,oBAAoB,GAAG,EAA7B;;AACA,OAAK,IAAIC,WAAT,IAAwBN,eAAxB,EAAyC;AACvC,UAAMO,kBAAkB,GAAGC,MAAM,CAACC,IAAP,CAAYN,WAAZ,EAAyBO,QAAzB,CAAkCJ,WAAW,CAACK,IAA9C,CAA3B;;AACA,QAAI,CAACJ,kBAAL,EAAyB;AACvB;AACD;;AAED,UAAMK,CAAC,GAAGT,WAAW,CAACG,WAAW,CAACK,IAAb,C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ED,QAAMzB,IAAI,GAAGP,UAAU,CAACsD,OAAX,EAAb;AACA,QAAMC,IAAI,GAAGvD,UAAU,CAACwD,OAAX,EAAb;;AACA,MAAI;AACF5C,IAAAA,WAAW,GAAG,MAAMA,WAAW,CAAC6C,OAAZ,CAAoBlD,IAApB,EAA0BgD,IAA1B,CAApB,CADE,CAGF;AACA;;AACA1D,IAAAA,MAAM,GAAGG,UAAU,CAAC0D,qBAAX,EAAT;AACA,WAAOZ,SAAS,CAAClC,WAAD,EAAcf,MAAd,EAAsBC,OAAtB,CAAhB,CANE,CAM8C;AACjD,GAPD,CAOE,OAAOuC,CAAP,EAAU;AACV,WAAOD,cAAc,CAACC,CAAD,EAAIrC,UAAJ,CAArB;AACD;AACF","sourcesContent":["/*!\n * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * \n * See the License for the specific language governing permissions and limitations under the License.\n */\n\n\n/* eslint-disable max-statements, max-depth, complexity */\nimport { AuthSdkError } from '../errors';\nimport { Remediator, RemediationValues } from './remediators';\nimport { RunOptions } from './run';\nimport { NextStep, IdxMessage } from './types';\nimport { \n IdxResponse, \n IdxRemediation,\n isIdxResponse, \n} from './types/idx-js';\n\ninterface RemediationResponse {\n idxResponse?: IdxResponse;\n nextStep?: NextStep;\n messages?: IdxMessage[];\n terminal?: boolean;\n canceled?: boolean;\n}\n// Return first match idxRemediation in allowed remediators\nexport function getRemediator(\n idxRemediations: IdxRemediation[],\n values: RemediationValues,\n options: RunOptions,\n): Remediator {\n const { remediators } = options;\n\n let remediator;\n const remediatorCandidates = [];\n for (let remediation of idxRemediations) {\n const isRemeditionInFlow = Object.keys(remediators).includes(remediation.name);\n if (!isRemeditionInFlow) {\n continue;\n }\n\n const T = remediators[remediation.name];\n remediator = new T(remediation, values);\n if (remediator.canRemediate()) {\n // found the remediator\n return remediator;\n }\n // remediator cannot handle the current values\n // maybe return for next step\n remediatorCandidates.push(remediator); \n }\n \n return remediatorCandidates[0];\n}\n\nfunction isTerminalResponse(idxResponse: IdxResponse) {\n const { neededToProceed, interactionCode } = idxResponse;\n return !neededToProceed.length && !interactionCode;\n}\n\nfunction canSkipFn(idxResponse: IdxResponse) {\n return idxResponse.neededToProceed.some(({ name }) => name === 'skip');\n}\n\nfunction canResendFn(idxResponse: IdxResponse) {\n return Object.keys(idxResponse.actions).some(actionName => actionName.includes('resend'));\n}\n\nfunction getIdxMessages(idxResponse: IdxResponse): IdxMessage[] {\n let messages = [];\n const { rawIdxState, neededToProceed } = idxResponse;\n\n // Handle global messages\n const globalMessages = rawIdxState.messages?.value.map(message => message);\n if (globalMessages) {\n messages = [...messages, ...globalMessages];\n }\n\n // Handle field messages for current flow\n for (let remediation of neededToProceed) {\n const fieldMessages = Remediator.getMessages(remediation);\n if (fieldMessages) {\n messages = [...messages, ...fieldMessages];\n }\n }\n\n return messages;\n}\n\nfunction getNextStep(\n remediator: Remediator, idxResponse: IdxResponse\n): NextStep {\n const nextStep = remediator.getNextStep(idxResponse.context);\n const canSkip = canSkipFn(idxResponse);\n const canResend = canResendFn(idxResponse);\n return {\n ...nextStep,\n ...(canSkip && {canSkip}),\n ...(canResend && {canResend}),\n };\n}\n\nfunction handleIdxError(e, remediator?) {\n // Handle idx messages\n const idxState: IdxResponse = isIdxResponse(e) ? e : null;\n if (!idxState) {\n // Thrown error terminates the interaction with idx\n throw e;\n }\n const terminal = isTerminalResponse(idxState);\n const messages = getIdxMessages(idxState);\n if (terminal) {\n return { terminal, messages };\n } else {\n const nextStep = remediator && getNextStep(remediator, idxState);\n return { \n messages, \n ...(nextStep && { nextStep }) \n };\n }\n}\n\nfunction getActionFromValues(values, idxResponse: IdxResponse): string | undefined {\n // Currently support resend actions only\n return Object.keys(idxResponse.actions).find(action => !!values.resend && action.includes('-resend'));\n}\n\nfunction removeActionFromValues(values) {\n // Currently support resend actions only\n values.resend = undefined;\n return values;\n}\n\n// This function is called recursively until it reaches success or cannot be remediated\nexport async function remediate(\n idxResponse: IdxResponse,\n values: RemediationValues,\n options: RunOptions\n): Promise<RemediationResponse> {\n let { neededToProceed, interactionCode } = idxResponse;\n const { remediators } = options;\n\n // If the response contains an interaction code, there is no need to remediate\n if (interactionCode) {\n return { idxResponse };\n }\n\n // Reach to terminal state\n const terminal = isTerminalResponse(idxResponse);\n const messages = getIdxMessages(idxResponse);\n if (terminal) {\n return { terminal, messages };\n }\n\n const remediator = getRemediator(neededToProceed, values, options);\n \n if (!remediator) {\n throw new AuthSdkError(`\n No remediation can match current flow, check policy settings in your org.\n Remediations: [${neededToProceed.reduce((acc, curr) => acc ? acc + ' ,' + curr.name : curr.name, '')}]\n `);\n }\n\n if (messages.length) {\n const nextStep = getNextStep(remediator, idxResponse);\n return { nextStep, messages };\n }\n \n // Try actions in idxResponse first\n const actionFromValues = getActionFromValues(values, idxResponse);\n const actions = [\n ...options.actions || [],\n ...(actionFromValues && [actionFromValues] || []),\n ];\n if (actions) {\n for (let action of actions) {\n let valuesWithoutExecutedAction = removeActionFromValues(values);\n if (typeof idxResponse.actions[action] === 'function') {\n try {\n idxResponse = await idxResponse.actions[action]();\n } catch (e) {\n return handleIdxError(e, remediators);\n }\n if (action === 'cancel') {\n return { canceled: true };\n }\n return remediate(idxResponse, valuesWithoutExecutedAction, options); // recursive call\n }\n }\n }\n\n // Return next step to the caller\n if (!remediator.canRemediate()) {\n const nextStep = getNextStep(remediator, idxResponse);\n return { idxResponse, nextStep };\n }\n\n const name = remediator.getName();\n const data = remediator.getData();\n try {\n idxResponse = await idxResponse.proceed(name, data);\n\n // We may want to trim the values bag for the next remediation\n // Let the remediator decide what the values should be (default to current values)\n values = remediator.getValuesAfterProceed();\n return remediate(idxResponse, values, options); // recursive call\n } catch (e) {\n return handleIdxError(e, remediator);\n }\n}\n"],"file":"remediate.js"}
|