@okta/okta-auth-js 6.1.0 → 6.2.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 +24 -0
- package/README.md +53 -23
- package/cjs/AuthStateManager.js +5 -4
- package/cjs/AuthStateManager.js.map +1 -1
- package/cjs/OktaAuth.js +30 -14
- package/cjs/OktaAuth.js.map +1 -1
- package/cjs/OktaUserAgent.js +2 -2
- package/cjs/ServiceManager.js +195 -0
- package/cjs/ServiceManager.js.map +1 -0
- package/cjs/TokenManager.js +6 -14
- package/cjs/TokenManager.js.map +1 -1
- package/cjs/browser/browserStorage.js +12 -7
- package/cjs/browser/browserStorage.js.map +1 -1
- package/cjs/crypto/node.js +19 -13
- package/cjs/crypto/node.js.map +1 -1
- package/cjs/idx/remediators/AuthenticatorVerificationData.js +44 -7
- package/cjs/idx/remediators/AuthenticatorVerificationData.js.map +1 -1
- package/cjs/idx/remediators/Base/AuthenticatorData.js.map +1 -1
- package/cjs/idx/run.js +6 -0
- package/cjs/idx/run.js.map +1 -1
- package/cjs/options/browser.js +81 -0
- package/cjs/options/browser.js.map +1 -0
- package/cjs/{options.js → options/index.js} +12 -78
- package/cjs/options/index.js.map +1 -0
- package/cjs/options/node.js +46 -0
- package/cjs/options/node.js.map +1 -0
- package/cjs/server/serverStorage.js +7 -4
- package/cjs/server/serverStorage.js.map +1 -1
- package/cjs/services/AutoRenewService.js +94 -0
- package/cjs/services/AutoRenewService.js.map +1 -0
- package/cjs/services/SyncStorageService.js +93 -0
- package/cjs/services/SyncStorageService.js.map +1 -0
- package/cjs/services/index.js +30 -0
- package/cjs/services/index.js.map +1 -0
- package/cjs/types/Service.js +2 -0
- package/cjs/types/Service.js.map +1 -0
- package/cjs/types/index.js +13 -0
- package/cjs/types/index.js.map +1 -1
- package/dist/okta-auth-js.min.js +1 -1
- package/dist/okta-auth-js.min.js.LICENSE.txt +0 -8
- 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.LICENSE.txt +1 -7
- package/dist/okta-auth-js.umd.js.map +1 -1
- package/esm/{index.js → esm.browser.js} +1184 -2399
- package/esm/esm.browser.js.map +1 -0
- package/esm/esm.node.mjs +9277 -0
- package/esm/esm.node.mjs.map +1 -0
- package/lib/AuthStateManager.d.ts +1 -3
- package/lib/OktaAuth.d.ts +5 -4
- package/lib/ServiceManager.d.ts +38 -0
- package/lib/TokenManager.d.ts +0 -1
- package/lib/idx/remediators/AuthenticatorVerificationData.d.ts +5 -5
- package/lib/idx/remediators/Base/AuthenticatorData.d.ts +5 -6
- package/lib/options/browser.d.ts +16 -0
- package/lib/{options.d.ts → options/index.d.ts} +1 -1
- package/lib/options/node.d.ts +16 -0
- package/lib/services/AutoRenewService.d.ts +27 -0
- package/lib/services/{TokenService.d.ts → SyncStorageService.d.ts} +8 -5
- package/lib/services/index.d.ts +13 -0
- package/lib/types/OktaAuthOptions.d.ts +5 -0
- package/lib/types/Service.d.ts +23 -0
- package/lib/types/api.d.ts +5 -2
- package/lib/types/index.d.ts +1 -0
- package/package.json +24 -10
- package/cjs/options.js.map +0 -1
- package/cjs/services/TokenService.js +0 -111
- package/cjs/services/TokenService.js.map +0 -1
- package/esm/index.js.map +0 -1
|
@@ -4,10 +4,14 @@ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequ
|
|
|
4
4
|
|
|
5
5
|
exports.AuthenticatorVerificationData = void 0;
|
|
6
6
|
|
|
7
|
+
var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/reduce"));
|
|
8
|
+
|
|
7
9
|
var _find = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/find"));
|
|
8
10
|
|
|
9
11
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
10
12
|
|
|
13
|
+
var _errors = require("../../errors");
|
|
14
|
+
|
|
11
15
|
var _AuthenticatorData = require("./Base/AuthenticatorData");
|
|
12
16
|
|
|
13
17
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
@@ -24,27 +28,60 @@ var _AuthenticatorData = require("./Base/AuthenticatorData");
|
|
|
24
28
|
* See the License for the specific language governing permissions and limitations under the License.
|
|
25
29
|
*/
|
|
26
30
|
class AuthenticatorVerificationData extends _AuthenticatorData.AuthenticatorData {
|
|
31
|
+
constructor(remediation, values = {}) {
|
|
32
|
+
super(remediation, values); // TODO: extend this feature to all authenticators
|
|
33
|
+
|
|
34
|
+
this.shouldProceedWithEmailAuthenticator = this.authenticator.methods.length === 1 && this.authenticator.methods[0].type === 'email';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
canRemediate() {
|
|
38
|
+
// auto proceed if there is only one method
|
|
39
|
+
if (this.shouldProceedWithEmailAuthenticator) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return super.canRemediate();
|
|
44
|
+
}
|
|
45
|
+
|
|
27
46
|
mapAuthenticator() {
|
|
28
|
-
var
|
|
47
|
+
var _context2, _value$find, _context3;
|
|
29
48
|
|
|
30
49
|
const authenticatorData = this.getAuthenticatorData();
|
|
31
|
-
const authenticatorFromRemediation = this.getAuthenticatorFromRemediation();
|
|
50
|
+
const authenticatorFromRemediation = this.getAuthenticatorFromRemediation(); // auto proceed with the only methodType option
|
|
51
|
+
|
|
52
|
+
if (this.shouldProceedWithEmailAuthenticator) {
|
|
53
|
+
var _authenticatorFromRem, _context;
|
|
54
|
+
|
|
55
|
+
return (_authenticatorFromRem = authenticatorFromRemediation.form) === null || _authenticatorFromRem === void 0 ? void 0 : (0, _reduce.default)(_context = _authenticatorFromRem.value).call(_context, (acc, curr) => {
|
|
56
|
+
if (curr.value) {
|
|
57
|
+
acc[curr.name] = curr.value;
|
|
58
|
+
} else if (curr.options) {
|
|
59
|
+
acc[curr.name] = curr.options[0].value;
|
|
60
|
+
} else {
|
|
61
|
+
throw new _errors.AuthSdkError(`Unsupported authenticator data type: ${curr}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return acc;
|
|
65
|
+
}, {});
|
|
66
|
+
} // return based on user selection
|
|
67
|
+
|
|
68
|
+
|
|
32
69
|
return {
|
|
33
|
-
id: (0, _find.default)(
|
|
70
|
+
id: (0, _find.default)(_context2 = authenticatorFromRemediation.form.value).call(_context2, ({
|
|
34
71
|
name
|
|
35
72
|
}) => name === 'id').value,
|
|
36
|
-
enrollmentId: (_value$find = (0, _find.default)(
|
|
73
|
+
enrollmentId: (_value$find = (0, _find.default)(_context3 = authenticatorFromRemediation.form.value).call(_context3, ({
|
|
37
74
|
name
|
|
38
75
|
}) => name === 'enrollmentId')) === null || _value$find === void 0 ? void 0 : _value$find.value,
|
|
39
|
-
methodType: authenticatorData.methodType
|
|
76
|
+
methodType: authenticatorData === null || authenticatorData === void 0 ? void 0 : authenticatorData.methodType
|
|
40
77
|
};
|
|
41
78
|
}
|
|
42
79
|
|
|
43
80
|
getInputAuthenticator() {
|
|
44
|
-
var
|
|
81
|
+
var _context4;
|
|
45
82
|
|
|
46
83
|
const authenticator = this.getAuthenticatorFromRemediation();
|
|
47
|
-
const methodType = (0, _find.default)(
|
|
84
|
+
const methodType = (0, _find.default)(_context4 = authenticator.form.value).call(_context4, ({
|
|
48
85
|
name
|
|
49
86
|
}) => name === 'methodType'); // if has methodType in form, let user select the methodType
|
|
50
87
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../lib/idx/remediators/AuthenticatorVerificationData.ts"],"names":["AuthenticatorVerificationData","AuthenticatorData","mapAuthenticator","authenticatorData","getAuthenticatorData","authenticatorFromRemediation","getAuthenticatorFromRemediation","
|
|
1
|
+
{"version":3,"sources":["../../../../lib/idx/remediators/AuthenticatorVerificationData.ts"],"names":["AuthenticatorVerificationData","AuthenticatorData","constructor","remediation","values","shouldProceedWithEmailAuthenticator","authenticator","methods","length","type","canRemediate","mapAuthenticator","authenticatorData","getAuthenticatorData","authenticatorFromRemediation","getAuthenticatorFromRemediation","form","value","acc","curr","name","options","AuthSdkError","id","enrollmentId","methodType","getInputAuthenticator","required","inputs"],"mappings":";;;;;;;;;;;;AAcA;;AACA;;AAfA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AASO,MAAMA,6BAAN,SAA4CC,oCAA5C,CAA8D;AAMnEC,EAAAA,WAAW,CAACC,WAAD,EAA8BC,MAA+B,GAAG,EAAhE,EAAoE;AAC7E,UAAMD,WAAN,EAAmBC,MAAnB,EAD6E,CAG7E;;AACA,SAAKC,mCAAL,GAA2C,KAAKC,aAAL,CAAmBC,OAAnB,CAA2BC,MAA3B,KAAsC,CAAtC,IACtC,KAAKF,aAAL,CAAmBC,OAAnB,CAA2B,CAA3B,EAA8BE,IAA9B,KAAuC,OAD5C;AAED;;AAEDC,EAAAA,YAAY,GAAG;AACb;AACA,QAAI,KAAKL,mCAAT,EAA8C;AAC5C,aAAO,IAAP;AACD;;AACD,WAAO,MAAMK,YAAN,EAAP;AACD;;AAEDC,EAAAA,gBAAgB,GAAG;AAAA;;AACjB,UAAMC,iBAAiB,GAAG,KAAKC,oBAAL,EAA1B;AACA,UAAMC,4BAA4B,GAAG,KAAKC,+BAAL,EAArC,CAFiB,CAIjB;;AACA,QAAI,KAAKV,mCAAT,EAA8C;AAAA;;AAC5C,sCAAOS,4BAA4B,CAACE,IAApC,0DAAO,sDAAmCC,KAAnC,iBAAgD,CAACC,GAAD,EAAMC,IAAN,KAAe;AACpE,YAAIA,IAAI,CAACF,KAAT,EAAgB;AACdC,UAAAA,GAAG,CAACC,IAAI,CAACC,IAAN,CAAH,GAAiBD,IAAI,CAACF,KAAtB;AACD,SAFD,MAEO,IAAIE,IAAI,CAACE,OAAT,EAAkB;AACvBH,UAAAA,GAAG,CAACC,IAAI,CAACC,IAAN,CAAH,GAAiBD,IAAI,CAACE,OAAL,CAAc,CAAd,EAAiBJ,KAAlC;AACD,SAFM,MAEA;AACL,gBAAM,IAAIK,oBAAJ,CAAkB,wCAAuCH,IAAK,EAA9D,CAAN;AACD;;AACD,eAAOD,GAAP;AACD,OATM,EASJ,EATI,CAAP;AAUD,KAhBgB,CAkBjB;;;AACA,WAAO;AACLK,MAAAA,EAAE,EAAE,+BAAAT,4BAA4B,CAACE,IAA7B,CAAmCC,KAAnC,kBACI,CAAC;AAAEG,QAAAA;AAAF,OAAD,KAAcA,IAAI,KAAK,IAD3B,EACkCH,KAFjC;AAGLO,MAAAA,YAAY,iBAAE,+BAAAV,4BAA4B,CAACE,IAA7B,CAAmCC,KAAnC,kBACN,CAAC;AAAEG,QAAAA;AAAF,OAAD,KAAcA,IAAI,KAAK,cADjB,CAAF,gDAAE,YACkCH,KAJ3C;AAKLQ,MAAAA,UAAU,EAAEb,iBAAF,aAAEA,iBAAF,uBAAEA,iBAAiB,CAAEa;AAL1B,KAAP;AAOD;;AAEDC,EAAAA,qBAAqB,GAAG;AAAA;;AACtB,UAAMpB,aAAa,GAAG,KAAKS,+BAAL,EAAtB;AACA,UAAMU,UAAU,GAAG,+BAAAnB,aAAa,CAACU,IAAd,CAAoBC,KAApB,kBAA+B,CAAC;AAAEG,MAAAA;AAAF,KAAD,KAAcA,IAAI,KAAK,YAAtD,CAAnB,CAFsB,CAGtB;;AACA,QAAIK,UAAU,IAAIA,UAAU,CAACJ,OAA7B,EAAsC;AACpC,aAAO;AAAED,QAAAA,IAAI,EAAE,YAAR;AAAsBX,QAAAA,IAAI,EAAE,QAA5B;AAAsCkB,QAAAA,QAAQ,EAAE;AAAhD,OAAP;AACD,KANqB,CAOtB;;;AACA,UAAMC,MAAM,GAAG,CAAC,GAAGtB,aAAa,CAACU,IAAd,CAAoBC,KAAxB,CAAf;AACA,WAAOW,MAAP;AACD;;AA5DkE;;;8BAAxD5B,6B,qBACc,iC","sourcesContent":["/* eslint-disable @typescript-eslint/no-non-null-assertion */\n/*!\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 { AuthSdkError } from '../../errors';\nimport { AuthenticatorData, AuthenticatorDataValues } from './Base/AuthenticatorData';\nimport { IdxRemediation } from '../types/idx-js';\n\nexport type AuthenticatorVerificationDataValues = AuthenticatorDataValues;\n\nexport class AuthenticatorVerificationData extends AuthenticatorData {\n static remediationName = 'authenticator-verification-data';\n\n values!: AuthenticatorVerificationDataValues;\n shouldProceedWithEmailAuthenticator: boolean;\n\n constructor(remediation: IdxRemediation, values: AuthenticatorDataValues = {}) {\n super(remediation, values);\n\n // TODO: extend this feature to all authenticators\n this.shouldProceedWithEmailAuthenticator = this.authenticator.methods.length === 1 \n && this.authenticator.methods[0].type === 'email';\n }\n\n canRemediate() {\n // auto proceed if there is only one method\n if (this.shouldProceedWithEmailAuthenticator) {\n return true;\n }\n return super.canRemediate();\n }\n\n mapAuthenticator() {\n const authenticatorData = this.getAuthenticatorData();\n const authenticatorFromRemediation = this.getAuthenticatorFromRemediation();\n\n // auto proceed with the only methodType option\n if (this.shouldProceedWithEmailAuthenticator) {\n return authenticatorFromRemediation.form?.value.reduce((acc, curr) => {\n if (curr.value) {\n acc[curr.name] = curr.value;\n } else if (curr.options) {\n acc[curr.name] = curr.options![0].value;\n } else {\n throw new AuthSdkError(`Unsupported authenticator data type: ${curr}`);\n }\n return acc;\n }, {});\n }\n\n // return based on user selection\n return { \n id: authenticatorFromRemediation.form!.value\n .find(({ name }) => name === 'id')!.value,\n enrollmentId: authenticatorFromRemediation.form!.value\n .find(({ name }) => name === 'enrollmentId')?.value,\n methodType: authenticatorData?.methodType,\n };\n }\n\n getInputAuthenticator() {\n const authenticator = this.getAuthenticatorFromRemediation();\n const methodType = authenticator.form!.value.find(({ name }) => name === 'methodType');\n // if has methodType in form, let user select the methodType\n if (methodType && methodType.options) {\n return { name: 'methodType', type: 'string', required: true };\n }\n // no methodType, then return form values\n const inputs = [...authenticator.form!.value];\n return inputs;\n }\n\n}\n"],"file":"AuthenticatorVerificationData.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../lib/idx/remediators/Base/AuthenticatorData.ts"],"names":["AuthenticatorData","Remediator","constructor","remediation","values","authenticator","getAuthenticator","formatAuthenticatorData","authenticatorData","getAuthenticatorData","authenticatorsData","data","key","mapAuthenticatorDataFromValues","push","canRemediate","some","getNextStep","common","options","getMethodTypes","methodType","getAuthenticatorFromRemediation","value","name","form","getValuesAfterProceed"],"mappings":";;;;;;;;;;;;;;;;AAcA;;AAdA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;
|
|
1
|
+
{"version":3,"sources":["../../../../../lib/idx/remediators/Base/AuthenticatorData.ts"],"names":["AuthenticatorData","Remediator","constructor","remediation","values","authenticator","getAuthenticator","formatAuthenticatorData","authenticatorData","getAuthenticatorData","authenticatorsData","data","key","mapAuthenticatorDataFromValues","push","canRemediate","some","getNextStep","common","options","getMethodTypes","methodType","getAuthenticatorFromRemediation","value","name","form","getValuesAfterProceed"],"mappings":";;;;;;;;;;;;;;;;AAcA;;AAdA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAUA;AACO,MAAMA,iBAAN,SAAgCC,sBAAhC,CAA2C;AAShDC,EAAAA,WAAW,CAACC,WAAD,EAA8BC,MAA+B,GAAG,EAAhE,EAAoE;AAC7E,UAAMD,WAAN,EAAmBC,MAAnB,EAD6E,CAG7E;;AAH6E,+CAPzE;AACJ,uBAAiB;AADb,KAOyE;AAI7E,SAAKC,aAAL,GAAqB,KAAKC,gBAAL,EAArB;AAEA,SAAKC,u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iB,IAAIA,iBAAzB,CAFW;AAGX,UAAIa,UAAU,IAAI;AAAEA,QAAAA;AAAF,OAAlB;AAHW,KAAb;AAMA,WAAOV,IAAI,CAACU,UAAL,GAAkBV,IAAlB,GAAyB,IAAhC;AACD;;AAESW,EAAAA,+BAA+B,GAAwB;AAAA;;AAC/D,UAAMjB,aAAa,GAAG,oCAAKF,WAAL,CAAiBoB,KAAjB,kBACd,CAAC;AAAEC,MAAAA;AAAF,KAAD,KAAcA,IAAI,KAAK,eADT,CAAtB;AAEA,WAAOnB,aAAP;AACD;;AAEOe,EAAAA,cAAc,GAAgB;AAAA;;AACpC,UAAMf,aAAkC,GAAG,KAAKiB,+BAAL,EAA3C;AACA,0BAAO,+BAAAjB,aAAa,CAACoB,IAAd,CAAoBF,KAApB,kBAA+B,CAAC;AAAEC,MAAAA;AAAF,KAAD,KAAcA,IAAI,KAAK,YAAtD,CAAP,gDAAO,YAAqEL,OAA5E;AACD;;AAEDO,EAAAA,qBAAqB,GAAsB;AAAA;;AACzC,SAAKtB,MAAL,GAAc,MAAMsB,qBAAN,EAAd,CADyC,CAEzC;;AACA,UAAMhB,kBAAkB,GAAG,4DAAYA,kBAAZ,kBACjBC,IAAI,IAAIA,IAAI,CAACC,GAAL,KAAa,KAAKP,aAAL,CAAmBO,GADvB,CAA3B;AAEA,WAAO,EAAE,wBAAG,IAAH,CAAF;AAAkBF,MAAAA;AAAlB,KAAP;AACD;;AAnF+C","sourcesContent":["/* eslint-disable @typescript-eslint/no-non-null-assertion */\n/*!\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 { Remediator, RemediationValues } from './Remediator';\nimport { IdxRemediationValue, IdxOption, IdxRemediation, IdxAuthenticator } from '../../types/idx-js';\n\nexport type AuthenticatorDataValues = RemediationValues & {\n methodType?: string;\n};\n\n// Base class - DO NOT expose static remediationName\nexport class AuthenticatorData extends Remediator {\n\n map = {\n 'authenticator': []\n };\n\n values!: AuthenticatorDataValues;\n authenticator: IdxAuthenticator;\n\n constructor(remediation: IdxRemediation, values: AuthenticatorDataValues = {}) {\n super(remediation, values);\n\n // set before other data calculation\n this.authenticator = this.getAuthenticator()!;\n\n this.formatAuthenticatorData();\n }\n\n protected formatAuthenticatorData() {\n const authenticatorData = this.getAuthenticatorData();\n if (authenticatorData) {\n this.values.authenticatorsData = this.values.authenticatorsData!.map(data => {\n if (data.key === this.authenticator.key) {\n return this.mapAuthenticatorDataFromValues(data);\n }\n return data;\n });\n } else {\n const data = this.mapAuthenticatorDataFromValues();\n if (data) {\n this.values.authenticatorsData!.push(data);\n }\n }\n }\n\n protected getAuthenticatorData() {\n return this.values.authenticatorsData!\n .find(({ key }) => key === this.authenticator.key);\n }\n\n canRemediate() {\n return this.values.authenticatorsData!\n .some(data => data.key === this.authenticator.key);\n }\n\n getNextStep() {\n const common = super.getNextStep();\n const options = this.getMethodTypes();\n return { \n ...common, \n ...(options && { options }) \n };\n }\n\n protected mapAuthenticatorDataFromValues(authenticatorData?) {\n // add methodType to authenticatorData if it exists in values\n const { methodType } = this.values;\n const data = { \n key: this.authenticator.key, \n ...(authenticatorData && authenticatorData),\n ...(methodType && { methodType }) \n };\n\n return data.methodType ? data : null;\n }\n\n protected getAuthenticatorFromRemediation(): IdxRemediationValue {\n const authenticator = this.remediation.value!\n .find(({ name }) => name === 'authenticator') as IdxRemediationValue;\n return authenticator;\n }\n\n private getMethodTypes(): IdxOption[] {\n const authenticator: IdxRemediationValue = this.getAuthenticatorFromRemediation();\n return authenticator.form!.value.find(({ name }) => name === 'methodType')?.options as IdxOption[];\n }\n\n getValuesAfterProceed(): RemediationValues {\n this.values = super.getValuesAfterProceed();\n // remove used authenticatorData\n const authenticatorsData = this.values.authenticatorsData!\n .filter(data => data.key !== this.authenticator.key);\n return { ...this.values, authenticatorsData };\n }\n}\n"],"file":"AuthenticatorData.js"}
|
package/cjs/idx/run.js
CHANGED
|
@@ -103,6 +103,8 @@ function getAvailableSteps(idxResponse) {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
async function run(authClient, options = {}) {
|
|
106
|
+
var _meta;
|
|
107
|
+
|
|
106
108
|
let tokens;
|
|
107
109
|
let nextStep;
|
|
108
110
|
let messages;
|
|
@@ -264,6 +266,10 @@ async function run(authClient, options = {}) {
|
|
|
264
266
|
authClient.transactionManager.clear({
|
|
265
267
|
clearSharedStorage
|
|
266
268
|
});
|
|
269
|
+
} else if ((_meta = meta) !== null && _meta !== void 0 && _meta.state) {
|
|
270
|
+
// ensures state is saved to sessionStorage
|
|
271
|
+
(0, _transactionMeta.saveTransactionMeta)(authClient, { ...meta
|
|
272
|
+
});
|
|
267
273
|
} // from idx-js, used by the widget
|
|
268
274
|
|
|
269
275
|
|
package/cjs/idx/run.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../lib/idx/run.ts"],"names":["getEnabledFeatures","idxResponse","res","actions","neededToProceed","push","IdxFeature","PASSWORD_RECOVERY","some","name","REGISTRATION","SOCIAL_IDP","ACCOUNT_UNLOCK","getAvailableSteps","remediatorMap","remediators","map","remediatorClass","remediationName","remediation","T","remediator","getNextStep","context","run","authClient","options","tokens","nextStep","messages","error","meta","enabledFeatures","availableSteps","status","IdxStatus","PENDING","shouldClearTransaction","clearSharedStorage","interactionHandle","metaFromResp","interactionCode","flow","state","scopes","version","withCredentials","exchangeCodeForTokens","autoRemediate","step","recoveryToken","activationToken","idx","getFlow","setFlow","flowSpec","transactionManager","clear","interactResponse","values","stateHandle","rawIdxState","idxResponseFromResp","nextStepFromResp","terminal","canceled","messagesFromResp","saveIdxResponse","TERMINAL","CANCELED","SUCCESS","clientId","codeVerifier","ignoreSignature","redirectUri","urls","token","err","FAILURE","proceed"],"mappings":";;;;;;;;;;;;;;AAcA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAQA;;AACA;;;;;;AA5BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AAyBA,SAASA,kBAAT,CAA4BC,WAA5B,EAAoE;AAClE,QAAMC,GAAG,GAAG,EAAZ;AACA,QAAM;AAAEC,IAAAA,OAAF;AAAWC,IAAAA;AAAX,MAA+BH,WAArC;;AAEA,MAAIE,OAAO,CAAC,8BAAD,CAAX,EAA6C;AAC3CD,IAAAA,GAAG,CAACG,IAAJ,CAASC,kBAAWC,iBAApB;AACD;;AAED,MAAIH,eAAe,CAACI,IAAhB,CAAqB,CAAC;AAAEC,IAAAA;AAAF,GAAD,KAAcA,IAAI,KAAK,uBAA5C,CAAJ,EAA0E;AACxEP,IAAAA,GAAG,CAACG,IAAJ,CAASC,kBAAWI,YAApB;AACD;;AAED,MAAIN,eAAe,CAACI,IAAhB,CAAqB,CAAC;AAAEC,IAAAA;AAAF,GAAD,KAAcA,IAAI,KAAK,cAA5C,CAAJ,EAAiE;AAC/DP,IAAAA,GAAG,CAACG,IAAJ,CAASC,kBAAWK,UAApB;AACD;;AAED,MAAIP,eAAe,CAACI,IAAhB,CAAqB,CAAC;AAAEC,IAAAA;AAAF,GAAD,KAAcA,IAAI,KAAK,gBAA5C,CAAJ,EAAmE;AACjEP,IAAAA,GAAG,CAACG,IAAJ,CAASC,kBAAWM,cAApB;AACD;;AAED,SAAOV,GAAP;AACD;;AAED,SAASW,iBAAT,CAA2BZ,WAA3B,EAAiE;AAAA;;AAC/D,QAAMC,GAAG,GAAG,EAAZ;AAEA,QAAMY,aAAa,GAAG,qDAAcC,WAAd,kBAAkC,CAACC,GAAD,EAAMC,eAAN,KAA0B;AAChF;AACA,QAAIA,eAAe,CAACC,eAApB,EAAq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,OAAF;AAAWoB,IAAAA,OAAX;AAAoBnB,IAAAA,eAApB;AAAqC2E,IAAAA,OAArC;AAA8ClB,IAAAA;AAA9C,MAA8D5D,WAAW,IAAI,EAAnF;AACA,SAAO;AACLiC,IAAAA,MADK;AAEL,QAAIH,IAAI,IAAI;AAAEA,MAAAA;AAAF,KAAZ,CAFK;AAGL,QAAIC,eAAe,IAAI;AAAEA,MAAAA;AAAF,KAAvB,CAHK;AAIL,QAAIC,cAAc,IAAI;AAAEA,MAAAA;AAAF,KAAtB,CAJK;AAKL,QAAIN,MAAM,IAAI;AAAEA,MAAAA,MAAM,EAAEA,MAAM,CAACA;AAAjB,KAAd,CALK;AAML,QAAIC,QAAQ,IAAI;AAAEA,MAAAA;AAAF,KAAhB,CANK;AAOL,QAAIC,QAAQ,IAAI;AAAEA,MAAAA;AAAF,KAAhB,CAPK;AAQL,QAAIC,KAAK,IAAI;AAAEA,MAAAA;AAAF,KAAb,CARK;AASLW,IAAAA,eATK;AASY;AAEjB;AACAtC,IAAAA,OAZK;AAaLoB,IAAAA,OAbK;AAcLnB,IAAAA,eAdK;AAeL2E,IAAAA,OAfK;AAgBLlB,IAAAA;AAhBK,GAAP;AAkBD","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, complexity, max-depth */\nimport { interact } from './interact';\nimport { introspect } from './introspect';\nimport { remediate, RemediateOptions } from './remediate';\nimport { getFlowSpecification, RemediationFlow } from './flow';\nimport * as remediators from './remediators';\nimport { \n OktaAuthInterface,\n IdxStatus,\n IdxTransaction,\n IdxFeature,\n NextStep,\n FlowIdentifier,\n} from '../types';\nimport { IdxResponse, isIdxResponse } from './types/idx-js';\nimport { getSavedTransactionMeta } from './transactionMeta';\nimport { ProceedOptions } from './proceed';\n\nexport type RunOptions = ProceedOptions & RemediateOptions & {\n flow?: FlowIdentifier;\n remediators?: RemediationFlow;\n actions?: string[];\n withCredentials?: boolean;\n}\n\nfunction getEnabledFeatures(idxResponse: IdxResponse): IdxFeature[] {\n const res = [];\n const { actions, neededToProceed } = idxResponse;\n\n if (actions['currentAuthenticator-recover']) {\n res.push(IdxFeature.PASSWORD_RECOVERY as never);\n }\n\n if (neededToProceed.some(({ name }) => name === 'select-enroll-profile')) {\n res.push(IdxFeature.REGISTRATION as never);\n }\n\n if (neededToProceed.some(({ name }) => name === 'redirect-idp')) {\n res.push(IdxFeature.SOCIAL_IDP as never);\n }\n\n if (neededToProceed.some(({ name }) => name === 'unlock-account')) {\n res.push(IdxFeature.ACCOUNT_UNLOCK as never);\n }\n\n return res;\n}\n\nfunction getAvailableSteps(idxResponse: IdxResponse): NextStep[] {\n const res = [];\n\n const remediatorMap = Object.values(remediators).reduce((map, remediatorClass) => {\n // Only add concrete subclasses to the map\n if (remediatorClass.remediationName) {\n map[remediatorClass.remediationName] = remediatorClass;\n }\n return map;\n }, {});\n\n for (let remediation of idxResponse.neededToProceed) {\n const T = remediatorMap[remediation.name];\n if (T) {\n const remediator = new T(remediation);\n res.push (remediator.getNextStep(idxResponse.context) as never);\n }\n }\n\n return res;\n}\n\nexport async function run(\n authClient: OktaAuthInterface, \n options: RunOptions = {},\n): Promise<IdxTransaction> {\n let tokens;\n let nextStep;\n let messages;\n let error;\n let meta;\n let enabledFeatures;\n let availableSteps;\n let status = IdxStatus.PENDING;\n let shouldClearTransaction = false;\n let clearSharedStorage = true;\n let idxResponse;\n let interactionHandle;\n let metaFromResp;\n let interactionCode;\n\n try {\n\n let {\n flow,\n state,\n scopes,\n version,\n remediators,\n actions,\n withCredentials,\n exchangeCodeForTokens,\n autoRemediate,\n step,\n recoveryToken,\n activationToken\n } = options;\n\n // Only one flow can be operating at a time\n flow = flow || authClient.idx.getFlow() || 'default';\n if (flow) {\n authClient.idx.setFlow(flow);\n const flowSpec = getFlowSpecification(authClient, flow);\n // Favor option values over flow spec\n withCredentials = (typeof withCredentials !== 'undefined') ? withCredentials : flowSpec.withCredentials;\n remediators = remediators || flowSpec.remediators;\n actions = actions || flowSpec.actions;\n }\n\n // Try to resume saved transaction\n metaFromResp = getSavedTransactionMeta(authClient, { state, recoveryToken, activationToken });\n interactionHandle = metaFromResp?.interactionHandle; // may be undefined\n\n if (!interactionHandle) {\n // start a new transaction\n authClient.transactionManager.clear();\n const interactResponse = await interact(authClient, {\n withCredentials,\n state,\n scopes,\n activationToken,\n recoveryToken\n }); \n interactionHandle = interactResponse.interactionHandle;\n metaFromResp = interactResponse.meta;\n withCredentials = metaFromResp.withCredentials;\n }\n\n // Introspect to get idx response\n idxResponse = await introspect(authClient, { withCredentials, version, interactionHandle });\n enabledFeatures = getEnabledFeatures(idxResponse);\n availableSteps = getAvailableSteps(idxResponse);\n \n // Include meta in the transaction response\n meta = metaFromResp;\n\n if (autoRemediate !== false && (remediators || actions)) {\n const values: remediators.RemediationValues = { \n ...options, \n stateHandle: idxResponse.rawIdxState.stateHandle \n };\n\n // Can we handle the remediations?\n const { \n idxResponse: idxResponseFromResp, \n nextStep: nextStepFromResp,\n terminal,\n canceled,\n messages: messagesFromResp,\n } = await remediate(idxResponse, values, { remediators, actions, flow, step });\n idxResponse = idxResponseFromResp || idxResponse;\n\n // Track fields from remediation response\n nextStep = nextStepFromResp;\n messages = messagesFromResp;\n\n // Save intermediate idx response in storage to reduce introspect call\n if (nextStep) {\n authClient.transactionManager.saveIdxResponse(idxResponse.rawIdxState);\n availableSteps = getAvailableSteps(idxResponse);\n }\n\n if (terminal) {\n status = IdxStatus.TERMINAL;\n shouldClearTransaction = true;\n clearSharedStorage = false; // transaction may be continued in another tab\n } if (canceled) {\n status = IdxStatus.CANCELED;\n shouldClearTransaction = true;\n } else if (idxResponse?.interactionCode) { \n interactionCode = idxResponse.interactionCode;\n\n if (exchangeCodeForTokens === false) {\n status = IdxStatus.SUCCESS;\n shouldClearTransaction = false;\n } else {\n // exchange the interaction code for tokens\n const {\n clientId,\n codeVerifier,\n ignoreSignature,\n redirectUri,\n urls,\n scopes,\n } = metaFromResp;\n tokens = await authClient.token.exchangeCodeForTokens({\n interactionCode,\n clientId,\n codeVerifier,\n ignoreSignature,\n redirectUri,\n scopes\n }, urls);\n\n status = IdxStatus.SUCCESS;\n shouldClearTransaction = true;\n }\n }\n }\n } catch (err) {\n // current version of idx-js will throw/reject IDX responses. Handle these differently than regular errors\n if (isIdxResponse(err)) {\n error = err;\n status = IdxStatus.FAILURE;\n shouldClearTransaction = true;\n } else {\n // error is not an IDX response, throw it like a regular error\n throw err;\n }\n\n }\n\n if (shouldClearTransaction) {\n authClient.transactionManager.clear({ clearSharedStorage });\n }\n \n // from idx-js, used by the widget\n const { actions, context, neededToProceed, proceed, rawIdxState } = idxResponse || {};\n return {\n status,\n ...(meta && { meta }),\n ...(enabledFeatures && { enabledFeatures }),\n ...(availableSteps && { availableSteps }),\n ...(tokens && { tokens: tokens.tokens }),\n ...(nextStep && { nextStep }),\n ...(messages && { messages }),\n ...(error && { error }),\n interactionCode, // if options.exchangeCodeForTokens is false\n\n // from idx-js\n actions,\n context,\n neededToProceed,\n proceed,\n rawIdxState,\n };\n}\n"],"file":"run.js"}
|
|
1
|
+
{"version":3,"sources":["../../../lib/idx/run.ts"],"names":["getEnabledFeatures","idxResponse","res","actions","neededToProceed","push","IdxFeature","PASSWORD_RECOVERY","some","name","REGISTRATION","SOCIAL_IDP","ACCOUNT_UNLOCK","getAvailableSteps","remediatorMap","remediators","map","remediatorClass","remediationName","remediation","T","remediator","getNextStep","context","run","authClient","options","tokens","nextStep","messages","error","meta","enabledFeatures","availableSteps","status","IdxStatus","PENDING","shouldClearTransaction","clearSharedStorage","interactionHandle","metaFromResp","interactionCode","flow","state","scopes","version","withCredentials","exchangeCodeForTokens","autoRemediate","step","recoveryToken","activationToken","idx","getFlow","setFlow","flowSpec","transactionManager","clear","interactResponse","values","stateHandle","rawIdxState","idxResponseFromResp","nextStepFromResp","terminal","canceled","messagesFromResp","saveIdxResponse","TERMINAL","CANCELED","SUCCESS","clientId","codeVerifier","ignoreSignature","redirectUri","urls","token","err","FAILURE","proceed"],"mappings":";;;;;;;;;;;;;;AAcA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAQA;;AACA;;;;;;AA5BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AAyBA,SAASA,kBAAT,CAA4BC,WAA5B,EAAoE;AAClE,QAAMC,GAAG,GAAG,EAAZ;AACA,QAAM;AAAEC,IAAAA,OAAF;AAAWC,IAAAA;AAAX,MAA+BH,WAArC;;AAEA,MAAIE,OAAO,CAAC,8BAAD,CAAX,EAA6C;AAC3CD,IAAAA,GAAG,CAACG,IAAJ,CAASC,kBAAWC,iBAApB;AACD;;AAED,MAAIH,eAAe,CAACI,IAAhB,CAAqB,CAAC;AAAEC,IAAAA;AAAF,GAAD,KAAcA,IAAI,KAAK,uBAA5C,CAAJ,EAA0E;AACxEP,IAAAA,GAAG,CAACG,IAAJ,CAASC,kBAAWI,YAApB;AACD;;AAED,MAAIN,eAAe,CAACI,IAAhB,CAAqB,CAAC;AAAEC,IAAAA;AAAF,GAAD,KAAcA,IAAI,KAAK,cAA5C,CAAJ,EAAiE;AAC/DP,IAAAA,GAAG,CAACG,IAAJ,CAASC,kBAAWK,UAApB;AACD;;AAED,MAAIP,eAAe,CAACI,IAAhB,CAAqB,CAAC;AAAEC,IAAAA;AAAF,GAAD,KAAcA,IAAI,KAAK,gBAA5C,CAAJ,EAAmE;AACjEP,IAAAA,GAAG,CAACG,IAAJ,CAASC,kBAAWM,cAApB;AACD;;AAED,SAAOV,GAAP;AACD;;AAED,SAASW,iBAAT,C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YAAMwC,GAAN;AACD;AAEF;;AAED,MAAIxC,sBAAJ,EAA4B;AAC1BZ,IAAAA,UAAU,CAAC+B,kBAAX,CAA8BC,KAA9B,CAAoC;AAAEnB,MAAAA;AAAF,KAApC;AACD,GAFD,MAGK,aAAIP,IAAJ,kCAAI,MAAMY,KAAV,EAAiB;AACpB;AACA,8CAAoBlB,UAApB,EAAgC,EAAE,GAAGM;AAAL,KAAhC;AACD,GAzJwB,CA2JzB;;;AACA,QAAM;AAAE5B,IAAAA,OAAF;AAAWoB,IAAAA,OAAX;AAAoBnB,IAAAA,eAApB;AAAqC2E,IAAAA,OAArC;AAA8ClB,IAAAA;AAA9C,MAA8D5D,WAAW,IAAI,EAAnF;AACA,SAAO;AACLiC,IAAAA,MADK;AAEL,QAAIH,IAAI,IAAI;AAAEA,MAAAA;AAAF,KAAZ,CAFK;AAGL,QAAIC,eAAe,IAAI;AAAEA,MAAAA;AAAF,KAAvB,CAHK;AAIL,QAAIC,cAAc,IAAI;AAAEA,MAAAA;AAAF,KAAtB,CAJK;AAKL,QAAIN,MAAM,IAAI;AAAEA,MAAAA,MAAM,EAAEA,MAAM,CAACA;AAAjB,KAAd,CALK;AAML,QAAIC,QAAQ,IAAI;AAAEA,MAAAA;AAAF,KAAhB,CANK;AAOL,QAAIC,QAAQ,IAAI;AAAEA,MAAAA;AAAF,KAAhB,CAPK;AAQL,QAAIC,KAAK,IAAI;AAAEA,MAAAA;AAAF,KAAb,CARK;AASLW,IAAAA,eATK;AASY;AAEjB;AACAtC,IAAAA,OAZK;AAaLoB,IAAAA,OAbK;AAcLnB,IAAAA,eAdK;AAeL2E,IAAAA,OAfK;AAgBLlB,IAAAA;AAhBK,GAAP;AAkBD","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, complexity, max-depth */\nimport { interact } from './interact';\nimport { introspect } from './introspect';\nimport { remediate, RemediateOptions } from './remediate';\nimport { getFlowSpecification, RemediationFlow } from './flow';\nimport * as remediators from './remediators';\nimport { \n OktaAuthInterface,\n IdxStatus,\n IdxTransaction,\n IdxFeature,\n NextStep,\n FlowIdentifier,\n} from '../types';\nimport { IdxResponse, isIdxResponse } from './types/idx-js';\nimport { getSavedTransactionMeta, saveTransactionMeta } from './transactionMeta';\nimport { ProceedOptions } from './proceed';\n\nexport type RunOptions = ProceedOptions & RemediateOptions & {\n flow?: FlowIdentifier;\n remediators?: RemediationFlow;\n actions?: string[];\n withCredentials?: boolean;\n}\n\nfunction getEnabledFeatures(idxResponse: IdxResponse): IdxFeature[] {\n const res = [];\n const { actions, neededToProceed } = idxResponse;\n\n if (actions['currentAuthenticator-recover']) {\n res.push(IdxFeature.PASSWORD_RECOVERY as never);\n }\n\n if (neededToProceed.some(({ name }) => name === 'select-enroll-profile')) {\n res.push(IdxFeature.REGISTRATION as never);\n }\n\n if (neededToProceed.some(({ name }) => name === 'redirect-idp')) {\n res.push(IdxFeature.SOCIAL_IDP as never);\n }\n\n if (neededToProceed.some(({ name }) => name === 'unlock-account')) {\n res.push(IdxFeature.ACCOUNT_UNLOCK as never);\n }\n\n return res;\n}\n\nfunction getAvailableSteps(idxResponse: IdxResponse): NextStep[] {\n const res = [];\n\n const remediatorMap = Object.values(remediators).reduce((map, remediatorClass) => {\n // Only add concrete subclasses to the map\n if (remediatorClass.remediationName) {\n map[remediatorClass.remediationName] = remediatorClass;\n }\n return map;\n }, {});\n\n for (let remediation of idxResponse.neededToProceed) {\n const T = remediatorMap[remediation.name];\n if (T) {\n const remediator = new T(remediation);\n res.push (remediator.getNextStep(idxResponse.context) as never);\n }\n }\n\n return res;\n}\n\nexport async function run(\n authClient: OktaAuthInterface, \n options: RunOptions = {},\n): Promise<IdxTransaction> {\n let tokens;\n let nextStep;\n let messages;\n let error;\n let meta;\n let enabledFeatures;\n let availableSteps;\n let status = IdxStatus.PENDING;\n let shouldClearTransaction = false;\n let clearSharedStorage = true;\n let idxResponse;\n let interactionHandle;\n let metaFromResp;\n let interactionCode;\n\n try {\n\n let {\n flow,\n state,\n scopes,\n version,\n remediators,\n actions,\n withCredentials,\n exchangeCodeForTokens,\n autoRemediate,\n step,\n recoveryToken,\n activationToken\n } = options;\n\n // Only one flow can be operating at a time\n flow = flow || authClient.idx.getFlow() || 'default';\n if (flow) {\n authClient.idx.setFlow(flow);\n const flowSpec = getFlowSpecification(authClient, flow);\n // Favor option values over flow spec\n withCredentials = (typeof withCredentials !== 'undefined') ? withCredentials : flowSpec.withCredentials;\n remediators = remediators || flowSpec.remediators;\n actions = actions || flowSpec.actions;\n }\n\n // Try to resume saved transaction\n metaFromResp = getSavedTransactionMeta(authClient, { state, recoveryToken, activationToken });\n interactionHandle = metaFromResp?.interactionHandle; // may be undefined\n\n if (!interactionHandle) {\n // start a new transaction\n authClient.transactionManager.clear();\n const interactResponse = await interact(authClient, {\n withCredentials,\n state,\n scopes,\n activationToken,\n recoveryToken\n }); \n interactionHandle = interactResponse.interactionHandle;\n metaFromResp = interactResponse.meta;\n withCredentials = metaFromResp.withCredentials;\n }\n\n // Introspect to get idx response\n idxResponse = await introspect(authClient, { withCredentials, version, interactionHandle });\n enabledFeatures = getEnabledFeatures(idxResponse);\n availableSteps = getAvailableSteps(idxResponse);\n \n // Include meta in the transaction response\n meta = metaFromResp;\n\n if (autoRemediate !== false && (remediators || actions)) {\n const values: remediators.RemediationValues = { \n ...options, \n stateHandle: idxResponse.rawIdxState.stateHandle \n };\n\n // Can we handle the remediations?\n const { \n idxResponse: idxResponseFromResp, \n nextStep: nextStepFromResp,\n terminal,\n canceled,\n messages: messagesFromResp,\n } = await remediate(idxResponse, values, { remediators, actions, flow, step });\n idxResponse = idxResponseFromResp || idxResponse;\n\n // Track fields from remediation response\n nextStep = nextStepFromResp;\n messages = messagesFromResp;\n\n // Save intermediate idx response in storage to reduce introspect call\n if (nextStep) {\n authClient.transactionManager.saveIdxResponse(idxResponse.rawIdxState);\n availableSteps = getAvailableSteps(idxResponse);\n }\n\n if (terminal) {\n status = IdxStatus.TERMINAL;\n shouldClearTransaction = true;\n clearSharedStorage = false; // transaction may be continued in another tab\n } if (canceled) {\n status = IdxStatus.CANCELED;\n shouldClearTransaction = true;\n } else if (idxResponse?.interactionCode) { \n interactionCode = idxResponse.interactionCode;\n\n if (exchangeCodeForTokens === false) {\n status = IdxStatus.SUCCESS;\n shouldClearTransaction = false;\n } else {\n // exchange the interaction code for tokens\n const {\n clientId,\n codeVerifier,\n ignoreSignature,\n redirectUri,\n urls,\n scopes,\n } = metaFromResp;\n tokens = await authClient.token.exchangeCodeForTokens({\n interactionCode,\n clientId,\n codeVerifier,\n ignoreSignature,\n redirectUri,\n scopes\n }, urls);\n\n status = IdxStatus.SUCCESS;\n shouldClearTransaction = true;\n }\n }\n }\n } catch (err) {\n // current version of idx-js will throw/reject IDX responses. Handle these differently than regular errors\n if (isIdxResponse(err)) {\n error = err;\n status = IdxStatus.FAILURE;\n shouldClearTransaction = true;\n } else {\n // error is not an IDX response, throw it like a regular error\n throw err;\n }\n\n }\n\n if (shouldClearTransaction) {\n authClient.transactionManager.clear({ clearSharedStorage });\n }\n else if (meta?.state) {\n // ensures state is saved to sessionStorage\n saveTransactionMeta(authClient, { ...meta });\n }\n \n // from idx-js, used by the widget\n const { actions, context, neededToProceed, proceed, rawIdxState } = idxResponse || {};\n return {\n status,\n ...(meta && { meta }),\n ...(enabledFeatures && { enabledFeatures }),\n ...(availableSteps && { availableSteps }),\n ...(tokens && { tokens: tokens.tokens }),\n ...(nextStep && { nextStep }),\n ...(messages && { messages }),\n ...(error && { error }),\n interactionCode, // if options.exchangeCodeForTokens is false\n\n // from idx-js\n actions,\n context,\n neededToProceed,\n proceed,\n rawIdxState,\n };\n}\n"],"file":"run.js"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
exports.getCookieSettings = getCookieSettings;
|
|
6
|
+
Object.defineProperty(exports, "storage", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _browserStorage.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
exports.enableSharedStorage = exports.STORAGE_MANAGER_OPTIONS = void 0;
|
|
13
|
+
|
|
14
|
+
var _util = require("../util");
|
|
15
|
+
|
|
16
|
+
var _browserStorage = _interopRequireDefault(require("../browser/browserStorage"));
|
|
17
|
+
|
|
18
|
+
/*!
|
|
19
|
+
* Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.
|
|
20
|
+
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
|
|
21
|
+
*
|
|
22
|
+
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
|
|
23
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
24
|
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
25
|
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
26
|
+
*
|
|
27
|
+
* See the License for the specific language governing permissions and limitations under the License.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/* eslint-disable complexity */
|
|
31
|
+
const STORAGE_MANAGER_OPTIONS = {
|
|
32
|
+
token: {
|
|
33
|
+
storageTypes: ['localStorage', 'sessionStorage', 'cookie']
|
|
34
|
+
},
|
|
35
|
+
cache: {
|
|
36
|
+
storageTypes: ['localStorage', 'sessionStorage', 'cookie']
|
|
37
|
+
},
|
|
38
|
+
transaction: {
|
|
39
|
+
storageTypes: ['sessionStorage', 'localStorage', 'cookie']
|
|
40
|
+
},
|
|
41
|
+
'shared-transaction': {
|
|
42
|
+
storageTypes: ['localStorage']
|
|
43
|
+
},
|
|
44
|
+
'original-uri': {
|
|
45
|
+
storageTypes: ['localStorage']
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
exports.STORAGE_MANAGER_OPTIONS = STORAGE_MANAGER_OPTIONS;
|
|
49
|
+
const enableSharedStorage = true;
|
|
50
|
+
exports.enableSharedStorage = enableSharedStorage;
|
|
51
|
+
|
|
52
|
+
function getCookieSettings(args = {}, isHTTPS) {
|
|
53
|
+
// Secure cookies will be automatically used on a HTTPS connection
|
|
54
|
+
// Non-secure cookies will be automatically used on a HTTP connection
|
|
55
|
+
// secure option can override the automatic behavior
|
|
56
|
+
var cookieSettings = args.cookies || {};
|
|
57
|
+
|
|
58
|
+
if (typeof cookieSettings.secure === 'undefined') {
|
|
59
|
+
cookieSettings.secure = isHTTPS;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (typeof cookieSettings.sameSite === 'undefined') {
|
|
63
|
+
cookieSettings.sameSite = cookieSettings.secure ? 'none' : 'lax';
|
|
64
|
+
} // If secure=true, but the connection is not HTTPS, set secure=false.
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
if (cookieSettings.secure && !isHTTPS) {
|
|
68
|
+
// eslint-disable-next-line no-console
|
|
69
|
+
(0, _util.warn)('The current page is not being served with the HTTPS protocol.\n' + 'For security reasons, we strongly recommend using HTTPS.\n' + 'If you cannot use HTTPS, set "cookies.secure" option to false.');
|
|
70
|
+
cookieSettings.secure = false;
|
|
71
|
+
} // Chrome >= 80 will block cookies with SameSite=None unless they are also Secure
|
|
72
|
+
// If sameSite=none, but the connection is not HTTPS, set sameSite=lax.
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
if (cookieSettings.sameSite === 'none' && !cookieSettings.secure) {
|
|
76
|
+
cookieSettings.sameSite = 'lax';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return cookieSettings;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../lib/options/browser.ts"],"names":["STORAGE_MANAGER_OPTIONS","token","storageTypes","cache","transaction","enableSharedStorage","getCookieSettings","args","isHTTPS","cookieSettings","cookies","secure","sameSite"],"mappings":";;;;;;;;;;;;;AAcA;;AAEA;;AAhBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AAMO,MAAMA,uBAA8C,GAAG;AAC5DC,EAAAA,KAAK,EAAE;AACLC,IAAAA,YAAY,EAAE,CACZ,cADY,EAEZ,gBAFY,EAGZ,QAHY;AADT,GADqD;AAQ5DC,EAAAA,KAAK,EAAE;AACLD,IAAAA,YAAY,EAAE,CACZ,cADY,EAEZ,gBAFY,EAGZ,QAHY;AADT,GARqD;AAe5DE,EAAAA,WAAW,EAAE;AACXF,IAAAA,YAAY,EAAE,CACZ,gBADY,EAEZ,cAFY,EAGZ,QAHY;AADH,GAf+C;AAsB5D,wBAAsB;AACpBA,IAAAA,YAAY,EAAE,CACZ,cADY;AADM,GAtBsC;AA2B5D,kBAAgB;AACdA,IAAAA,YAAY,EAAE,CACZ,cADY;AADA;AA3B4C,CAAvD;;AAkCA,MAAMG,mBAAmB,GAAG,IAA5B;;;AAEA,SAASC,iBAAT,CAA2BC,IAAqB,GAAG,EAAnD,EAAuDC,OAAvD,EAAyE;AAC9E;AACA;AACA;AACA,MAAIC,cAAc,GAAGF,IAAI,CAACG,OAAL,IAAgB,EAArC;;AACA,MAAI,OAAOD,cAAc,CAACE,MAAtB,KAAiC,WAArC,EAAkD;AAChDF,IAAAA,cAAc,CAACE,MAAf,GAAwBH,OAAxB;AACD;;AACD,MAAI,OAAOC,cAAc,CAACG,QAAtB,KAAmC,WAAvC,EAAoD;AAClDH,IAAAA,cAAc,CAACG,QAAf,GAA0BH,cAAc,CAACE,MAAf,GAAwB,MAAxB,GAAiC,KAA3D;AACD,GAV6E,CAY9E;;;AACA,MAAIF,cAAc,CAACE,MAAf,IAAyB,CAACH,OAA9B,EAAuC;AACrC;AACA,oBACE,oEACA,4DADA,GAEA,gEAHF;AAKAC,IAAAA,cAAc,CAACE,MAAf,GAAwB,KAAxB;AACD,GArB6E,CAuB9E;AACA;;;AACA,MAAIF,cAAc,CAACG,QAAf,KAA4B,MAA5B,IAAsC,CAACH,cAAc,CAACE,MAA1D,EAAkE;AAChEF,IAAAA,cAAc,CAACG,QAAf,GAA0B,KAA1B;AACD;;AAED,SAAOH,cAAP;AACD","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/* eslint-disable complexity */\nimport { StorageManagerOptions, OktaAuthOptions } from '../types';\nimport { warn } from '../util';\n\nexport { default as storage } from '../browser/browserStorage';\n\nexport const STORAGE_MANAGER_OPTIONS: StorageManagerOptions = {\n token: {\n storageTypes: [\n 'localStorage',\n 'sessionStorage',\n 'cookie'\n ]\n },\n cache: {\n storageTypes: [\n 'localStorage',\n 'sessionStorage',\n 'cookie'\n ]\n },\n transaction: {\n storageTypes: [\n 'sessionStorage',\n 'localStorage',\n 'cookie'\n ]\n },\n 'shared-transaction': {\n storageTypes: [\n 'localStorage'\n ]\n },\n 'original-uri': {\n storageTypes: [\n 'localStorage'\n ]\n }\n};\n\nexport const enableSharedStorage = true;\n\nexport function getCookieSettings(args: OktaAuthOptions = {}, isHTTPS: boolean) {\n // Secure cookies will be automatically used on a HTTPS connection\n // Non-secure cookies will be automatically used on a HTTP connection\n // secure option can override the automatic behavior\n var cookieSettings = args.cookies || {};\n if (typeof cookieSettings.secure === 'undefined') {\n cookieSettings.secure = isHTTPS;\n }\n if (typeof cookieSettings.sameSite === 'undefined') {\n cookieSettings.sameSite = cookieSettings.secure ? 'none' : 'lax';\n }\n\n // If secure=true, but the connection is not HTTPS, set secure=false.\n if (cookieSettings.secure && !isHTTPS) {\n // eslint-disable-next-line no-console\n warn(\n 'The current page is not being served with the HTTPS protocol.\\n' +\n 'For security reasons, we strongly recommend using HTTPS.\\n' +\n 'If you cannot use HTTPS, set \"cookies.secure\" option to false.'\n );\n cookieSettings.secure = false;\n }\n\n // Chrome >= 80 will block cookies with SameSite=None unless they are also Secure\n // If sameSite=none, but the connection is not HTTPS, set sameSite=lax.\n if (cookieSettings.sameSite === 'none' && !cookieSettings.secure) {\n cookieSettings.sameSite = 'lax';\n }\n\n return cookieSettings;\n}\n"],"file":"browser.js"}
|
|
@@ -7,17 +7,15 @@ exports.buildOptions = buildOptions;
|
|
|
7
7
|
|
|
8
8
|
var _assign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/assign"));
|
|
9
9
|
|
|
10
|
-
var _util = require("
|
|
10
|
+
var _util = require("../util");
|
|
11
11
|
|
|
12
|
-
var _builderUtil = require("
|
|
12
|
+
var _builderUtil = require("../builderUtil");
|
|
13
13
|
|
|
14
|
-
var _fetchRequest = _interopRequireDefault(require("
|
|
14
|
+
var _fetchRequest = _interopRequireDefault(require("../fetch/fetchRequest"));
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _node = require("./node");
|
|
17
17
|
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
var _features = require("./features");
|
|
18
|
+
var _features = require("../features");
|
|
21
19
|
|
|
22
20
|
/*!
|
|
23
21
|
* Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.
|
|
@@ -30,81 +28,17 @@ var _features = require("./features");
|
|
|
30
28
|
*
|
|
31
29
|
* See the License for the specific language governing permissions and limitations under the License.
|
|
32
30
|
*/
|
|
33
|
-
|
|
34
|
-
/* eslint-disable complexity */
|
|
35
|
-
const BROWSER_STORAGE = {
|
|
36
|
-
token: {
|
|
37
|
-
storageTypes: ['localStorage', 'sessionStorage', 'cookie']
|
|
38
|
-
},
|
|
39
|
-
cache: {
|
|
40
|
-
storageTypes: ['localStorage', 'sessionStorage', 'cookie']
|
|
41
|
-
},
|
|
42
|
-
transaction: {
|
|
43
|
-
storageTypes: ['sessionStorage', 'localStorage', 'cookie']
|
|
44
|
-
},
|
|
45
|
-
'shared-transaction': {
|
|
46
|
-
storageTypes: ['localStorage']
|
|
47
|
-
},
|
|
48
|
-
'original-uri': {
|
|
49
|
-
storageTypes: ['localStorage']
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
const SERVER_STORAGE = {
|
|
53
|
-
token: {
|
|
54
|
-
storageTypes: ['memory']
|
|
55
|
-
},
|
|
56
|
-
cache: {
|
|
57
|
-
storageTypes: ['memory']
|
|
58
|
-
},
|
|
59
|
-
transaction: {
|
|
60
|
-
storageTypes: ['memory']
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
function getCookieSettings(args = {}, isHTTPS) {
|
|
65
|
-
// Secure cookies will be automatically used on a HTTPS connection
|
|
66
|
-
// Non-secure cookies will be automatically used on a HTTP connection
|
|
67
|
-
// secure option can override the automatic behavior
|
|
68
|
-
var cookieSettings = args.cookies || {};
|
|
69
|
-
|
|
70
|
-
if (typeof cookieSettings.secure === 'undefined') {
|
|
71
|
-
cookieSettings.secure = isHTTPS;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (typeof cookieSettings.sameSite === 'undefined') {
|
|
75
|
-
cookieSettings.sameSite = cookieSettings.secure ? 'none' : 'lax';
|
|
76
|
-
} // If secure=true, but the connection is not HTTPS, set secure=false.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (cookieSettings.secure && !isHTTPS) {
|
|
80
|
-
// eslint-disable-next-line no-console
|
|
81
|
-
(0, _util.warn)('The current page is not being served with the HTTPS protocol.\n' + 'For security reasons, we strongly recommend using HTTPS.\n' + 'If you cannot use HTTPS, set "cookies.secure" option to false.');
|
|
82
|
-
cookieSettings.secure = false;
|
|
83
|
-
} // Chrome >= 80 will block cookies with SameSite=None unless they are also Secure
|
|
84
|
-
// If sameSite=none, but the connection is not HTTPS, set sameSite=lax.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (cookieSettings.sameSite === 'none' && !cookieSettings.secure) {
|
|
88
|
-
cookieSettings.sameSite = 'lax';
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return cookieSettings;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
31
|
function getDefaultOptions() {
|
|
95
|
-
const
|
|
96
|
-
const storageManager = (0, _features.isBrowser)() ? BROWSER_STORAGE : SERVER_STORAGE;
|
|
97
|
-
const enableSharedStorage = (0, _features.isBrowser)() ? true : false; // localStorage for multi-tab flows (browser only)
|
|
98
|
-
|
|
99
|
-
return {
|
|
32
|
+
const options = {
|
|
100
33
|
devMode: false,
|
|
101
34
|
httpRequestClient: _fetchRequest.default,
|
|
102
|
-
storageUtil,
|
|
103
|
-
storageManager,
|
|
35
|
+
storageUtil: _node.storage,
|
|
36
|
+
storageManager: _node.STORAGE_MANAGER_OPTIONS,
|
|
104
37
|
transactionManager: {
|
|
105
|
-
enableSharedStorage
|
|
38
|
+
enableSharedStorage: _node.enableSharedStorage
|
|
106
39
|
}
|
|
107
40
|
};
|
|
41
|
+
return options;
|
|
108
42
|
}
|
|
109
43
|
|
|
110
44
|
function mergeOptions(options, args) {
|
|
@@ -145,7 +79,7 @@ function buildOptions(args = {}) {
|
|
|
145
79
|
devMode: !!args.devMode,
|
|
146
80
|
storageManager: args.storageManager,
|
|
147
81
|
transactionManager: args.transactionManager,
|
|
148
|
-
cookies: (0,
|
|
82
|
+
cookies: (0, _node.getCookieSettings)(args, (0, _features.isHTTPS)()),
|
|
149
83
|
flow: args.flow,
|
|
150
84
|
codeChallenge: args.codeChallenge,
|
|
151
85
|
codeChallengeMethod: args.codeChallengeMethod,
|
|
@@ -157,4 +91,4 @@ function buildOptions(args = {}) {
|
|
|
157
91
|
clientSecret: args.clientSecret
|
|
158
92
|
});
|
|
159
93
|
}
|
|
160
|
-
//# sourceMappingURL=
|
|
94
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../lib/options/index.ts"],"names":["getDefaultOptions","options","devMode","httpRequestClient","fetchRequest","storageUtil","storage","storageManager","STORAGE_MANAGER_OPTIONS","transactionManager","enableSharedStorage","mergeOptions","args","buildOptions","issuer","tokenUrl","authorizeUrl","userinfoUrl","revokeUrl","logoutUrl","clientId","redirectUri","state","scopes","postLogoutRedirectUri","responseMode","responseType","pkce","useInteractionCodeFlow","transformErrorXHR","transformAuthState","restoreOriginalUri","headers","cookies","flow","codeChallenge","codeChallengeMethod","recoveryToken","activationToken","ignoreSignature","clientSecret"],"mappings":";;;;;;;;;AAYA;;AACA;;AAGA;;AACA;;AACA;;AAlBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAUO,SAASA,iBAAT,GAA8C;AACnD,QAAMC,OAAO,GAAG;AACdC,IAAAA,OAAO,EAAE,KADK;AAEdC,IAAAA,iBAAiB,EAAEC,qBAFL;AAGdC,IAAAA,WAAW,EAAEC,aAHC;AAIdC,IAAAA,cAAc,EAAEC,6BAJF;AAKdC,IAAAA,kBAAkB,EAAE;AAClBC,MAAAA,mBAAmB,EAAnBA;AADkB;AALN,GAAhB;AASA,SAAOT,OAAP;AACD;;AAED,SAASU,YAAT,CAAsBV,OAAtB,EAA+BW,IAA/B,EAAsD;AACpD,SAAO,qBAAc,EAAd,EAAkBX,OAAlB,EAA2B,sBAAWW,IAAX,CAA3B,EAA6C;AAClDL,IAAAA,cAAc,EAAE,qBAAc,EAAd,EAAkBN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,iBAAiB,EAAES,IAAI,CAACT,iBAnBR;AAoBhB0B,IAAAA,iBAAiB,EAAEjB,IAAI,CAACiB,iBApBR;AAqBhBC,IAAAA,kBAAkB,EAAElB,IAAI,CAACkB,kBArBT;AAsBhBC,IAAAA,kBAAkB,EAAEnB,IAAI,CAACmB,kBAtBT;AAuBhB1B,IAAAA,WAAW,EAAEO,IAAI,CAACP,WAvBF;AAwBhB2B,IAAAA,OAAO,EAAEpB,IAAI,CAACoB,OAxBE;AAyBhB9B,IAAAA,OAAO,EAAE,CAAC,CAACU,IAAI,CAACV,OAzBA;AA0BhBK,IAAAA,cAAc,EAAEK,IAAI,CAACL,cA1BL;AA2BhBE,IAAAA,kBAAkB,EAAEG,IAAI,CAACH,kBA3BT;AA4BhBwB,IAAAA,OAAO,EAAE,6BAAkBrB,IAAlB,EAAwB,wBAAxB,CA5BO;AA6BhBsB,IAAAA,IAAI,EAAEtB,IAAI,CAACsB,IA7BK;AA8BhBC,IAAAA,aAAa,EAAEvB,IAAI,CAACuB,aA9BJ;AA+BhBC,IAAAA,mBAAmB,EAAExB,IAAI,CAACwB,mBA/BV;AAgChBC,IAAAA,aAAa,EAAEzB,IAAI,CAACyB,aAhCJ;AAiChBC,IAAAA,eAAe,EAAE1B,IAAI,CAAC0B,eAjCN;AAmChB;AACAC,IAAAA,eAAe,EAAE,CAAC,CAAC3B,IAAI,CAAC2B,eApCR;AAsChB;AACAC,IAAAA,YAAY,EAAE5B,IAAI,CAAC4B;AAvCH,GAAX,CAAP;AAyCD","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\nimport { removeTrailingSlash, removeNils } from '../util';\nimport { assertValidConfig } from '../builderUtil';\nimport { OktaAuthOptions } from '../types';\n\nimport fetchRequest from '../fetch/fetchRequest';\nimport { storage, STORAGE_MANAGER_OPTIONS, enableSharedStorage, getCookieSettings } from './node';\nimport { isHTTPS } from '../features';\n\nexport function getDefaultOptions(): OktaAuthOptions {\n const options = {\n devMode: false,\n httpRequestClient: fetchRequest,\n storageUtil: storage,\n storageManager: STORAGE_MANAGER_OPTIONS,\n transactionManager: {\n enableSharedStorage\n }\n };\n return options;\n}\n\nfunction mergeOptions(options, args): OktaAuthOptions {\n return Object.assign({}, options, removeNils(args), {\n storageManager: Object.assign({}, options.storageManager, args.storageManager),\n transactionManager: Object.assign({}, options.transactionManager, args.transactionManager),\n });\n}\n\nexport function buildOptions(args: OktaAuthOptions = {}): OktaAuthOptions {\n assertValidConfig(args);\n args = mergeOptions(getDefaultOptions(), args);\n return removeNils({\n // OIDC configuration\n issuer: removeTrailingSlash(args.issuer),\n tokenUrl: removeTrailingSlash(args.tokenUrl),\n authorizeUrl: removeTrailingSlash(args.authorizeUrl),\n userinfoUrl: removeTrailingSlash(args.userinfoUrl),\n revokeUrl: removeTrailingSlash(args.revokeUrl),\n logoutUrl: removeTrailingSlash(args.logoutUrl),\n clientId: args.clientId,\n redirectUri: args.redirectUri,\n state: args.state,\n scopes: args.scopes,\n postLogoutRedirectUri: args.postLogoutRedirectUri,\n responseMode: args.responseMode,\n responseType: args.responseType,\n pkce: args.pkce === false ? false : true, // PKCE defaults to true\n useInteractionCodeFlow: args.useInteractionCodeFlow,\n\n // Internal options\n httpRequestClient: args.httpRequestClient,\n transformErrorXHR: args.transformErrorXHR,\n transformAuthState: args.transformAuthState,\n restoreOriginalUri: args.restoreOriginalUri,\n storageUtil: args.storageUtil,\n headers: args.headers,\n devMode: !!args.devMode,\n storageManager: args.storageManager,\n transactionManager: args.transactionManager,\n cookies: getCookieSettings(args, isHTTPS()),\n flow: args.flow,\n codeChallenge: args.codeChallenge,\n codeChallengeMethod: args.codeChallengeMethod,\n recoveryToken: args.recoveryToken,\n activationToken: args.activationToken,\n\n // Give the developer the ability to disable token signature validation.\n ignoreSignature: !!args.ignoreSignature,\n\n // Server-side web applications\n clientSecret: args.clientSecret\n });\n}\n"],"file":"index.js"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
exports.getCookieSettings = getCookieSettings;
|
|
6
|
+
Object.defineProperty(exports, "storage", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _serverStorage.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
exports.enableSharedStorage = exports.STORAGE_MANAGER_OPTIONS = void 0;
|
|
13
|
+
|
|
14
|
+
var _serverStorage = _interopRequireDefault(require("../server/serverStorage"));
|
|
15
|
+
|
|
16
|
+
/*!
|
|
17
|
+
* Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.
|
|
18
|
+
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
|
|
19
|
+
*
|
|
20
|
+
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
|
|
21
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
22
|
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
23
|
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24
|
+
*
|
|
25
|
+
* See the License for the specific language governing permissions and limitations under the License.
|
|
26
|
+
*/
|
|
27
|
+
const STORAGE_MANAGER_OPTIONS = {
|
|
28
|
+
token: {
|
|
29
|
+
storageTypes: ['memory']
|
|
30
|
+
},
|
|
31
|
+
cache: {
|
|
32
|
+
storageTypes: ['memory']
|
|
33
|
+
},
|
|
34
|
+
transaction: {
|
|
35
|
+
storageTypes: ['memory']
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.STORAGE_MANAGER_OPTIONS = STORAGE_MANAGER_OPTIONS;
|
|
39
|
+
const enableSharedStorage = false; // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
|
|
40
|
+
|
|
41
|
+
exports.enableSharedStorage = enableSharedStorage;
|
|
42
|
+
|
|
43
|
+
function getCookieSettings(args = {}, isHTTPS) {
|
|
44
|
+
return args.cookies;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../lib/options/node.ts"],"names":["STORAGE_MANAGER_OPTIONS","token","storageTypes","cache","transaction","enableSharedStorage","getCookieSettings","args","isHTTPS","cookies"],"mappings":";;;;;;;;;;;;;AAcA;;AAdA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMO,MAAMA,uBAA8C,GAAG;AAC5DC,EAAAA,KAAK,EAAE;AACLC,IAAAA,YAAY,EAAE,CACZ,QADY;AADT,GADqD;AAM5DC,EAAAA,KAAK,EAAE;AACLD,IAAAA,YAAY,EAAE,CACZ,QADY;AADT,GANqD;AAW5DE,EAAAA,WAAW,EAAE;AACXF,IAAAA,YAAY,EAAE,CACZ,QADY;AADH;AAX+C,CAAvD;;AAkBA,MAAMG,mBAAmB,GAAG,KAA5B,C,CAEP;;;;AACO,SAASC,iBAAT,CAA2BC,IAAqB,GAAG,EAAnD,EAAuDC,OAAvD,EAA0E;AAC/E,SAAOD,IAAI,CAACE,OAAZ;AACD","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\nimport { StorageManagerOptions, OktaAuthOptions } from '../types';\n\nexport { default as storage } from '../server/serverStorage';\n\nexport const STORAGE_MANAGER_OPTIONS: StorageManagerOptions = {\n token: {\n storageTypes: [\n 'memory'\n ]\n },\n cache: {\n storageTypes: [\n 'memory'\n ]\n },\n transaction: {\n storageTypes: [\n 'memory'\n ]\n }\n};\n\nexport const enableSharedStorage = false;\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars\nexport function getCookieSettings(args: OktaAuthOptions = {}, isHTTPS?: boolean) {\n return args.cookies;\n}\n"],"file":"node.js"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
exports.default = void 0;
|
|
4
6
|
|
|
7
|
+
var _nodeCache = _interopRequireDefault(require("node-cache"));
|
|
8
|
+
|
|
5
9
|
var _errors = require("../errors");
|
|
6
10
|
|
|
7
11
|
/*!
|
|
@@ -16,12 +20,11 @@ var _errors = require("../errors");
|
|
|
16
20
|
* See the License for the specific language governing permissions and limitations under the License.
|
|
17
21
|
*
|
|
18
22
|
*/
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
// Do not use this type in code, so it won't be emitted in the declaration output
|
|
19
25
|
// eslint-disable-next-line import/no-commonjs
|
|
20
|
-
const NodeCache = require('node-cache'); // commonJS module cannot be imported without esModuleInterop
|
|
21
26
|
// this is a SHARED memory storage to support a stateless http server
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const sharedStorage = typeof NodeCache === 'function' ? new NodeCache() : null;
|
|
27
|
+
const sharedStorage = typeof _nodeCache.default === 'function' ? new _nodeCache.default() : null;
|
|
25
28
|
|
|
26
29
|
class ServerCookies {
|
|
27
30
|
// NodeCache
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../lib/server/serverStorage.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["../../../lib/server/serverStorage.ts"],"names":["sharedStorage","NodeCache","ServerCookies","constructor","nodeCache","set","name","value","expiresAt","Date","parse","ttl","now","get","delete","del","ServerStorage","storage","testStorageType","storageType","supported","getStorageByType","storageProvider","getStorage","AuthSdkError","findStorageType","getHttpCache","getItem","setItem","key"],"mappings":";;;;;;AAeA;;AAEA;;AAjBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAIA;AAEA;AACA,MAAMA,aAAa,GAAG,OAAOC,kBAAP,KAAqB,UAArB,GAAkC,IAAIA,kBAAJ,EAAlC,GAAoD,IAA1E;;AAEA,MAAMC,aAAN,CAAuC;AACrB;AAEhBC,EAAAA,WAAW,CAACC,SAAD,EAAY;AACrB,SAAKA,SAAL,GAAiBA,SAAjB;AACD;;AAEDC,EAAAA,GAAG,CAACC,IAAD,EAAeC,KAAf,EAA8BC,SAA9B,EAAyD;AAC1D;AACA,QAAI,CAAC,CAAEC,IAAI,CAACC,KAAL,CAAWF,SAAX,CAAP,EAA+B;AAC7B;AACA,UAAIG,GAAG,GAAG,CAACF,IAAI,CAACC,KAAL,CAAWF,SAAX,IAAwBC,IAAI,CAACG,GAAL,EAAzB,IAAuC,IAAjD;AACA,WAAKR,SAAL,CAAeC,GAAf,CAAmBC,IAAnB,EAAyBC,KAAzB,EAAgCI,GAAhC;AACD,KAJD,MAIO;AACL,WAAKP,SAAL,CAAeC,GAAf,CAAmBC,IAAnB,EAAyBC,KAAzB;AACD;;AAED,WAAO,KAAKM,GAAL,CAASP,IAAT,CAAP;AACD;;AAEDO,EAAAA,GAAG,CAACP,IAAD,EAAe;AAChB,WAAO,KAAKF,SAAL,CAAeS,GAAf,CAAmBP,IAAnB,CAAP;AACD;;AAEDQ,EAAAA,MAAM,CAACR,IAAD,EAAO;AACX,WAAO,KAAKF,SAAL,CAAeW,GAAf,CAAmBT,IAAnB,CAAP;AACD;;AA1BoC,C,CA4BvC;;;AACA,MAAMU,aAAN,CAA2C;AACzB;AAEhBb,EAAAA,WAAW,CAACC,SAAD,EAAY;AACrB,SAAKA,SAAL,GAAiBA,SAAjB;AACA,SAAKa,OAAL,GAAe,IAAIf,aAAJ,CAAkBE,SAAlB,CAAf;AACD;;AAEDc,EAAAA,eAAe,CAACC,WAAD,EAAoC;AACjD,QAAIC,SAAS,GAAG,KAAhB;;AACA,YAAQD,WAAR;AACE,WAAK,QAAL;AACEC,QAAAA,SAAS,GAAG,IAAZ;AACA;;AACF;AACE;AALJ;;AAOA,WAAOA,SAAP;AACD;;AAEDC,EAAAA,gBAAgB,CAACF,WAAD,EAA0C;AACxD,QAAIG,eAAJ;;AACA,YAAQH,WAAR;AACE,WAAK,QAAL;AACEG,QAAAA,eAAe,GAAG,KAAKC,UAAL,EAAlB;AACA;;AACF;AACE,cAAM,IAAIC,oBAAJ,CAAkB,gCAA+BL,WAAY,EAA7D,CAAN;AACA;AANJ;;AAQA,WAAOG,eAAP;AACD;;AAEDG,EAAAA,eAAe,GAAgB;AAC7B,WAAO,QAAP;AACD,GAnCwC,CAqCzC;;;AACAC,EAAAA,YAAY,GAAG;AACb,WAAO,IAAP,CADa,CACA;AACd,GAxCwC,CA0CzC;;;AACAH,EAAAA,UAAU,GAAkB;AAC1B,WAAO;AACLI,MAAAA,OAAO,EAAE,KAAKvB,SAAL,CAAeS,GADnB;AAELe,MAAAA,OAAO,EAAE,CAACC,GAAD,EAAMtB,KAAN,KAAgB;AACvB,aAAKH,SAAL,CAAeC,GAAf,CAAmBwB,GAAnB,EAAwBtB,KAAxB,EAA+B,0BAA/B;AACD;AAJI,KAAP;AAMD;;AAlDwC;;eAqD5B,IAAIS,aAAJ,CAAkBhB,aAAlB,C","sourcesContent":["/*!\n * Copyright (c) 2018-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// @ts-ignore \n// Do not use this type in code, so it won't be emitted in the declaration output\nimport NodeCache from 'node-cache';\nimport { SimpleStorage, StorageType, StorageUtil, Cookies } from '../types';\nimport { AuthSdkError } from '../errors';\n// eslint-disable-next-line import/no-commonjs\n\n// this is a SHARED memory storage to support a stateless http server\nconst sharedStorage = typeof NodeCache === 'function' ? new NodeCache() : null;\n\nclass ServerCookies implements Cookies {\n nodeCache: any; // NodeCache\n \n constructor(nodeCache) {\n this.nodeCache = nodeCache;\n }\n\n set(name: string, value: string, expiresAt: string): string {\n // eslint-disable-next-line no-extra-boolean-cast\n if (!!(Date.parse(expiresAt))) {\n // Time to expiration in seconds\n var ttl = (Date.parse(expiresAt) - Date.now()) / 1000;\n this.nodeCache.set(name, value, ttl);\n } else {\n this.nodeCache.set(name, value);\n }\n\n return this.get(name);\n }\n\n get(name): string {\n return this.nodeCache.get(name);\n }\n\n delete(name) {\n return this.nodeCache.del(name);\n }\n}\n// Building this as an object allows us to mock the functions in our tests\nclass ServerStorage implements StorageUtil {\n nodeCache: any; // NodeCache\n storage: Cookies;\n constructor(nodeCache) {\n this.nodeCache = nodeCache;\n this.storage = new ServerCookies(nodeCache);\n }\n\n testStorageType(storageType: StorageType): boolean {\n var supported = false;\n switch (storageType) {\n case 'memory':\n supported = true;\n break;\n default:\n break;\n }\n return supported;\n }\n\n getStorageByType(storageType: StorageType): SimpleStorage {\n let storageProvider;\n switch (storageType) {\n case 'memory':\n storageProvider = this.getStorage();\n break;\n default:\n throw new AuthSdkError(`Unrecognized storage option: ${storageType}`);\n break;\n }\n return storageProvider;\n }\n\n findStorageType(): StorageType {\n return 'memory';\n }\n\n // will be removed in next version. OKTA-362589\n getHttpCache() {\n return null; // stubbed in server.js\n }\n\n // shared in-memory using node cache\n getStorage(): SimpleStorage {\n return {\n getItem: this.nodeCache.get,\n setItem: (key, value) => {\n this.nodeCache.set(key, value, '2200-01-01T00:00:00.000Z');\n }\n };\n }\n}\n\nexport default new ServerStorage(sharedStorage);\n"],"file":"serverStorage.js"}
|