@okta/okta-auth-js 6.3.2 → 6.4.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 +28 -0
- package/README.md +6 -0
- package/cjs/AuthStateManager.js +1 -0
- package/cjs/AuthStateManager.js.map +1 -1
- package/cjs/OktaAuth.js +10 -11
- package/cjs/OktaAuth.js.map +1 -1
- package/cjs/OktaUserAgent.js +2 -2
- package/cjs/TokenManager.js.map +1 -1
- package/cjs/crypto/verifyToken.js +2 -1
- package/cjs/crypto/verifyToken.js.map +1 -1
- package/cjs/errors/AuthApiError.js.map +1 -1
- package/cjs/errors/OAuthError.js +7 -1
- package/cjs/errors/OAuthError.js.map +1 -1
- package/cjs/fetch/fetchRequest.js +17 -3
- package/cjs/fetch/fetchRequest.js.map +1 -1
- package/cjs/http/request.js +7 -3
- package/cjs/http/request.js.map +1 -1
- package/cjs/idx/idxState/index.js +55 -0
- package/cjs/idx/idxState/index.js.map +1 -0
- package/cjs/idx/{idx-js → idxState}/v1/actionParser.js +1 -0
- package/cjs/idx/idxState/v1/actionParser.js.map +1 -0
- package/cjs/idx/{idx-js → idxState}/v1/generateIdxAction.js +43 -30
- package/cjs/idx/idxState/v1/generateIdxAction.js.map +1 -0
- package/cjs/idx/{idx-js → idxState}/v1/idxResponseParser.js +8 -8
- package/cjs/idx/idxState/v1/idxResponseParser.js.map +1 -0
- package/cjs/idx/{idx-js → idxState}/v1/makeIdxState.js +3 -2
- package/cjs/idx/idxState/v1/makeIdxState.js.map +1 -0
- package/cjs/idx/{idx-js → idxState}/v1/parsers.js +1 -0
- package/cjs/idx/idxState/v1/parsers.js.map +1 -0
- package/cjs/idx/{idx-js → idxState}/v1/remediationParser.js +4 -2
- package/cjs/idx/idxState/v1/remediationParser.js.map +1 -0
- package/cjs/idx/interact.js +42 -21
- package/cjs/idx/interact.js.map +1 -1
- package/cjs/idx/introspect.js +37 -12
- package/cjs/idx/introspect.js.map +1 -1
- package/cjs/idx/remediate.js +56 -132
- package/cjs/idx/remediate.js.map +1 -1
- package/cjs/idx/remediators/AuthenticatorEnrollmentData.js.map +1 -1
- package/cjs/idx/remediators/AuthenticatorVerificationData.js +7 -6
- package/cjs/idx/remediators/AuthenticatorVerificationData.js.map +1 -1
- package/cjs/idx/remediators/Base/AuthenticatorData.js.map +1 -1
- package/cjs/idx/remediators/Base/Remediator.js +12 -2
- package/cjs/idx/remediators/Base/Remediator.js.map +1 -1
- package/cjs/idx/remediators/Base/SelectAuthenticator.js.map +1 -1
- package/cjs/idx/remediators/Base/VerifyAuthenticator.js.map +1 -1
- package/cjs/idx/remediators/ChallengeAuthenticator.js.map +1 -1
- package/cjs/idx/remediators/EnrollAuthenticator.js.map +1 -1
- package/cjs/idx/remediators/EnrollPoll.js.map +1 -1
- package/cjs/idx/remediators/EnrollProfile.js.map +1 -1
- package/cjs/idx/remediators/EnrollmentChannelData.js.map +1 -1
- package/cjs/idx/remediators/Identify.js.map +1 -1
- package/cjs/idx/remediators/ReEnrollAuthenticator.js.map +1 -1
- package/cjs/idx/remediators/ResetAuthenticator.js.map +1 -1
- package/cjs/idx/remediators/SelectAuthenticatorAuthenticate.js.map +1 -1
- package/cjs/idx/remediators/SelectAuthenticatorEnroll.js.map +1 -1
- package/cjs/idx/remediators/SelectAuthenticatorUnlockAccount.js.map +1 -1
- package/cjs/idx/remediators/SelectEnrollProfile.js.map +1 -1
- package/cjs/idx/remediators/SelectEnrollmentChannel.js.map +1 -1
- package/cjs/idx/remediators/Skip.js.map +1 -1
- package/cjs/idx/run.js +16 -12
- package/cjs/idx/run.js.map +1 -1
- package/cjs/idx/types/idx-js.js +2 -0
- package/cjs/idx/types/idx-js.js.map +1 -1
- package/cjs/idx/types/index.js +0 -138
- package/cjs/idx/types/index.js.map +1 -1
- package/cjs/idx/util.js +127 -5
- package/cjs/idx/util.js.map +1 -1
- package/cjs/server/serverStorage.js +1 -0
- package/cjs/server/serverStorage.js.map +1 -1
- package/cjs/tx/AuthTransaction.js.map +1 -1
- package/cjs/types/Token.js +0 -1
- package/cjs/types/Token.js.map +1 -1
- package/cjs/util/object.js.map +1 -1
- package/cjs/util/types.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/esm.browser.js +599 -684
- package/esm/esm.browser.js.map +1 -1
- package/esm/esm.node.mjs +599 -684
- package/esm/esm.node.mjs.map +1 -1
- package/lib/TokenManager.d.ts +2 -2
- package/lib/errors/OAuthError.d.ts +2 -0
- package/lib/idx/flow/RemediationFlow.d.ts +2 -2
- package/lib/idx/idxState/index.d.ts +7 -0
- package/lib/idx/{idx-js → idxState}/v1/actionParser.d.ts +0 -0
- package/lib/idx/{idx-js → idxState}/v1/generateIdxAction.d.ts +3 -1
- package/lib/idx/{idx-js → idxState}/v1/idxResponseParser.d.ts +3 -2
- package/lib/idx/{idx-js → idxState}/v1/makeIdxState.d.ts +3 -2
- package/lib/idx/{idx-js → idxState}/v1/parsers.d.ts +0 -0
- package/lib/idx/{idx-js → idxState}/v1/remediationParser.d.ts +2 -1
- package/lib/idx/interact.d.ts +22 -0
- package/lib/idx/remediate.d.ts +9 -12
- package/lib/idx/remediators/AuthenticatorEnrollmentData.d.ts +1 -2
- package/lib/idx/remediators/AuthenticatorVerificationData.d.ts +3 -3
- package/lib/idx/remediators/Base/AuthenticatorData.d.ts +3 -4
- package/lib/idx/remediators/Base/Remediator.d.ts +8 -4
- package/lib/idx/remediators/Base/SelectAuthenticator.d.ts +2 -3
- package/lib/idx/remediators/Base/VerifyAuthenticator.d.ts +3 -4
- package/lib/idx/remediators/ChallengeAuthenticator.d.ts +1 -2
- package/lib/idx/remediators/EnrollAuthenticator.d.ts +1 -2
- package/lib/idx/remediators/EnrollPoll.d.ts +1 -2
- package/lib/idx/remediators/EnrollProfile.d.ts +1 -2
- package/lib/idx/remediators/EnrollmentChannelData.d.ts +1 -2
- package/lib/idx/remediators/Identify.d.ts +1 -2
- package/lib/idx/remediators/ReEnrollAuthenticator.d.ts +1 -2
- package/lib/idx/remediators/ResetAuthenticator.d.ts +1 -2
- package/lib/idx/remediators/SelectAuthenticatorAuthenticate.d.ts +1 -2
- package/lib/idx/remediators/SelectAuthenticatorEnroll.d.ts +1 -2
- package/lib/idx/remediators/SelectAuthenticatorUnlockAccount.d.ts +1 -2
- package/lib/idx/remediators/SelectEnrollProfile.d.ts +1 -2
- package/lib/idx/remediators/SelectEnrollmentChannel.d.ts +1 -2
- package/lib/idx/remediators/Skip.d.ts +1 -2
- package/lib/idx/types/idx-js.d.ts +5 -2
- package/lib/idx/types/index.d.ts +26 -17
- package/lib/idx/util.d.ts +7 -4
- package/lib/types/EventEmitter.d.ts +3 -3
- package/lib/types/Service.d.ts +6 -6
- package/lib/types/Storage.d.ts +6 -6
- package/lib/types/TokenManager.d.ts +5 -2
- package/lib/types/UserClaims.d.ts +1 -1
- package/lib/util/types.d.ts +1 -1
- package/package.json +9 -10
- package/cjs/idx/headers.js +0 -59
- package/cjs/idx/headers.js.map +0 -1
- package/cjs/idx/idx-js/client.js +0 -91
- package/cjs/idx/idx-js/client.js.map +0 -1
- package/cjs/idx/idx-js/index.js +0 -40
- package/cjs/idx/idx-js/index.js.map +0 -1
- package/cjs/idx/idx-js/interact.js +0 -83
- package/cjs/idx/idx-js/interact.js.map +0 -1
- package/cjs/idx/idx-js/introspect.js +0 -62
- package/cjs/idx/idx-js/introspect.js.map +0 -1
- package/cjs/idx/idx-js/parsers.js +0 -41
- package/cjs/idx/idx-js/parsers.js.map +0 -1
- package/cjs/idx/idx-js/util.js +0 -34
- package/cjs/idx/idx-js/util.js.map +0 -1
- package/cjs/idx/idx-js/v1/actionParser.js.map +0 -1
- package/cjs/idx/idx-js/v1/generateIdxAction.js.map +0 -1
- package/cjs/idx/idx-js/v1/idxResponseParser.js.map +0 -1
- package/cjs/idx/idx-js/v1/makeIdxState.js.map +0 -1
- package/cjs/idx/idx-js/v1/parsers.js.map +0 -1
- package/cjs/idx/idx-js/v1/remediationParser.js.map +0 -1
- package/lib/idx/headers.d.ts +0 -16
- package/lib/idx/idx-js/client.d.ts +0 -36
- package/lib/idx/idx-js/index.d.ts +0 -35
- package/lib/idx/idx-js/interact.d.ts +0 -25
- package/lib/idx/idx-js/introspect.d.ts +0 -21
- package/lib/idx/idx-js/parsers.d.ts +0 -15
- package/lib/idx/idx-js/util.d.ts +0 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../lib/crypto/verifyToken.ts"],"names":["verifyToken","idToken","key","format","algo","name","hash","extractable","usages","use","webcrypto","subtle","importKey","then","cryptoKey","jwt","split","payload","b64Signature","signature","verify"],"mappings":";;;;AAYA;;AACA;;AACA;;AAdA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMO,SAASA,WAAT,CAAqBC,OAArB,EAA8BC,GAA9B,EAAmC;AACxCA,EAAAA,GAAG,GAAG,iBAAMA,GAAN,CAAN;AAEA,MAAIC,MAAM,GAAG,KAAb;AACA,MAAIC,IAAI,GAAG;AACTC,IAAAA,IAAI,EAAE,mBADG;AAETC,IAAAA,IAAI,EAAE;AAAED,MAAAA,IAAI,EAAE;AAAR;AAFG,GAAX;AAIA,MAAIE,WAAW,GAAG,IAAlB;AACA,MAAIC,MAAM,GAAG,CAAC,QAAD,CAAb,CATwC,CAWxC;AACA;AACA;;AACA,SAAON,GAAG,CAACO,GAAX,CAdwC,CAgBxC;;AACA,SAAOC,qBAAUC,MAAV,CAAiBC,SAAjB,CACLT,MADK,EAELD,GAFK,EAGLE,IAHK,EAILG,WAJK,EAKLC,MALK,EAONK,IAPM,CAOD,UAASC,SAAT,EAAoB;AACxB,QAAIC,GAAG,GAAGd,OAAO,CAACe,KAAR,CAAc,GAAd,CAAV;AACA,QAAIC,OAAO,GAAG,0BAAeF,GAAG,CAAC,CAAD,CAAH,GAAS,GAAT,GAAeA,GAAG,CAAC,CAAD,CAAjC,CAAd;AACA,QAAIG,YAAY,GAAG,2BAAgBH,GAAG,CAAC,CAAD,CAAnB,CAAnB;AACA,QAAII,SAAS,GAAG,0BAAeD,YAAf,CAAhB;AAEA,WAAOR,qBAAUC,MAAV,CAAiBS,MAAjB,CACLhB,IADK,EAELU,SAFK,EAGLK,SAHK,EAILF,OAJK,CAAP;AAMD,GAnBM,CAAP;AAoBD","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 { clone } from '../util';\nimport { stringToBuffer, base64UrlDecode } from './base64';\nimport { webcrypto } from './webcrypto';\n\nexport function verifyToken(idToken, key) {\n key = clone(key);\n\n var format = 'jwk';\n var algo = {\n name: 'RSASSA-PKCS1-v1_5',\n hash: { name: 'SHA-256' }\n };\n var extractable = true;\n var usages = ['verify'];\n\n // https://connect.microsoft.com/IE/feedback/details/2242108/webcryptoapi-importing-jwk-with-use-field-fails\n // This is a metadata tag that specifies the intent of how the key should be used.\n // It's not necessary to properly verify the jwt's signature.\n delete key.use;\n\n // @ts-ignore\n return webcrypto.subtle.importKey(\n format,\n key,\n algo,\n extractable,\n usages\n )\n .then(function(cryptoKey) {\n var jwt = idToken.split('.');\n var payload = stringToBuffer(jwt[0] + '.' + jwt[1]);\n var b64Signature = base64UrlDecode(jwt[2]);\n var signature = stringToBuffer(b64Signature);\n\n return webcrypto.subtle.verify(\n algo,\n cryptoKey,\n signature,\n payload\n );\n });\n}\n\n"],"file":"verifyToken.js"}
|
|
1
|
+
{"version":3,"sources":["../../../lib/crypto/verifyToken.ts"],"names":["verifyToken","idToken","key","format","algo","name","hash","extractable","usages","use","webcrypto","subtle","importKey","then","cryptoKey","jwt","split","payload","b64Signature","signature","verify"],"mappings":";;;;AAYA;;AACA;;AACA;;AAdA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMO,SAASA,WAAT,CAAqBC,OAArB,EAA8BC,GAA9B,EAAmC;AACxCA,EAAAA,GAAG,GAAG,iBAAMA,GAAN,CAAN;AAEA,MAAIC,MAAM,GAAG,KAAb;AACA,MAAIC,IAAI,GAAG;AACTC,IAAAA,IAAI,EAAE,mBADG;AAETC,IAAAA,IAAI,EAAE;AAAED,MAAAA,IAAI,EAAE;AAAR;AAFG,GAAX;AAIA,MAAIE,WAAW,GAAG,IAAlB;AACA,MAAIC,MAAM,GAAG,CAAC,QAAD,CAAb,CATwC,CAWxC;AACA;AACA;;AACA,SAAON,GAAG,CAACO,GAAX,CAdwC,CAgBxC;AACA;;AACA,SAAOC,qBAAUC,MAAV,CAAiBC,SAAjB,CACLT,MADK,EAELD,GAFK,EAGLE,IAHK,EAILG,WAJK,EAKLC,MALK,EAONK,IAPM,CAOD,UAASC,SAAT,EAAoB;AACxB,QAAIC,GAAG,GAAGd,OAAO,CAACe,KAAR,CAAc,GAAd,CAAV;AACA,QAAIC,OAAO,GAAG,0BAAeF,GAAG,CAAC,CAAD,CAAH,GAAS,GAAT,GAAeA,GAAG,CAAC,CAAD,CAAjC,CAAd;AACA,QAAIG,YAAY,GAAG,2BAAgBH,GAAG,CAAC,CAAD,CAAnB,CAAnB;AACA,QAAII,SAAS,GAAG,0BAAeD,YAAf,CAAhB;AAEA,WAAOR,qBAAUC,MAAV,CAAiBS,MAAjB,CACLhB,IADK,EAELU,SAFK,EAGLK,SAHK,EAILF,OAJK,CAAP;AAMD,GAnBM,CAAP;AAoBD","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 { clone } from '../util';\nimport { stringToBuffer, base64UrlDecode } from './base64';\nimport { webcrypto } from './webcrypto';\n\nexport function verifyToken(idToken, key) {\n key = clone(key);\n\n var format = 'jwk';\n var algo = {\n name: 'RSASSA-PKCS1-v1_5',\n hash: { name: 'SHA-256' }\n };\n var extractable = true;\n var usages = ['verify'];\n\n // https://connect.microsoft.com/IE/feedback/details/2242108/webcryptoapi-importing-jwk-with-use-field-fails\n // This is a metadata tag that specifies the intent of how the key should be used.\n // It's not necessary to properly verify the jwt's signature.\n delete key.use;\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return webcrypto.subtle.importKey(\n format,\n key,\n algo,\n extractable,\n usages\n )\n .then(function(cryptoKey) {\n var jwt = idToken.split('.');\n var payload = stringToBuffer(jwt[0] + '.' + jwt[1]);\n var b64Signature = base64UrlDecode(jwt[2]);\n var signature = stringToBuffer(b64Signature);\n\n return webcrypto.subtle.verify(\n algo,\n cryptoKey,\n signature,\n payload\n );\n });\n}\n\n"],"file":"verifyToken.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../lib/errors/AuthApiError.ts"],"names":["AuthApiError","CustomError","constructor","err","xhr","message","errorSummary","name","errorCode","errorLink","errorId","errorCauses"],"mappings":";;;;;;AAYA;;AAZA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;
|
|
1
|
+
{"version":3,"sources":["../../../lib/errors/AuthApiError.ts"],"names":["AuthApiError","CustomError","constructor","err","xhr","message","errorSummary","name","errorCode","errorLink","errorId","errorCauses"],"mappings":";;;;;;AAYA;;AAZA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAKe,MAAMA,YAAN,SAA2BC,oBAA3B,CAA2D;AAQxEC,EAAAA,WAAW,CAACC,GAAD,EAAgBC,GAAhB,EAAoC;AAC7C,UAAMC,OAAO,GAAGF,GAAG,CAACG,YAApB;AACA,UAAMD,OAAN;AAEA,SAAKE,IAAL,GAAY,cAAZ;AACA,SAAKD,YAAL,GAAoBH,GAAG,CAACG,YAAxB;AACA,SAAKE,SAAL,GAAiBL,GAAG,CAACK,SAArB;AACA,SAAKC,SAAL,GAAiBN,GAAG,CAACM,SAArB;AACA,SAAKC,OAAL,GAAeP,GAAG,CAACO,OAAnB;AACA,SAAKC,WAAL,GAAmBR,GAAG,CAACQ,WAAvB;;AAEA,QAAIP,GAAJ,EAAS;AACP,WAAKA,GAAL,GAAWA,GAAX;AACD;AACF;;AAtBuE","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 CustomError from './CustomError';\nimport { APIError, HttpResponse } from '../types';\n\nexport default class AuthApiError extends CustomError implements APIError {\n errorSummary: string;\n errorCode?: string;\n errorLink?: string;\n errorId?: string;\n errorCauses?: string[];\n xhr?: HttpResponse;\n\n constructor(err: APIError, xhr?: HttpResponse) {\n const message = err.errorSummary;\n super(message);\n\n this.name = 'AuthApiError';\n this.errorSummary = err.errorSummary;\n this.errorCode = err.errorCode;\n this.errorLink = err.errorLink;\n this.errorId = err.errorId;\n this.errorCauses = err.errorCauses;\n\n if (xhr) {\n this.xhr = xhr;\n }\n }\n}\n"],"file":"AuthApiError.js"}
|
package/cjs/errors/OAuthError.js
CHANGED
|
@@ -6,6 +6,8 @@ exports.default = void 0;
|
|
|
6
6
|
|
|
7
7
|
var _CustomError = _interopRequireDefault(require("./CustomError"));
|
|
8
8
|
|
|
9
|
+
/* eslint-disable camelcase */
|
|
10
|
+
|
|
9
11
|
/*!
|
|
10
12
|
* Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.
|
|
11
13
|
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
|
|
@@ -18,11 +20,15 @@ var _CustomError = _interopRequireDefault(require("./CustomError"));
|
|
|
18
20
|
* See the License for the specific language governing permissions and limitations under the License.
|
|
19
21
|
*/
|
|
20
22
|
class OAuthError extends _CustomError.default {
|
|
23
|
+
// for widget / idx-js backward compatibility
|
|
21
24
|
constructor(errorCode, summary) {
|
|
22
25
|
super(summary);
|
|
23
26
|
this.name = 'OAuthError';
|
|
24
27
|
this.errorCode = errorCode;
|
|
25
|
-
this.errorSummary = summary;
|
|
28
|
+
this.errorSummary = summary; // for widget / idx-js backward compatibility
|
|
29
|
+
|
|
30
|
+
this.error = errorCode;
|
|
31
|
+
this.error_description = summary;
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../lib/errors/OAuthError.ts"],"names":["OAuthError","CustomError","constructor","errorCode","summary","name","errorSummary"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"sources":["../../../lib/errors/OAuthError.ts"],"names":["OAuthError","CustomError","constructor","errorCode","summary","name","errorSummary","error","error_description"],"mappings":";;;;;;AAaA;;AAbA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIe,MAAMA,UAAN,SAAyBC,oBAAzB,CAAqC;AAIlD;AAIAC,EAAAA,WAAW,CAACC,SAAD,EAAoBC,OAApB,EAAqC;AAC9C,UAAMA,OAAN;AAEA,SAAKC,IAAL,GAAY,YAAZ;AACA,SAAKF,SAAL,GAAiBA,SAAjB;AACA,SAAKG,YAAL,GAAoBF,OAApB,CAL8C,CAO9C;;AACA,SAAKG,KAAL,GAAaJ,SAAb;AACA,SAAKK,iBAAL,GAAyBJ,OAAzB;AACD;;AAlBiD","sourcesContent":["/* eslint-disable camelcase */\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\nimport CustomError from './CustomError';\n\nexport default class OAuthError extends CustomError {\n errorCode: string;\n errorSummary: string;\n\n // for widget / idx-js backward compatibility\n error: string;\n error_description: string;\n\n constructor(errorCode: string, summary: string) {\n super(summary);\n\n this.name = 'OAuthError';\n this.errorCode = errorCode;\n this.errorSummary = summary;\n\n // for widget / idx-js backward compatibility\n this.error = errorCode;\n this.error_description = summary;\n }\n}\n\n"],"file":"OAuthError.js"}
|
|
@@ -10,6 +10,10 @@ var _entries = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-st
|
|
|
10
10
|
|
|
11
11
|
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
|
|
12
12
|
|
|
13
|
+
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
14
|
+
|
|
15
|
+
var _entries2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/entries"));
|
|
16
|
+
|
|
13
17
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
14
18
|
|
|
15
19
|
var _crossFetch = _interopRequireDefault(require("cross-fetch"));
|
|
@@ -25,6 +29,9 @@ var _crossFetch = _interopRequireDefault(require("cross-fetch"));
|
|
|
25
29
|
*
|
|
26
30
|
* See the License for the specific language governing permissions and limitations under the License.
|
|
27
31
|
*/
|
|
32
|
+
// content-type = application/json OR application/ion+json
|
|
33
|
+
const appJsonContentTypeRegex = /application\/\w*\+?json/;
|
|
34
|
+
|
|
28
35
|
function readData(response) {
|
|
29
36
|
var _context;
|
|
30
37
|
|
|
@@ -71,10 +78,17 @@ function formatResult(status, data, response) {
|
|
|
71
78
|
function fetchRequest(method, url, args) {
|
|
72
79
|
var body = args.data;
|
|
73
80
|
var headers = args.headers || {};
|
|
74
|
-
var contentType = headers['Content-Type'] || headers['content-type'] || '';
|
|
81
|
+
var contentType = headers['Content-Type'] || headers['content-type'] || '';
|
|
82
|
+
|
|
83
|
+
if (body && typeof body !== 'string') {
|
|
84
|
+
// JSON encode body (if appropriate)
|
|
85
|
+
if (appJsonContentTypeRegex.test(contentType)) {
|
|
86
|
+
body = (0, _stringify.default)(body);
|
|
87
|
+
} else if (contentType === 'application/x-www-form-urlencoded') {
|
|
88
|
+
var _context3;
|
|
75
89
|
|
|
76
|
-
|
|
77
|
-
|
|
90
|
+
body = (0, _map.default)(_context3 = (0, _entries2.default)(body)).call(_context3, ([param, value]) => `${param}=${encodeURIComponent(value)}`).join('&');
|
|
91
|
+
}
|
|
78
92
|
}
|
|
79
93
|
|
|
80
94
|
var fetch = global.fetch || _crossFetch.default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../lib/fetch/fetchRequest.ts"],"names":["readData","response","headers","get","toLowerCase","json","catch","e","error","errorSummary","text","formatResult","status","data","isObject","pair","result","responseText","responseType","responseJSON","fetchRequest","method","url","args","body","contentType","fetch","global","crossFetch","fetchPromise","credentials","withCredentials","finally","resolve","then","ok"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../lib/fetch/fetchRequest.ts"],"names":["appJsonContentTypeRegex","readData","response","headers","get","toLowerCase","json","catch","e","error","errorSummary","text","formatResult","status","data","isObject","pair","result","responseText","responseType","responseJSON","fetchRequest","method","url","args","body","contentType","test","param","value","encodeURIComponent","join","fetch","global","crossFetch","fetchPromise","credentials","withCredentials","finally","resolve","then","ok"],"mappings":";;;;;;;;;;;;;;;;;;AAYA;;AAZA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAKA;AACA,MAAMA,uBAAuB,GAAG,yBAAhC;;AAEA,SAASC,QAAT,CAAkBC,QAAlB,EAAgE;AAAA;;AAC9D,MAAIA,QAAQ,CAACC,OAAT,CAAiBC,GAAjB,CAAqB,cAArB,KACF;AACA,mCAAAF,QAAQ,CAACC,OAAT,CAAiBC,GAAjB,CAAqB,cAArB,EAAsCC,WAAtC,mBAA4D,kBAA5D,KAAmF,CAFrF,EAEwF;AACxF,WAAOH,QAAQ,CAACI,IAAT,GACL;AADK,KAEJC,KAFI,CAEEC,CAAC,IAAI;AACV,aAAO;AACLC,QAAAA,KAAK,EAAED,CADF;AAELE,QAAAA,YAAY,EAAE;AAFT,OAAP;AAID,KAPI,CAAP;AAQC,GAXD,MAWO;AACL,WAAOR,QAAQ,CAACS,IAAT,EAAP;AACD;AACF;;AAED,SAASC,YAAT,CAAsBC,MAAtB,EAAsCC,IAAtC,EAA6DZ,QAA7D,EAAiF;AAC/E,QAAMa,QAAQ,GAAG,OAAOD,IAAP,KAAgB,QAAjC;AACA,QAAMX,OAAO,GAAG,EAAhB;;AACA,OAAK,MAAMa,IAAX,IAAmB,kCAACd,QAAQ,CAACC,OAAV,iBAAnB,EAAwD;AAAA;;AACtDA,IAAAA,OAAO,CAACa,IAAI,CAAC,CAAD,CAAL,CAAP,GAAmBA,IAAI,CAAC,CAAD,CAAvB;AACD;;AACD,QAAMC,MAAoB,GAAG;AAC3BC,IAAAA,YAAY,EAAEH,QAAQ,GAAG,wBAAeD,IAAf,CAAH,GAA0BA,IADrB;AAE3BD,IAAAA,MAAM,EAAEA,MAFmB;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,YAAY,CAACG,OAAlB,EAA2B;AACzBH,IAAAA,YAAY,GAAG,iBAAQI,OAAR,CAAgBJ,YAAhB,CAAf;AACD;;AAED,SAAOA,YAAY,CAACK,IAAb,CAAkB,UAAStC,QAAT,EAAmB;AAC1C,QAAIO,KAAK,GAAG,CAACP,QAAQ,CAACuC,EAAtB;AACA,QAAI5B,MAAM,GAAGX,QAAQ,CAACW,MAAtB;AACA,WAAOZ,QAAQ,CAACC,QAAD,CAAR,CACJsC,IADI,CACC1B,IAAI,IAAI;AACZ,aAAOF,YAAY,CAACC,MAAD,EAASC,IAAT,EAAeZ,QAAf,CAAnB;AACD,KAHI,EAIJsC,IAJI,CAICvB,MAAM,IAAI;AAAA;;AACd,UAAIR,KAAK,4BAAIQ,MAAM,CAACG,YAAX,iDAAI,qBAAqBX,KAAlC,EAAyC;AACvC;AACA,cAAMQ,MAAN;AACD;;AACD,aAAOA,MAAP;AACD,KAVI,CAAP;AAWD,GAdM,CAAP;AAeD;;eAEcI,Y","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\nimport crossFetch from 'cross-fetch';\nimport { FetchOptions, HttpResponse } from '../types';\n\n// content-type = application/json OR application/ion+json\nconst appJsonContentTypeRegex = /application\\/\\w*\\+?json/;\n\nfunction readData(response: Response): Promise<object | string> {\n if (response.headers.get('Content-Type') &&\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n response.headers.get('Content-Type')!.toLowerCase().indexOf('application/json') >= 0) {\n return response.json()\n // JSON parse can fail if response is not a valid object\n .catch(e => {\n return {\n error: e,\n errorSummary: 'Could not parse server response'\n };\n });\n } else {\n return response.text();\n }\n}\n\nfunction formatResult(status: number, data: object | string, response: Response) {\n const isObject = typeof data === 'object';\n const headers = {};\n for (const pair of (response.headers as any).entries()) {\n headers[pair[0]] = pair[1];\n }\n const result: HttpResponse = {\n responseText: isObject ? JSON.stringify(data) : data as string,\n status: status,\n headers\n };\n if (isObject) {\n result.responseType = 'json';\n result.responseJSON = data as object;\n }\n return result;\n}\n\n/* eslint-disable complexity */\nfunction fetchRequest(method: string, url: string, args: FetchOptions) {\n var body = args.data;\n var headers = args.headers || {};\n var contentType = (headers['Content-Type'] || headers['content-type'] || '');\n\n if (body && typeof body !== 'string') {\n // JSON encode body (if appropriate)\n if (appJsonContentTypeRegex.test(contentType)) {\n body = JSON.stringify(body);\n }\n else if (contentType === 'application/x-www-form-urlencoded') {\n body = Object.entries(body)\n .map( ([param, value]) => `${param}=${encodeURIComponent(value)}` )\n .join('&');\n }\n }\n\n var fetch = global.fetch || crossFetch;\n var fetchPromise = fetch(url, {\n method: method,\n headers: args.headers,\n body: body as string,\n credentials: args.withCredentials ? 'include' : 'omit'\n });\n\n if (!fetchPromise.finally) {\n fetchPromise = Promise.resolve(fetchPromise);\n }\n\n return fetchPromise.then(function(response) {\n var error = !response.ok;\n var status = response.status;\n return readData(response)\n .then(data => {\n return formatResult(status, data, response);\n })\n .then(result => {\n if (error || result.responseJSON?.error) {\n // Throwing result object since error handling is done in http.js\n throw result;\n }\n return result;\n });\n });\n}\n\nexport default fetchRequest;\n"],"file":"fetchRequest.js"}
|
package/cjs/http/request.js
CHANGED
|
@@ -12,10 +12,10 @@ var _assign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-sta
|
|
|
12
12
|
|
|
13
13
|
var _util = require("../util");
|
|
14
14
|
|
|
15
|
-
var _AuthApiError = _interopRequireDefault(require("../errors/AuthApiError"));
|
|
16
|
-
|
|
17
15
|
var _constants = require("../constants");
|
|
18
16
|
|
|
17
|
+
var _errors = require("../errors");
|
|
18
|
+
|
|
19
19
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
20
20
|
|
|
21
21
|
/*!
|
|
@@ -124,7 +124,11 @@ function httpRequest(sdk, options) {
|
|
|
124
124
|
resp = sdk.options.transformErrorXHR((0, _util.clone)(resp));
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
if (serverErr.error && serverErr.error_description) {
|
|
128
|
+
err = new _errors.OAuthError(serverErr.error, serverErr.error_description);
|
|
129
|
+
} else {
|
|
130
|
+
err = new _errors.AuthApiError(serverErr, resp);
|
|
131
|
+
}
|
|
128
132
|
|
|
129
133
|
if (err.errorCode === 'E0000011') {
|
|
130
134
|
storage.delete(_constants.STATE_TOKEN_KEY_NAME);
|
package/cjs/http/request.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../lib/http/request.ts"],"names":["httpRequest","sdk","options","url","method","args","saveAuthnState","accessToken","withCredentials","storageUtil","storage","httpCache","storageManager","getHttpCache","cookies","cacheResponse","cacheContents","getStorage","cachedResponse","Date","now","expiresAt","resolve","response","oktaUserAgentHeader","_oktaUserAgent","getHttpHeader","headers","ajaxOptions","data","undefined","err","res","httpRequestClient","then","resp","responseText","JSON","parse","stateToken","delete","STATE_TOKEN_KEY_NAME","set","updateStorage","Math","floor","DEFAULT_CACHE_DURATION","catch","serverErr","e","errorSummary","status","transformErrorXHR","AuthApiError","errorCode","get","getIssuerOrigin","getOptions","post","postOptions"],"mappings":";;;;;;;;;;;;AAeA;;AACA;;
|
|
1
|
+
{"version":3,"sources":["../../../lib/http/request.ts"],"names":["httpRequest","sdk","options","url","method","args","saveAuthnState","accessToken","withCredentials","storageUtil","storage","httpCache","storageManager","getHttpCache","cookies","cacheResponse","cacheContents","getStorage","cachedResponse","Date","now","expiresAt","resolve","response","oktaUserAgentHeader","_oktaUserAgent","getHttpHeader","headers","ajaxOptions","data","undefined","err","res","httpRequestClient","then","resp","responseText","JSON","parse","stateToken","delete","STATE_TOKEN_KEY_NAME","set","updateStorage","Math","floor","DEFAULT_CACHE_DURATION","catch","serverErr","e","errorSummary","status","transformErrorXHR","error","error_description","OAuthError","AuthApiError","errorCode","get","getIssuerOrigin","getOptions","post","postOptions"],"mappings":";;;;;;;;;;;;AAeA;;AACA;;AAEA;;AAlBA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AAMO,SAASA,WAAT,CAAqBC,GAArB,EAA6CC,OAA7C,EAAoF;AACzFA,EAAAA,OAAO,GAAGA,OAAO,IAAI,EAArB;AACA,MAAIC,GAAG,GAAGD,OAAO,CAACC,GAAlB;AAAA,MACIC,MAAM,GAAGF,OAAO,CAACE,MADrB;AAAA,MAEIC,IAAI,GAAGH,OAAO,CAACG,IAFnB;AAAA,MAGIC,cAAc,GAAGJ,OAAO,CAACI,cAH7B;AAAA,MAIIC,WAAW,GAAGL,OAAO,CAACK,WAJ1B;AAAA,MAKIC,eAAe,GAAGN,OAAO,CAACM,eAAR,KAA4B,IALlD;AAAA,MAKwD;AACpDC,EAAAA,WAAW,GAAGR,GAAG,CAACC,OAAJ,CAAYO,WAN9B;AAAA,MAOIC,OAAO,GAAGD,WAAW,CAAEC,OAP3B;AAAA,MAQIC,SAAS,GAAGV,GAAG,CAACW,cAAJ,CAAmBC,YAAnB,CAAgCZ,GAAG,CAACC,OAAJ,CAAYY,OAA5C,CARhB;;AAUA,MAAIZ,OAAO,CAACa,aAAZ,EAA2B;AACzB,QAAIC,aAAa,GAAGL,SAAS,CAACM,UAAV,EAApB;AACA,QAAIC,cAAc,GAAGF,aAAa,CAACb,GAAD,CAAlC;;AACA,QAAIe,cAAc,IAAIC,IAAI,CAACC,GAAL,KAAW,IAAX,GAAkBF,cAAc,CAACG,SAAvD,EAAkE;AAChE,aAAO,iBAAQC,OAAR,CAAgBJ,cAAc,CAACK,QAA/B,CAAP;AACD;AACF;;AAED,MAAIC,mBAAmB,GAAGv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N;AACD,KAFD,MAEO;AACLvB,MAAAA,GAAG,GAAG,IAAIyB,oBAAJ,CAAiBR,SAAjB,EAA4Bb,IAA5B,CAAN;AACD;;AAED,QAAIJ,GAAG,CAAC0B,SAAJ,KAAkB,UAAtB,EAAkC;AAChC/C,MAAAA,OAAO,CAAC8B,MAAR,CAAeC,+BAAf;AACD;;AAED,UAAMV,GAAN;AACD,GA5DI,CAAP;AA6DD;;AAEM,SAAS2B,GAAT,CAAazD,GAAb,EAAqCE,GAArC,EAAkDD,OAAlD,EAA4E;AACjFC,EAAAA,GAAG,GAAG,yBAAcA,GAAd,IAAqBA,GAArB,GAA2BF,GAAG,CAAC0D,eAAJ,KAAwBxD,GAAzD;AACA,MAAIyD,UAAU,GAAG;AACfzD,IAAAA,GAAG,EAAEA,GADU;AAEfC,IAAAA,MAAM,EAAE;AAFO,GAAjB;AAIA,uBAAcwD,UAAd,EAA0B1D,OAA1B;AACA,SAAOF,WAAW,CAACC,GAAD,EAAM2D,UAAN,CAAlB;AACD;;AAEM,SAASC,IAAT,CAAc5D,GAAd,EAAsCE,GAAtC,EAAmDE,IAAnD,EAAuEH,OAAvE,EAAiG;AACtGC,EAAAA,GAAG,GAAG,yBAAcA,GAAd,IAAqBA,GAArB,GAA2BF,GAAG,CAAC0D,eAAJ,KAAwBxD,GAAzD;AACA,MAAI2D,WAAW,GAAG;AAChB3D,IAAAA,GAAG,EAAEA,GADW;AAEhBC,IAAAA,MAAM,EAAE,MAFQ;AAGhBC,IAAAA,IAAI,EAAEA,IAHU;AAIhBC,IAAAA,cAAc,EAAE;AAJA,GAAlB;AAMA,uBAAcwD,WAAd,EAA2B5D,OAA3B;AACA,SAAOF,WAAW,CAACC,GAAD,EAAM6D,WAAN,CAAlB;AACD","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\n/* eslint-disable complexity */\nimport { isString, clone, isAbsoluteUrl, removeNils } from '../util';\nimport { STATE_TOKEN_KEY_NAME, DEFAULT_CACHE_DURATION } from '../constants';\nimport { OktaAuthInterface, RequestOptions, FetchOptions, RequestData } from '../types';\nimport { AuthApiError, OAuthError } from '../errors';\n\nexport function httpRequest(sdk: OktaAuthInterface, options: RequestOptions): Promise<any> {\n options = options || {};\n var url = options.url,\n method = options.method,\n args = options.args,\n saveAuthnState = options.saveAuthnState,\n accessToken = options.accessToken,\n withCredentials = options.withCredentials === true, // default value is false\n storageUtil = sdk.options.storageUtil,\n storage = storageUtil!.storage,\n httpCache = sdk.storageManager.getHttpCache(sdk.options.cookies);\n\n if (options.cacheResponse) {\n var cacheContents = httpCache.getStorage();\n var cachedResponse = cacheContents[url as string];\n if (cachedResponse && Date.now()/1000 < cachedResponse.expiresAt) {\n return Promise.resolve(cachedResponse.response);\n }\n }\n\n var oktaUserAgentHeader = sdk._oktaUserAgent.getHttpHeader();\n var headers: HeadersInit = {\n 'Accept': 'application/json',\n 'Content-Type': 'application/json',\n ...oktaUserAgentHeader\n };\n Object.assign(headers, sdk.options.headers, options.headers);\n headers = removeNils(headers) as HeadersInit;\n\n if (accessToken && isString(accessToken)) {\n headers['Authorization'] = 'Bearer ' + accessToken;\n }\n\n var ajaxOptions: FetchOptions = {\n headers,\n data: args || undefined,\n withCredentials\n };\n\n var err, res;\n return sdk.options.httpRequestClient!(method!, url!, ajaxOptions)\n .then(function(resp) {\n res = resp.responseText;\n if (res && isString(res)) {\n res = JSON.parse(res);\n if (res && typeof res === 'object' && !res.headers) {\n res.headers = resp.headers;\n }\n }\n\n if (saveAuthnState) {\n if (!res.stateToken) {\n storage.delete(STATE_TOKEN_KEY_NAME);\n }\n }\n\n if (res && res.stateToken && res.expiresAt) {\n storage.set(STATE_TOKEN_KEY_NAME, res.stateToken, res.expiresAt, sdk.options.cookies!);\n }\n\n if (res && options.cacheResponse) {\n httpCache.updateStorage(url!, {\n expiresAt: Math.floor(Date.now()/1000) + DEFAULT_CACHE_DURATION,\n response: res\n });\n }\n\n return res;\n })\n .catch(function(resp) {\n var serverErr = resp.responseText || {};\n if (isString(serverErr)) {\n try {\n serverErr = JSON.parse(serverErr);\n } catch (e) {\n serverErr = {\n errorSummary: 'Unknown error'\n };\n }\n }\n\n if (resp.status >= 500) {\n serverErr.errorSummary = 'Unknown error';\n }\n\n if (sdk.options.transformErrorXHR) {\n resp = sdk.options.transformErrorXHR(clone(resp));\n }\n\n if (serverErr.error && serverErr.error_description) {\n err = new OAuthError(serverErr.error, serverErr.error_description);\n } else {\n err = new AuthApiError(serverErr, resp);\n }\n\n if (err.errorCode === 'E0000011') {\n storage.delete(STATE_TOKEN_KEY_NAME);\n }\n\n throw err;\n });\n}\n\nexport function get(sdk: OktaAuthInterface, url: string, options?: RequestOptions) {\n url = isAbsoluteUrl(url) ? url : sdk.getIssuerOrigin() + url;\n var getOptions = {\n url: url,\n method: 'GET'\n };\n Object.assign(getOptions, options);\n return httpRequest(sdk, getOptions);\n}\n\nexport function post(sdk: OktaAuthInterface, url: string, args?: RequestData, options?: RequestOptions) {\n url = isAbsoluteUrl(url) ? url : sdk.getIssuerOrigin() + url;\n var postOptions = {\n url: url,\n method: 'POST',\n args: args,\n saveAuthnState: true\n };\n Object.assign(postOptions, options);\n return httpRequest(sdk, postOptions);\n}\n"],"file":"request.js"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
exports.validateVersionConfig = validateVersionConfig;
|
|
6
|
+
exports.makeIdxState = makeIdxState;
|
|
7
|
+
exports.parsersForVersion = void 0;
|
|
8
|
+
|
|
9
|
+
var _constants = require("../../constants");
|
|
10
|
+
|
|
11
|
+
var _parsers = _interopRequireDefault(require("./v1/parsers"));
|
|
12
|
+
|
|
13
|
+
// auth-js/types
|
|
14
|
+
// idx/types
|
|
15
|
+
const parsersForVersion = function parsersForVersion(version) {
|
|
16
|
+
switch (version) {
|
|
17
|
+
case '1.0.0':
|
|
18
|
+
return _parsers.default;
|
|
19
|
+
|
|
20
|
+
case undefined:
|
|
21
|
+
case null:
|
|
22
|
+
throw new Error('Api version is required');
|
|
23
|
+
|
|
24
|
+
default:
|
|
25
|
+
throw new Error(`Unknown api version: ${version}. Use an exact semver version.`);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.parsersForVersion = parsersForVersion;
|
|
30
|
+
|
|
31
|
+
function validateVersionConfig(version) {
|
|
32
|
+
if (!version) {
|
|
33
|
+
throw new Error('version is required');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const cleanVersion = (version !== null && version !== void 0 ? version : '').replace(/[^0-9a-zA-Z._-]/, '');
|
|
37
|
+
|
|
38
|
+
if (cleanVersion !== version || !version) {
|
|
39
|
+
throw new Error('invalid version supplied - version is required and uses semver syntax');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
parsersForVersion(version); // will throw for invalid version
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function makeIdxState(authClient, rawIdxResponse, toPersist = {}, requestDidSucceed) {
|
|
46
|
+
var _rawIdxResponse$versi;
|
|
47
|
+
|
|
48
|
+
const version = (_rawIdxResponse$versi = rawIdxResponse === null || rawIdxResponse === void 0 ? void 0 : rawIdxResponse.version) !== null && _rawIdxResponse$versi !== void 0 ? _rawIdxResponse$versi : _constants.IDX_API_VERSION;
|
|
49
|
+
validateVersionConfig(version);
|
|
50
|
+
const {
|
|
51
|
+
makeIdxState
|
|
52
|
+
} = parsersForVersion(version);
|
|
53
|
+
return makeIdxState(authClient, rawIdxResponse, toPersist, requestDidSucceed);
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../lib/idx/idxState/index.ts"],"names":["parsersForVersion","version","v1","undefined","Error","validateVersionConfig","cleanVersion","replace","makeIdxState","authClient","rawIdxResponse","toPersist","requestDidSucceed","IDX_API_VERSION"],"mappings":";;;;;;;;AAEA;;AACA;;AAHoD;AACgB;AAK7D,MAAMA,iBAAiB,GAAG,SAASA,iBAAT,CAA4BC,OAA5B,EAAsC;AACrE,UAAQA,OAAR;AACE,SAAK,OAAL;AACE,aAAOC,gBAAP;;AACF,SAAKC,SAAL;AACA,SAAK,IAAL;AACE,YAAM,IAAIC,KAAJ,CAAU,yBAAV,CAAN;;AACF;AACE,YAAM,IAAIA,KAAJ,CAAW,wBAAuBH,OAAQ,iCAA1C,CAAN;AAPJ;AASD,CAVM;;;;AAYA,SAASI,qBAAT,CAA+BJ,OAA/B,EAAwC;AAC7C,MAAK,CAACA,OAAN,EAAgB;AACd,UAAM,IAAIG,KAAJ,CAAU,qBAAV,CAAN;AACD;;AAED,QAAME,YAAY,GAAG,CAACL,OAAD,aAACA,OAAD,cAACA,OAAD,GAAY,EAAZ,EAAgBM,OAAhB,CAAwB,iBAAxB,EAA2C,EAA3C,CAArB;;AACA,MAAKD,YAAY,KAAKL,OAAjB,IAA4B,CAACA,OAAlC,EAA4C;AAC1C,UAAM,IAAIG,KAAJ,CAAU,uEAAV,CAAN;AACD;;AAEDJ,EAAAA,iBAAiB,CAACC,OAAD,CAAjB,CAV6C,CAUjB;AAC7B;;AAEM,SAASO,YAAT,CACLC,UADK,EAELC,cAFK,EAGLC,SAAkC,GAAG,EAHhC,EAILC,iBAJK,EAKQ;AAAA;;AACb,QAAMX,OAAO,4BAAGS,cAAH,aAAGA,cAAH,uBAAGA,cAAc,CAAET,OAAnB,yEAA8BY,0BAA3C;AACAR,EAAAA,qBAAqB,CAACJ,OAAD,CAArB;AAEA,QAAM;AAAEO,IAAAA;AAAF,MAAmBR,iBAAiB,CAACC,OAAD,CAA1C;AACA,SAAOO,YAAY,CAACC,UAAD,EAAaC,cAAb,EAA6BC,SAA7B,EAAwCC,iBAAxC,CAAnB;AACD","sourcesContent":["import { OktaAuthInterface } from '../../types'; // auth-js/types\nimport { IdxResponse, RawIdxResponse } from '../types/idx-js'; // idx/types\nimport { IDX_API_VERSION } from '../../constants';\nimport v1 from './v1/parsers';\n\n\nexport const parsersForVersion = function parsersForVersion( version ) {\n switch (version) {\n case '1.0.0':\n return v1;\n case undefined:\n case null:\n throw new Error('Api version is required');\n default:\n throw new Error(`Unknown api version: ${version}. Use an exact semver version.`);\n }\n};\n\nexport function validateVersionConfig(version) {\n if ( !version ) {\n throw new Error('version is required');\n }\n\n const cleanVersion = (version ?? '').replace(/[^0-9a-zA-Z._-]/, '');\n if ( cleanVersion !== version || !version ) {\n throw new Error('invalid version supplied - version is required and uses semver syntax');\n }\n\n parsersForVersion(version); // will throw for invalid version\n}\n\nexport function makeIdxState ( \n authClient: OktaAuthInterface,\n rawIdxResponse: RawIdxResponse,\n toPersist: Record<string, unknown> = {},\n requestDidSucceed: boolean,\n): IdxResponse {\n const version = rawIdxResponse?.version ?? IDX_API_VERSION;\n validateVersionConfig(version);\n \n const { makeIdxState } = parsersForVersion(version);\n return makeIdxState(authClient, rawIdxResponse, toPersist, requestDidSucceed);\n}\n"],"file":"index.js"}
|
|
@@ -13,6 +13,7 @@ exports.divideActionParamsByMutability = void 0;
|
|
|
13
13
|
*
|
|
14
14
|
* See the License for the specific language governing permissions and limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
16
17
|
// @ts-nocheck
|
|
17
18
|
const isFieldMutable = function isFieldMutable(field) {
|
|
18
19
|
// mutable defaults to true, annoyingly
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../lib/idx/idxState/v1/actionParser.ts"],"names":["isFieldMutable","field","mutable","divideSingleActionParamsByMutability","action","defaultParamsForAction","neededParamsForAction","immutableParamsForAction","value","push","name","divideActionParamsByMutability","actionList","Array","isArray","neededParams","defaultParams","immutableParams"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA,MAAMA,cAAc,GAAG,SAASA,cAAT,CAAwBC,KAAxB,EAA+B;AACpD;AACA,SAASA,KAAK,CAACC,OAAN,KAAkB,KAA3B;AACD,CAHD;;AAKA,MAAMC,oCAAoC,GAAG,SAASA,oCAAT,CAA+CC,MAA/C,EAAwD;AACnG,QAAMC,sBAAsB,GAAG,EAA/B,CADmG,CAChE;;AACnC,QAAMC,qBAAqB,GAAG,EAA9B,CAFmG,CAEjE;;AAClC,QAAMC,wBAAwB,GAAG,EAAjC,CAHmG,CAG9D;AACrC;AACA;AACA;;AACA,MAAI,CAACH,MAAM,CAACI,KAAZ,EAAmB;AACjBF,IAAAA,qBAAqB,CAACG,IAAtB,CAA2BL,MAA3B;AACA,WAAO;AAAEC,MAAAA,sBAAF;AAA0BC,MAAAA,qBAA1B;AAAiDC,MAAAA;AAAjD,KAAP;AACD;;AAED,OAAM,IAAIN,KAAV,IAAmBG,MAAM,CAACI,KAA1B,EAAkC;AAEhC,QAAKR,cAAc,CAAEC,KAAF,CAAnB,EAA+B;AAAA;;AAE7BK,MAAAA,qBAAqB,CAACG,IAAtB,CAA2BR,KAA3B;;AAEA,0BAAKA,KAAK,CAACO,KAAX,uDAAoB,KAApB,EAA4B;AAC1BH,QAAAA,sBAAsB,CAACJ,KAAK,CAACS,IAAP,CAAtB,GAAqCT,KAAK,CAACO,KAA3C;AACD;AAEF,KARD,MAQO;AAAA;;AACLD,MAAAA,wBAAwB,CAACN,KAAK,CAACS,IAAP,CAAxB,oBAAuCT,KAAK,CAACO,KAA7C,yDAAsD,EAAtD;AACD;AACF;;AACD,SAAO;AAAEH,IAAAA,sBAAF;AAA0BC,IAAAA,qBAA1B;AAAiDC,IAAAA;AAAjD,GAAP;AACD,CA3BD;;AA6BO,MAAMI,8BAA8B,GAAG,SAASA,8BAAT,CAAyCC,UAAzC,EAAsD;AAClG;AACAA,EAAAA,UAAU,GAAGC,KAAK,CAACC,OAAN,CAAcF,UAAd,IAA4BA,UAA5B,GAAyC,CAAEA,UAAF,CAAtD;AACA,QAAMG,YAAY,GAAG,EAArB;AACA,QAAMC,aAAa,GAAG,EAAtB;AACA,QAAMC,eAAe,GAAG,EAAxB;;AAEA,OAAM,IAAIb,MAAV,IAAoBQ,UAApB,EAAiC;AAC/B,UAAM;AACJP,MAAAA,sBADI;AAEJC,MAAAA,qBAFI;AAGJC,MAAAA;AAHI,QAIFJ,oCAAoC,CAACC,MAAD,CAJxC;AAKAW,IAAAA,YAAY,CAACN,IAAb,CAAkBH,qBAAlB;AACAU,IAAAA,aAAa,CAACZ,MAAM,CAACM,IAAR,CAAb,GAA6BL,sBAA7B;AACAY,IAAAA,eAAe,CAACb,MAAM,CAACM,IAAR,CAAf,GAA+BH,wBAA/B;AACD;;AAED,SAAO;AAAES,IAAAA,aAAF;AAAiBD,IAAAA,YAAjB;AAA+BE,IAAAA;AAA/B,GAAP;AACD,CAnBM","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\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-nocheck\nconst isFieldMutable = function isFieldMutable(field) {\n // mutable defaults to true, annoyingly\n return ( field.mutable !== false );\n};\n\nconst divideSingleActionParamsByMutability = function divideSingleActionParamsByMutability( action ) {\n const defaultParamsForAction = {}; // mutable and present\n const neededParamsForAction = []; // mutable values\n const immutableParamsForAction = {}; // immutable\n // TODO: remove assumption that form names are unique, neededParams being an array is a temp fix\n // not all actions have value (e.g. redirect)\n // making sure they are not empty and instead hold the remediation object\n if (!action.value) {\n neededParamsForAction.push(action);\n return { defaultParamsForAction, neededParamsForAction, immutableParamsForAction };\n }\n\n for ( let field of action.value ) {\n\n if ( isFieldMutable( field ) ) {\n\n neededParamsForAction.push(field);\n\n if ( field.value ?? false ) {\n defaultParamsForAction[field.name] = field.value;\n }\n\n } else {\n immutableParamsForAction[field.name] = field.value ?? '';\n }\n }\n return { defaultParamsForAction, neededParamsForAction, immutableParamsForAction };\n};\n\nexport const divideActionParamsByMutability = function divideActionParamsByMutability( actionList ) {\n // TODO: when removing form name is unique assumption, this may all be redundant\n actionList = Array.isArray(actionList) ? actionList : [ actionList ];\n const neededParams = [];\n const defaultParams = {};\n const immutableParams = {};\n\n for ( let action of actionList ) {\n const { \n defaultParamsForAction, \n neededParamsForAction, \n immutableParamsForAction \n } = divideSingleActionParamsByMutability(action);\n neededParams.push(neededParamsForAction);\n defaultParams[action.name] = defaultParamsForAction;\n immutableParams[action.name] = immutableParamsForAction;\n }\n\n return { defaultParams, neededParams, immutableParams };\n};\n\n"],"file":"actionParser.js"}
|
|
@@ -6,12 +6,14 @@ exports.default = void 0;
|
|
|
6
6
|
|
|
7
7
|
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _http = require("../../../http");
|
|
10
10
|
|
|
11
11
|
var _actionParser = require("./actionParser");
|
|
12
12
|
|
|
13
13
|
var _makeIdxState = require("./makeIdxState");
|
|
14
14
|
|
|
15
|
+
var _AuthApiError = _interopRequireDefault(require("../../../errors/AuthApiError"));
|
|
16
|
+
|
|
15
17
|
/*!
|
|
16
18
|
* Copyright (c) 2021-Present, Okta, Inc. and/or its affiliates. All rights reserved.
|
|
17
19
|
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
|
|
@@ -24,49 +26,60 @@ var _makeIdxState = require("./makeIdxState");
|
|
|
24
26
|
* See the License for the specific language governing permissions and limitations under the License.
|
|
25
27
|
*/
|
|
26
28
|
|
|
27
|
-
/* eslint-disable max-len */
|
|
29
|
+
/* eslint-disable max-len, complexity */
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
28
31
|
// @ts-nocheck
|
|
29
|
-
const generateDirectFetch = function generateDirectFetch({
|
|
32
|
+
const generateDirectFetch = function generateDirectFetch(authClient, {
|
|
30
33
|
actionDefinition,
|
|
31
34
|
defaultParamsForAction = {},
|
|
32
35
|
immutableParamsForAction = {},
|
|
33
|
-
toPersist
|
|
36
|
+
toPersist = {}
|
|
34
37
|
}) {
|
|
35
38
|
const target = actionDefinition.href;
|
|
36
|
-
return async function (params) {
|
|
39
|
+
return async function (params = {}) {
|
|
37
40
|
const headers = {
|
|
38
|
-
'
|
|
39
|
-
'
|
|
41
|
+
'Content-Type': 'application/json',
|
|
42
|
+
'Accept': actionDefinition.accepts || 'application/ion+json'
|
|
40
43
|
};
|
|
41
44
|
const body = (0, _stringify.default)({ ...defaultParamsForAction,
|
|
42
45
|
...params,
|
|
43
46
|
...immutableParamsForAction
|
|
44
47
|
});
|
|
45
|
-
const credentials = toPersist && toPersist.withCredentials === false ? 'omit' : 'include';
|
|
46
|
-
const response = await (0, _client.request)(target, {
|
|
47
|
-
method: actionDefinition.method,
|
|
48
|
-
headers,
|
|
49
|
-
body,
|
|
50
|
-
credentials
|
|
51
|
-
});
|
|
52
|
-
const responseJSON = await response.json();
|
|
53
|
-
const requestDidSucceed = response.ok;
|
|
54
|
-
const idxResponse = (0, _makeIdxState.makeIdxState)(responseJSON, toPersist, requestDidSucceed);
|
|
55
48
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
49
|
+
try {
|
|
50
|
+
var _toPersist$withCreden;
|
|
51
|
+
|
|
52
|
+
const response = await (0, _http.httpRequest)(authClient, {
|
|
53
|
+
url: target,
|
|
54
|
+
method: actionDefinition.method,
|
|
55
|
+
headers,
|
|
56
|
+
args: body,
|
|
57
|
+
withCredentials: (_toPersist$withCreden = toPersist === null || toPersist === void 0 ? void 0 : toPersist.withCredentials) !== null && _toPersist$withCreden !== void 0 ? _toPersist$withCreden : true
|
|
58
|
+
});
|
|
59
|
+
return (0, _makeIdxState.makeIdxState)(authClient, { ...response
|
|
60
|
+
}, toPersist, true);
|
|
61
|
+
} catch (err) {
|
|
62
|
+
if (!(err instanceof _AuthApiError.default) || !(err !== null && err !== void 0 && err.xhr)) {
|
|
63
|
+
throw err;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const response = err.xhr;
|
|
67
|
+
const payload = response.responseJSON || JSON.parse(response.responseText);
|
|
68
|
+
const wwwAuthHeader = response.headers['WWW-Authenticate'] || response.headers['www-authenticate'];
|
|
69
|
+
const idxResponse = (0, _makeIdxState.makeIdxState)(authClient, { ...payload
|
|
70
|
+
}, toPersist, false);
|
|
71
|
+
|
|
72
|
+
if (response.status === 401 && wwwAuthHeader === 'Oktadevicejwt realm="Okta Device"') {
|
|
73
|
+
// Okta server responds 401 status code with WWW-Authenticate header and new remediation
|
|
74
|
+
// so that the iOS/MacOS credential SSO extension (Okta Verify) can intercept
|
|
75
|
+
// the response reaches here when Okta Verify is not installed
|
|
76
|
+
// set `stepUp` to true if flow should be continued without showing any errors
|
|
77
|
+
idxResponse.stepUp = true;
|
|
78
|
+
} // Throw IDX response if request did not succeed. This behavior will be removed in version 7.0: OKTA-481844
|
|
63
79
|
|
|
64
80
|
|
|
65
|
-
if (!requestDidSucceed) {
|
|
66
81
|
throw idxResponse;
|
|
67
82
|
}
|
|
68
|
-
|
|
69
|
-
return idxResponse;
|
|
70
83
|
};
|
|
71
84
|
}; // TODO: Resolve in M2: Either build the final polling solution or remove this code
|
|
72
85
|
// const generatePollingFetch = function generatePollingFetch( { actionDefinition, defaultParamsForAction = {}, immutableParamsForAction = {} } ) {
|
|
@@ -81,12 +94,12 @@ const generateDirectFetch = function generateDirectFetch({
|
|
|
81
94
|
// body: JSON.stringify({ ...defaultParamsForAction, ...params, ...immutableParamsForAction })
|
|
82
95
|
// })
|
|
83
96
|
// .then( response => response.ok ? response.json() : response.json().then( err => Promise.reject(err)) )
|
|
84
|
-
// .then( idxResponse => makeIdxState(idxResponse) );
|
|
97
|
+
// .then( idxResponse => makeIdxState(authClient, idxResponse) );
|
|
85
98
|
// };
|
|
86
99
|
// };
|
|
87
100
|
|
|
88
101
|
|
|
89
|
-
const generateIdxAction = function generateIdxAction(actionDefinition, toPersist) {
|
|
102
|
+
const generateIdxAction = function generateIdxAction(authClient, actionDefinition, toPersist) {
|
|
90
103
|
// TODO: leaving this here to see where the polling is EXPECTED to drop into the code, but removing any accidental trigger of incomplete code
|
|
91
104
|
// const generator = actionDefinition.refresh ? generatePollingFetch : generateDirectFetch;
|
|
92
105
|
const generator = generateDirectFetch;
|
|
@@ -95,7 +108,7 @@ const generateIdxAction = function generateIdxAction(actionDefinition, toPersist
|
|
|
95
108
|
neededParams,
|
|
96
109
|
immutableParams
|
|
97
110
|
} = (0, _actionParser.divideActionParamsByMutability)(actionDefinition);
|
|
98
|
-
const action = generator({
|
|
111
|
+
const action = generator(authClient, {
|
|
99
112
|
actionDefinition,
|
|
100
113
|
defaultParamsForAction: defaultParams[actionDefinition.name],
|
|
101
114
|
immutableParamsForAction: immutableParams[actionDefinition.name],
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../lib/idx/idxState/v1/generateIdxAction.ts"],"names":["generateDirectFetch","authClient","actionDefinition","defaultParamsForAction","immutableParamsForAction","toPersist","target","href","params","headers","accepts","body","response","url","method","args","withCredentials","err","AuthApiError","xhr","payload","responseJSON","JSON","parse","responseText","wwwAuthHeader","idxResponse","status","stepUp","generateIdxAction","generator","defaultParams","neededParams","immutableParams","action","name"],"mappings":";;;;;;;;AAeA;;AAGA;;AACA;;AACA;;AApBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AAQA,MAAMA,mBAAmB,GAAG,SAASA,mBAAT,CAA6BC,UAA7B,EAA4D;AACtFC,EAAAA,gBADsF;AAEtFC,EAAAA,sBAAsB,GAAG,EAF6D;AAGtFC,EAAAA,wBAAwB,GAAG,EAH2D;AAItFC,EAAAA,SAAS,GAAG;AAJ0E,CAA5D,EAKzB;AACD,QAAMC,MAAM,GAAGJ,gBAAgB,CAACK,IAAhC;AACA,SAAO,gBAAeC,MAAuB,GAAG,EAAzC,EAAmE;AACxE,UAAMC,OAAO,GAAG;AACd,sBAAgB,kBADF;AAEd,gBAAUP,gBAAgB,CAACQ,OAAjB,IAA4B;AAFxB,KAAhB;AAIA,UAAMC,IAAI,GAAG,wBAAe,EAC1B,GAAGR,sBADuB;AAE1B,SAAGK,MAFuB;AAG1B,SAAGJ;AAHuB,KAAf,CAAb;;AAMA,QAAI;AAAA;;AACF,YAAMQ,QAAQ,GAAG,MAAM,uBAAYX,UAAZ,EAAwB;AAC7CY,QAAAA,GAAG,EAAEP,MADwC;AAE7CQ,QAAAA,MAAM,EAAEZ,gBAAgB,CAACY,MAFoB;AAG7CL,QAAAA,OAH6C;AAI7CM,QAAAA,IAAI,EAAEJ,IAJuC;AAK7CK,QAAAA,eAAe,2BAAEX,SAAF,aAAEA,SAAF,uBAAEA,SAAS,CAAEW,eAAb,yEAAgC;AALF,OAAxB,CAAvB;AAQA,aAAO,gCAAaf,UAAb,EAAyB,EAAE,GAAGW;AAAL,OAAzB,EAA0CP,SAA1C,EAAqD,IAArD,CAAP;AACD,KAVD,CAWA,OAAOY,GAAP,EAAY;AACV,UAAI,EAAE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E6B,eAAe,CAAC/B,gBAAgB,CAACiC,IAAlB,CAHN;AAInC9B,IAAAA;AAJmC,GAAb,CAAxB;AAMA6B,EAAAA,MAAM,CAACF,YAAP,GAAsBA,YAAtB;AACA,SAAOE,MAAP;AACD,CAdD;;eAgBeL,iB","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\n/* eslint-disable max-len, complexity */\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-nocheck\nimport { httpRequest } from '../../../http';\nimport { OktaAuthInterface } from '../../../types'; // auth-js/types\nimport { IdxActionParams } from '../../types/idx-js';\nimport { divideActionParamsByMutability } from './actionParser';\nimport { makeIdxState } from './makeIdxState';\nimport AuthApiError from '../../../errors/AuthApiError';\n\nconst generateDirectFetch = function generateDirectFetch(authClient: OktaAuthInterface, { \n actionDefinition, \n defaultParamsForAction = {}, \n immutableParamsForAction = {}, \n toPersist = {}\n}) {\n const target = actionDefinition.href;\n return async function(params: IdxActionParams = {}): Promise<IdxResponse> {\n const headers = {\n 'Content-Type': 'application/json',\n 'Accept': actionDefinition.accepts || 'application/ion+json',\n };\n const body = JSON.stringify({\n ...defaultParamsForAction,\n ...params,\n ...immutableParamsForAction\n });\n\n try {\n const response = await httpRequest(authClient, {\n url: target,\n method: actionDefinition.method,\n headers,\n args: body,\n withCredentials: toPersist?.withCredentials ?? true\n });\n\n return makeIdxState(authClient, { ...response }, toPersist, true);\n }\n catch (err) {\n if (!(err instanceof AuthApiError) || !err?.xhr) {\n throw err;\n }\n\n const response = err.xhr;\n const payload = response.responseJSON || JSON.parse(response.responseText);\n const wwwAuthHeader = response.headers['WWW-Authenticate'] || response.headers['www-authenticate'];\n\n const idxResponse = makeIdxState(authClient, { ...payload }, toPersist, false);\n if (response.status === 401 && wwwAuthHeader === 'Oktadevicejwt realm=\"Okta Device\"') {\n // Okta server responds 401 status code with WWW-Authenticate header and new remediation\n // so that the iOS/MacOS credential SSO extension (Okta Verify) can intercept\n // the response reaches here when Okta Verify is not installed\n // set `stepUp` to true if flow should be continued without showing any errors\n idxResponse.stepUp = true;\n }\n\n // Throw IDX response if request did not succeed. This behavior will be removed in version 7.0: OKTA-481844\n throw idxResponse;\n }\n };\n};\n\n// TODO: Resolve in M2: Either build the final polling solution or remove this code\n// const generatePollingFetch = function generatePollingFetch( { actionDefinition, defaultParamsForAction = {}, immutableParamsForAction = {} } ) {\n// // TODO: Discussions ongoing about when/how to terminate polling: OKTA-246581\n// const target = actionDefinition.href;\n// return async function(params) {\n// return fetch(target, {\n// method: actionDefinition.method,\n// headers: {\n// 'content-type': actionDefinition.accepts,\n// },\n// body: JSON.stringify({ ...defaultParamsForAction, ...params, ...immutableParamsForAction })\n// })\n// .then( response => response.ok ? response.json() : response.json().then( err => Promise.reject(err)) )\n// .then( idxResponse => makeIdxState(authClient, idxResponse) );\n// };\n// };\n\nconst generateIdxAction = function generateIdxAction( authClient: OktaAuthInterface, actionDefinition, toPersist ) {\n // TODO: leaving this here to see where the polling is EXPECTED to drop into the code, but removing any accidental trigger of incomplete code\n // const generator = actionDefinition.refresh ? generatePollingFetch : generateDirectFetch;\n const generator = generateDirectFetch;\n const { defaultParams, neededParams, immutableParams } = divideActionParamsByMutability( actionDefinition );\n\n const action = generator(authClient, {\n actionDefinition,\n defaultParamsForAction: defaultParams[actionDefinition.name],\n immutableParamsForAction: immutableParams[actionDefinition.name],\n toPersist\n });\n action.neededParams = neededParams;\n return action;\n};\n\nexport default generateIdxAction;\n"],"file":"generateIdxAction.js"}
|
|
@@ -26,7 +26,7 @@ const SKIP_FIELDS = (0, _fromEntries.default)((0, _map.default)(_context = ['rem
|
|
|
26
26
|
'context' // the API response of 'context' isn't externally useful. We ignore it and put all non-action (contextual) info into idxState.context
|
|
27
27
|
]).call(_context, field => [field, !!'skip this field']));
|
|
28
28
|
|
|
29
|
-
const parseNonRemediations = function parseNonRemediations(idxResponse, toPersist = {}) {
|
|
29
|
+
const parseNonRemediations = function parseNonRemediations(authClient, idxResponse, toPersist = {}) {
|
|
30
30
|
var _context2;
|
|
31
31
|
|
|
32
32
|
const actions = {};
|
|
@@ -42,7 +42,7 @@ const parseNonRemediations = function parseNonRemediations(idxResponse, toPersis
|
|
|
42
42
|
|
|
43
43
|
if (idxResponse[field].rel) {
|
|
44
44
|
// top level actions
|
|
45
|
-
actions[idxResponse[field].name] = (0, _generateIdxAction.default)(idxResponse[field], toPersist);
|
|
45
|
+
actions[idxResponse[field].name] = (0, _generateIdxAction.default)(authClient, idxResponse[field], toPersist);
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -68,7 +68,7 @@ const parseNonRemediations = function parseNonRemediations(idxResponse, toPersis
|
|
|
68
68
|
if (value.rel) {
|
|
69
69
|
// is [field].value[subField] an action?
|
|
70
70
|
// add any "action" value subfields to actions
|
|
71
|
-
actions[`${field}-${subField.name || subField}`] = (0, _generateIdxAction.default)(value, toPersist);
|
|
71
|
+
actions[`${field}-${subField.name || subField}`] = (0, _generateIdxAction.default)(authClient, value, toPersist);
|
|
72
72
|
} else {
|
|
73
73
|
// add non-action value subfields to context
|
|
74
74
|
context[field].value[subField] = value;
|
|
@@ -108,24 +108,24 @@ const expandRelatesTo = (idxResponse, value) => {
|
|
|
108
108
|
});
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
-
const convertRemediationAction = (remediation, toPersist) => {
|
|
112
|
-
const remediationActions = (0, _remediationParser.generateRemediationFunctions)([remediation], toPersist);
|
|
111
|
+
const convertRemediationAction = (authClient, remediation, toPersist) => {
|
|
112
|
+
const remediationActions = (0, _remediationParser.generateRemediationFunctions)(authClient, [remediation], toPersist);
|
|
113
113
|
const actionFn = remediationActions[remediation.name];
|
|
114
114
|
return { ...remediation,
|
|
115
115
|
action: actionFn
|
|
116
116
|
};
|
|
117
117
|
};
|
|
118
118
|
|
|
119
|
-
const parseIdxResponse = function parseIdxResponse(idxResponse, toPersist = {}) {
|
|
119
|
+
const parseIdxResponse = function parseIdxResponse(authClient, idxResponse, toPersist = {}) {
|
|
120
120
|
var _idxResponse$remediat;
|
|
121
121
|
|
|
122
122
|
const remediationData = ((_idxResponse$remediat = idxResponse.remediation) === null || _idxResponse$remediat === void 0 ? void 0 : _idxResponse$remediat.value) || [];
|
|
123
123
|
remediationData.forEach(remediation => expandRelatesTo(idxResponse, remediation));
|
|
124
|
-
const remediations = (0, _map.default)(remediationData).call(remediationData, remediation => convertRemediationAction(remediation, toPersist));
|
|
124
|
+
const remediations = (0, _map.default)(remediationData).call(remediationData, remediation => convertRemediationAction(authClient, remediation, toPersist));
|
|
125
125
|
const {
|
|
126
126
|
context,
|
|
127
127
|
actions
|
|
128
|
-
} = parseNonRemediations(idxResponse, toPersist);
|
|
128
|
+
} = parseNonRemediations(authClient, idxResponse, toPersist);
|
|
129
129
|
return {
|
|
130
130
|
remediations,
|
|
131
131
|
context,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../lib/idx/idxState/v1/idxResponseParser.ts"],"names":["SKIP_FIELDS","field","parseNonRemediations","authClient","idxResponse","toPersist","actions","context","forEach","fieldIsObject","rel","name","value","fieldValue","type","info","subField","expandRelatesTo","k","query","Array","isArray","result","path","json","innerValue","convertRemediationAction","remediation","remediationActions","actionFn","action","parseIdxResponse","remediationData","remediations"],"mappings":";;;;;;;;;;;;;;;;AAgBA;;AACA;;AACA;;;;AAEA,MAAMA,WAAW,GAAG,0BAAmB,8BACrC,aADqC,EACtB;AACf,SAFqC,CAE1B;AAF0B,kBAG/BC,KAAD,IAAW,CAAEA,KAAF,EAAS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UAAU,IAAIR,eAAe,CAACb,WAAD,EAAcqB,UAAd,CAA9C;AACD;AACF,GAfD;AAgBD,CAjBD;;AAmBA,MAAMC,wBAAwB,GAAG,CAACvB,UAAD,EAAgCwB,WAAhC,EAA6CtB,SAA7C,KAA2D;AAC1F,QAAMuB,kBAAkB,GAAG,qDAA8BzB,UAA9B,EAA0C,CAACwB,WAAD,CAA1C,EAAyDtB,SAAzD,CAA3B;AACA,QAAMwB,QAAQ,GAAGD,kBAAkB,CAACD,WAAW,CAAChB,IAAb,CAAnC;AACA,SAAO,EACL,GAAGgB,WADE;AAELG,IAAAA,MAAM,EAAED;AAFH,GAAP;AAID,CAPD;;AASO,MAAME,gBAAgB,GAAG,SAASA,gBAAT,CAA2B5B,UAA3B,EAA0DC,WAA1D,EAAuEC,SAAS,GAAG,EAAnF,EAI9B;AAAA;;AACA,QAAM2B,eAAe,GAAG,0BAAA5B,WAAW,CAACuB,WAAZ,gFAAyBf,KAAzB,KAAkC,EAA1D;AAEAoB,EAAAA,eAAe,CAACxB,OAAhB,CACEmB,WAAW,IAAIV,eAAe,CAACb,WAAD,EAAcuB,WAAd,CADhC;AAIA,QAAMM,YAAY,GAAG,kBAAAD,eAAe,MAAf,CAAAA,eAAe,EAAKL,WAAW,IAAID,wBAAwB,CAAEvB,UAAF,EAAcwB,WAAd,EAA2BtB,SAA3B,CAA5C,CAApC;AAEA,QAAM;AAAEE,IAAAA,OAAF;AAAWD,IAAAA;AAAX,MAAuBJ,oBAAoB,CAAEC,UAAF,EAAcC,WAAd,EAA2BC,SAA3B,CAAjD;AAEA,SAAO;AACL4B,IAAAA,YADK;AAEL1B,IAAAA,OAFK;AAGLD,IAAAA;AAHK,GAAP;AAKD,CApBM","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\n/* eslint-disable max-len */\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-nocheck\nimport { OktaAuthInterface } from '../../../types'; // auth-js/types\nimport { generateRemediationFunctions } from './remediationParser';\nimport generateIdxAction from './generateIdxAction';\nimport { JSONPath } from 'jsonpath-plus';\n\nconst SKIP_FIELDS = Object.fromEntries([\n 'remediation', // remediations are put into proceed/neededToProceed\n 'context', // the API response of 'context' isn't externally useful. We ignore it and put all non-action (contextual) info into idxState.context\n].map( (field) => [ field, !!'skip this field' ] ));\n\nexport const parseNonRemediations = function parseNonRemediations( authClient: OktaAuthInterface, idxResponse, toPersist = {} ) {\n const actions = {};\n const context = {};\n\n Object.keys(idxResponse)\n .filter( field => !SKIP_FIELDS[field])\n .forEach( field => {\n const fieldIsObject = typeof idxResponse[field] === 'object' && !!idxResponse[field];\n\n if ( !fieldIsObject ) {\n // simple fields are contextual info\n context[field] = idxResponse[field];\n return;\n }\n\n if ( idxResponse[field].rel ) {\n // top level actions\n actions[idxResponse[field].name] = generateIdxAction(authClient, idxResponse[field], toPersist);\n return;\n }\n\n const { value: fieldValue, type, ...info} = idxResponse[field];\n context[field] = { type, ...info}; // add the non-action parts as context\n\n if ( type !== 'object' ) {\n // only object values hold actions\n context[field].value = fieldValue;\n return;\n }\n\n // We are an object field containing an object value\n context[field].value = {};\n Object.entries(fieldValue)\n .forEach( ([subField, value]) => {\n if (value.rel) { // is [field].value[subField] an action?\n // add any \"action\" value subfields to actions\n actions[`${field}-${subField.name || subField}`] = generateIdxAction(authClient, value, toPersist);\n } else {\n // add non-action value subfields to context\n context[field].value[subField] = value;\n }\n });\n });\n\n return { context, actions };\n};\n\nconst expandRelatesTo = (idxResponse, value) => {\n Object.keys(value).forEach(k => {\n if (k === 'relatesTo') {\n const query = Array.isArray(value[k]) ? value[k][0] : value[k];\n if (typeof query === 'string') {\n // eslint-disable-next-line new-cap\n const result = JSONPath({ path: query, json: idxResponse })[0];\n if (result) {\n value[k] = result;\n return;\n }\n }\n }\n if (Array.isArray(value[k])) {\n value[k].forEach(innerValue => expandRelatesTo(idxResponse, innerValue));\n }\n });\n};\n\nconst convertRemediationAction = (authClient: OktaAuthInterface, remediation, toPersist) => {\n const remediationActions = generateRemediationFunctions( authClient, [remediation], toPersist );\n const actionFn = remediationActions[remediation.name];\n return {\n ...remediation,\n action: actionFn,\n };\n};\n\nexport const parseIdxResponse = function parseIdxResponse( authClient: OktaAuthInterface, idxResponse, toPersist = {} ): {\n remediations: IdxRemediation[];\n context: IdxContext;\n actions: IdxActions;\n} {\n const remediationData = idxResponse.remediation?.value || [];\n\n remediationData.forEach(\n remediation => expandRelatesTo(idxResponse, remediation)\n );\n\n const remediations = remediationData.map(remediation => convertRemediationAction( authClient, remediation, toPersist ));\n\n const { context, actions } = parseNonRemediations( authClient, idxResponse, toPersist );\n\n return {\n remediations,\n context,\n actions,\n };\n};\n"],"file":"idxResponseParser.js"}
|
|
@@ -21,7 +21,8 @@ var _idxResponseParser = require("./idxResponseParser");
|
|
|
21
21
|
*
|
|
22
22
|
* See the License for the specific language governing permissions and limitations under the License.
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
// auth-js/types
|
|
25
|
+
function makeIdxState(authClient, idxResponse, toPersist, requestDidSucceed) {
|
|
25
26
|
var _rawIdxResponse$succe, _rawIdxResponse$succe2, _rawIdxResponse$succe3;
|
|
26
27
|
|
|
27
28
|
const rawIdxResponse = idxResponse;
|
|
@@ -29,7 +30,7 @@ function makeIdxState(idxResponse, toPersist, requestDidSucceed) {
|
|
|
29
30
|
remediations,
|
|
30
31
|
context,
|
|
31
32
|
actions
|
|
32
|
-
} = (0, _idxResponseParser.parseIdxResponse)(idxResponse, toPersist);
|
|
33
|
+
} = (0, _idxResponseParser.parseIdxResponse)(authClient, idxResponse, toPersist);
|
|
33
34
|
const neededToProceed = [...remediations];
|
|
34
35
|
|
|
35
36
|
const proceed = async function (remediationChoice, paramsFromUser = {}) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../lib/idx/idxState/v1/makeIdxState.ts"],"names":["makeIdxState","authClient","idxResponse","toPersist","requestDidSucceed","rawIdxResponse","remediations","context","actions","neededToProceed","proceed","remediationChoice","paramsFromUser","remediationChoiceObject","remediation","name","reject","action","findCode","item","interactionCode","successWithInteractionCode","value","rawIdxState"],"mappings":";;;;;;;;;;AAcA;;AAdA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAGuE;AAGhE,SAASA,YAAT,CACLC,UADK,EAELC,WAFK,EAGLC,SAHK,EAILC,iBAJK,EAKQ;AAAA;;AACb,QAAMC,cAAc,GAAIH,WAAxB;AACA,QAAM;AAAEI,IAAAA,YAAF;AAAgBC,IAAAA,OAAhB;AAAyBC,IAAAA;AAAzB,MAAqC,yCAAkBP,UAAlB,EAA8BC,WAA9B,EAA2CC,SAA3C,CAA3C;AACA,QAAMM,eAAe,GAAG,CAAC,GAAGH,YAAJ,CAAxB;;AAEA,QAAMI,OAA+B,GAAG,gBAAgBC,iBAAhB,EAAmCC,cAAc,GAAG,EAApD,EAAyD;AAC/F;AACJ;AACA;AACA;AACA;AACA;AACI,UAAMC,uBAAuB,GAAG,mBAAAP,YAAY,MAAZ,CAAAA,YAAY,EAAOQ,WAAD,IAAiBA,WAAW,CAACC,IAAZ,KAAqBJ,iBAA5C,CAA5C;;AACA,QAAK,CAACE,uBAAN,EAAgC;AAC9B,aAAO,iBAAQG,MAAR,CAAgB,gCAA+BL,iBAAkB,GAAjE,CAAP;AACD;;AAED,WAAOE,uBAAuB,CAACI,MAAxB,CAA+BL,cAA/B,CAAP;AACD,GAbD;;AAeA,QAAMM,QAAQ,GAAGC,IAAI,IAAIA,IAAI,CAACJ,IAAL,KAAc,kBAAvC;;AACA,QAAMK,eAAe,4BAAGf,cAAc,CAACgB,0BAAlB,oFAAG,sBAA2CC,KAA9C,qFAAG,wEAAwDJ,QAAxD,CAAH,2DAAG,uBAAoEI,KAA5F;AAEA,SAAO;AACLZ,IAAAA,OADK;AAELD,IAAAA,eAFK;AAGLD,IAAAA,OAHK;AAILD,IAAAA,OAJK;AAKLgB,IAAAA,WAAW,EAAElB,cALR;AAMLe,IAAAA,eANK;AAOLjB,IAAAA,SAPK;AAQLC,IAAAA;AARK,GAAP;AAUD","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 { IdxResponse } from '../../types/idx-js';\nimport { OktaAuthInterface, RawIdxResponse } from '../../../types'; // auth-js/types\nimport { parseIdxResponse } from './idxResponseParser';\n\nexport function makeIdxState( \n authClient: OktaAuthInterface,\n idxResponse: RawIdxResponse,\n toPersist,\n requestDidSucceed: boolean\n): IdxResponse {\n const rawIdxResponse = idxResponse;\n const { remediations, context, actions } = parseIdxResponse( authClient, idxResponse, toPersist );\n const neededToProceed = [...remediations];\n\n const proceed: IdxResponse['proceed'] = async function( remediationChoice, paramsFromUser = {} ) {\n /*\n remediationChoice is the name attribute on each form\n name should remain unique for items inside the remediation that are considered forms(identify, select-factor)\n name can be duplicate for items like redirect where its not considered a form(redirect)\n when names are not unique its a redirect to a href, so widget wont POST to idx-js layer.\n */\n const remediationChoiceObject = remediations.find((remediation) => remediation.name === remediationChoice);\n if ( !remediationChoiceObject ) {\n return Promise.reject(`Unknown remediation choice: [${remediationChoice}]`);\n }\n\n return remediationChoiceObject.action(paramsFromUser);\n };\n\n const findCode = item => item.name === 'interaction_code';\n const interactionCode = rawIdxResponse.successWithInteractionCode?.value?.find( findCode )?.value as string;\n\n return {\n proceed,\n neededToProceed,\n actions,\n context,\n rawIdxState: rawIdxResponse,\n interactionCode,\n toPersist,\n requestDidSucceed,\n };\n}\n"],"file":"makeIdxState.js"}
|
|
@@ -15,6 +15,7 @@ var _makeIdxState = require("./makeIdxState");
|
|
|
15
15
|
*
|
|
16
16
|
* See the License for the specific language governing permissions and limitations under the License.
|
|
17
17
|
*/
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
18
19
|
// @ts-nocheck
|
|
19
20
|
var _default = {
|
|
20
21
|
makeIdxState: _makeIdxState.makeIdxState
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../lib/idx/idxState/v1/parsers.ts"],"names":["makeIdxState"],"mappings":";;;;AAcA;;AAdA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;eAGe;AACbA,EAAAA,YAAY,EAAZA;AADa,C","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\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-nocheck\nimport { makeIdxState } from './makeIdxState';\n\nexport default {\n makeIdxState,\n};\n"],"file":"parsers.js"}
|
|
@@ -21,10 +21,12 @@ var _generateIdxAction = _interopRequireDefault(require("./generateIdxAction"));
|
|
|
21
21
|
*
|
|
22
22
|
* See the License for the specific language governing permissions and limitations under the License.
|
|
23
23
|
*/
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
24
25
|
// @ts-nocheck
|
|
25
|
-
|
|
26
|
+
// auth-js/types
|
|
27
|
+
const generateRemediationFunctions = function generateRemediationFunctions(authClient, remediationValue, toPersist = {}) {
|
|
26
28
|
return (0, _fromEntries.default)((0, _map.default)(remediationValue).call(remediationValue, remediation => {
|
|
27
|
-
return [remediation.name, (0, _generateIdxAction.default)(remediation, toPersist)];
|
|
29
|
+
return [remediation.name, (0, _generateIdxAction.default)(authClient, remediation, toPersist)];
|
|
28
30
|
}));
|
|
29
31
|
};
|
|
30
32
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../lib/idx/idxState/v1/remediationParser.ts"],"names":["generateRemediationFunctions","authClient","remediationValue","toPersist","remediation","name"],"mappings":";;;;;;;;;;AAeA;;AAfA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACuD;AAGhD,MAAMA,4BAA4B,GAAG,SAASA,4BAAT,CAC1CC,UAD0C,EAE1CC,gBAF0C,EAG1CC,SAAS,GAAG,EAH8B,EAI1C;AACA,SAAO,0BAAoB,kBAAAD,gBAAgB,MAAhB,CAAAA,gBAAgB,EAAME,WAAW,IAAI;AAC9D,WAAO,CACLA,WAAW,CAACC,IADP,EAEL,gCAAkBJ,UAAlB,EAA8BG,WAA9B,EAA2CD,SAA3C,CAFK,CAAP;AAID,GAL0C,CAApC,CAAP;AAMD,CAXM","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\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-nocheck\nimport { OktaAuthInterface } from '../../../types'; // auth-js/types\nimport generateIdxAction from './generateIdxAction';\n\nexport const generateRemediationFunctions = function generateRemediationFunctions(\n authClient: OktaAuthInterface,\n remediationValue,\n toPersist = {}\n) {\n return Object.fromEntries( remediationValue.map( remediation => {\n return [\n remediation.name,\n generateIdxAction(authClient, remediation, toPersist),\n ];\n }) );\n};\n"],"file":"remediationParser.js"}
|