@nsshunt/stsoauth2plugin 1.0.12 → 1.0.13
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/dist/stsoauth2plugin.mjs +1340 -739
- package/dist/stsoauth2plugin.mjs.map +1 -1
- package/dist/stsoauth2plugin.umd.js +2135 -1
- package/dist/stsoauth2plugin.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/stsoauth2plugin.mjs
CHANGED
|
@@ -1,119 +1,171 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
6
|
};
|
|
7
|
-
var
|
|
8
|
-
if (
|
|
7
|
+
var __accessCheck = (obj, member, msg) => {
|
|
8
|
+
if (!member.has(obj))
|
|
9
|
+
throw TypeError("Cannot " + msg);
|
|
10
|
+
};
|
|
11
|
+
var __privateGet = (obj, member, getter) => {
|
|
12
|
+
__accessCheck(obj, member, "read from private field");
|
|
13
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
14
|
+
};
|
|
15
|
+
var __privateAdd = (obj, member, value) => {
|
|
16
|
+
if (member.has(obj))
|
|
9
17
|
throw TypeError("Cannot add the same private member more than once");
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
19
|
+
};
|
|
20
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
21
|
+
__accessCheck(obj, member, "write to private field");
|
|
22
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
23
|
+
return value;
|
|
24
|
+
};
|
|
25
|
+
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
26
|
+
set _(value) {
|
|
27
|
+
__privateSet(obj, member, value, setter);
|
|
14
28
|
},
|
|
15
29
|
get _() {
|
|
16
|
-
return
|
|
30
|
+
return __privateGet(obj, member, getter);
|
|
17
31
|
}
|
|
18
32
|
});
|
|
19
|
-
|
|
20
|
-
import
|
|
21
|
-
import
|
|
22
|
-
import
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import
|
|
33
|
+
var _crypto, _router, _cUtils, _qParams, _STORAGE_AUTHORIZE_OPTIONS_KEY, _STORAGE_SESSION_KEY, _aic, _options, _messages, _oauth2ManagerPort, _messageId, _messageHandlers, _messageTimeout, _worker, _transactionStore, _operationSemaphore, _maxSemaphoreRetries, _semaphoreRetrySleep, _ProcessMessageResponse, _PostMessage, _HandleLogEvent, _HandleUpdateInstrumentEvent, _GetStore, _HandleErrorEvent, _HandleAuthenticateEvent, _SetupRoute, _clientSessionStore, _cUtils2, _qParams2, _STORAGE_SESSION_KEY2, _oauthWorkerPort, _options2, _httpsAgent, _HandleAuthenticateEvent2, _HandleErrorEvent2, _LogMessage, _GetAccessToken, _GetCookies, _UpdateInstrument, _ProcessCommand, _RestoreSession, _Authorize, _HandleRedirect, _GetTokenFromBroker, _GetToken, _RefreshToken, _Logout;
|
|
34
|
+
import { inject } from "vue";
|
|
35
|
+
import Debug from "debug";
|
|
36
|
+
import * as wt from "node:worker_threads";
|
|
37
|
+
import { OAuth2ParameterType, Sleep } from "@nsshunt/stsutils";
|
|
38
|
+
import { ClientStorageFactory, ClientStorageType } from "@nsshunt/stsvueutils";
|
|
39
|
+
import { defineStore } from "pinia";
|
|
40
|
+
import { STSInstrumentControllerPluginKey } from "@nsshunt/stspublisherserver";
|
|
41
|
+
import https from "node:https";
|
|
27
42
|
import "colors";
|
|
28
|
-
import
|
|
29
|
-
import { Gauge
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
import axios from "axios";
|
|
44
|
+
import { Gauge } from "@nsshunt/stsinstrumentation";
|
|
45
|
+
const STSOAuth2ManagerPluginKey = Symbol();
|
|
46
|
+
const isNode = Object.prototype.toString.call(typeof process !== "undefined" ? process : 0) === "[object process]";
|
|
47
|
+
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
48
|
+
function getAugmentedNamespace(n2) {
|
|
49
|
+
if (n2.__esModule)
|
|
50
|
+
return n2;
|
|
51
|
+
var f = n2.default;
|
|
52
|
+
if (typeof f == "function") {
|
|
53
|
+
var a = function a2() {
|
|
54
|
+
if (this instanceof a2) {
|
|
55
|
+
var args = [null];
|
|
56
|
+
args.push.apply(args, arguments);
|
|
57
|
+
var Ctor = Function.bind.apply(f, args);
|
|
58
|
+
return new Ctor();
|
|
43
59
|
}
|
|
44
|
-
return
|
|
60
|
+
return f.apply(this, arguments);
|
|
45
61
|
};
|
|
46
|
-
|
|
62
|
+
a.prototype = f.prototype;
|
|
47
63
|
} else
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
Object.
|
|
52
|
-
|
|
64
|
+
a = {};
|
|
65
|
+
Object.defineProperty(a, "__esModule", { value: true });
|
|
66
|
+
Object.keys(n2).forEach(function(k) {
|
|
67
|
+
var d = Object.getOwnPropertyDescriptor(n2, k);
|
|
68
|
+
Object.defineProperty(a, k, d.get ? d : {
|
|
69
|
+
enumerable: true,
|
|
53
70
|
get: function() {
|
|
54
|
-
return
|
|
71
|
+
return n2[k];
|
|
55
72
|
}
|
|
56
73
|
});
|
|
57
|
-
})
|
|
74
|
+
});
|
|
75
|
+
return a;
|
|
58
76
|
}
|
|
59
|
-
var
|
|
77
|
+
var sha256Exports = {};
|
|
78
|
+
var sha256 = {
|
|
60
79
|
get exports() {
|
|
61
|
-
return
|
|
80
|
+
return sha256Exports;
|
|
62
81
|
},
|
|
63
|
-
set exports(
|
|
64
|
-
|
|
82
|
+
set exports(v) {
|
|
83
|
+
sha256Exports = v;
|
|
65
84
|
}
|
|
66
85
|
};
|
|
67
|
-
function
|
|
68
|
-
throw new Error('Could not dynamically require "' +
|
|
86
|
+
function commonjsRequire(path) {
|
|
87
|
+
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
69
88
|
}
|
|
70
|
-
var
|
|
89
|
+
var coreExports = {};
|
|
90
|
+
var core = {
|
|
71
91
|
get exports() {
|
|
72
|
-
return
|
|
92
|
+
return coreExports;
|
|
73
93
|
},
|
|
74
|
-
set exports(
|
|
75
|
-
|
|
94
|
+
set exports(v) {
|
|
95
|
+
coreExports = v;
|
|
76
96
|
}
|
|
77
97
|
};
|
|
78
|
-
const
|
|
98
|
+
const __viteBrowserExternal = {};
|
|
99
|
+
const __viteBrowserExternal$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
79
100
|
__proto__: null,
|
|
80
|
-
default:
|
|
81
|
-
}, Symbol.toStringTag, { value: "Module" }))
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
101
|
+
default: __viteBrowserExternal
|
|
102
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
103
|
+
const require$$0 = /* @__PURE__ */ getAugmentedNamespace(__viteBrowserExternal$1);
|
|
104
|
+
var hasRequiredCore;
|
|
105
|
+
function requireCore() {
|
|
106
|
+
if (hasRequiredCore)
|
|
107
|
+
return coreExports;
|
|
108
|
+
hasRequiredCore = 1;
|
|
109
|
+
(function(module, exports) {
|
|
110
|
+
(function(root, factory) {
|
|
111
|
+
{
|
|
112
|
+
module.exports = factory();
|
|
113
|
+
}
|
|
114
|
+
})(commonjsGlobal, function() {
|
|
115
|
+
var CryptoJS = CryptoJS || function(Math2, undefined$1) {
|
|
116
|
+
var crypto2;
|
|
117
|
+
if (typeof window !== "undefined" && window.crypto) {
|
|
118
|
+
crypto2 = window.crypto;
|
|
119
|
+
}
|
|
120
|
+
if (typeof self !== "undefined" && self.crypto) {
|
|
121
|
+
crypto2 = self.crypto;
|
|
122
|
+
}
|
|
123
|
+
if (typeof globalThis !== "undefined" && globalThis.crypto) {
|
|
124
|
+
crypto2 = globalThis.crypto;
|
|
125
|
+
}
|
|
126
|
+
if (!crypto2 && typeof window !== "undefined" && window.msCrypto) {
|
|
127
|
+
crypto2 = window.msCrypto;
|
|
128
|
+
}
|
|
129
|
+
if (!crypto2 && typeof commonjsGlobal !== "undefined" && commonjsGlobal.crypto) {
|
|
130
|
+
crypto2 = commonjsGlobal.crypto;
|
|
131
|
+
}
|
|
132
|
+
if (!crypto2 && typeof commonjsRequire === "function") {
|
|
91
133
|
try {
|
|
92
|
-
|
|
93
|
-
} catch {
|
|
134
|
+
crypto2 = require$$0;
|
|
135
|
+
} catch (err) {
|
|
94
136
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
137
|
+
}
|
|
138
|
+
var cryptoSecureRandomInt = function() {
|
|
139
|
+
if (crypto2) {
|
|
140
|
+
if (typeof crypto2.getRandomValues === "function") {
|
|
98
141
|
try {
|
|
99
|
-
return
|
|
100
|
-
} catch {
|
|
142
|
+
return crypto2.getRandomValues(new Uint32Array(1))[0];
|
|
143
|
+
} catch (err) {
|
|
101
144
|
}
|
|
102
|
-
|
|
145
|
+
}
|
|
146
|
+
if (typeof crypto2.randomBytes === "function") {
|
|
103
147
|
try {
|
|
104
|
-
return
|
|
105
|
-
} catch {
|
|
148
|
+
return crypto2.randomBytes(4).readInt32LE();
|
|
149
|
+
} catch (err) {
|
|
106
150
|
}
|
|
151
|
+
}
|
|
107
152
|
}
|
|
108
153
|
throw new Error("Native crypto module could not be used to get secure random number.");
|
|
109
|
-
}
|
|
110
|
-
|
|
154
|
+
};
|
|
155
|
+
var create = Object.create || function() {
|
|
156
|
+
function F() {
|
|
111
157
|
}
|
|
112
|
-
return function(
|
|
113
|
-
var
|
|
114
|
-
|
|
158
|
+
return function(obj) {
|
|
159
|
+
var subtype;
|
|
160
|
+
F.prototype = obj;
|
|
161
|
+
subtype = new F();
|
|
162
|
+
F.prototype = null;
|
|
163
|
+
return subtype;
|
|
115
164
|
};
|
|
116
|
-
}()
|
|
165
|
+
}();
|
|
166
|
+
var C = {};
|
|
167
|
+
var C_lib = C.lib = {};
|
|
168
|
+
var Base = C_lib.Base = function() {
|
|
117
169
|
return {
|
|
118
170
|
/**
|
|
119
171
|
* Creates a new object that inherits from this object.
|
|
@@ -133,11 +185,19 @@ function je() {
|
|
|
133
185
|
* }
|
|
134
186
|
* });
|
|
135
187
|
*/
|
|
136
|
-
extend: function(
|
|
137
|
-
var
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
188
|
+
extend: function(overrides) {
|
|
189
|
+
var subtype = create(this);
|
|
190
|
+
if (overrides) {
|
|
191
|
+
subtype.mixIn(overrides);
|
|
192
|
+
}
|
|
193
|
+
if (!subtype.hasOwnProperty("init") || this.init === subtype.init) {
|
|
194
|
+
subtype.init = function() {
|
|
195
|
+
subtype.$super.init.apply(this, arguments);
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
subtype.init.prototype = subtype;
|
|
199
|
+
subtype.$super = this;
|
|
200
|
+
return subtype;
|
|
141
201
|
},
|
|
142
202
|
/**
|
|
143
203
|
* Extends this object and runs the init method.
|
|
@@ -152,8 +212,9 @@ function je() {
|
|
|
152
212
|
* var instance = MyType.create();
|
|
153
213
|
*/
|
|
154
214
|
create: function() {
|
|
155
|
-
var
|
|
156
|
-
|
|
215
|
+
var instance = this.extend();
|
|
216
|
+
instance.init.apply(instance, arguments);
|
|
217
|
+
return instance;
|
|
157
218
|
},
|
|
158
219
|
/**
|
|
159
220
|
* Initializes a newly created object.
|
|
@@ -180,10 +241,15 @@ function je() {
|
|
|
180
241
|
* field: 'value'
|
|
181
242
|
* });
|
|
182
243
|
*/
|
|
183
|
-
mixIn: function(
|
|
184
|
-
for (var
|
|
185
|
-
|
|
186
|
-
|
|
244
|
+
mixIn: function(properties) {
|
|
245
|
+
for (var propertyName in properties) {
|
|
246
|
+
if (properties.hasOwnProperty(propertyName)) {
|
|
247
|
+
this[propertyName] = properties[propertyName];
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (properties.hasOwnProperty("toString")) {
|
|
251
|
+
this.toString = properties.toString;
|
|
252
|
+
}
|
|
187
253
|
},
|
|
188
254
|
/**
|
|
189
255
|
* Creates a copy of this object.
|
|
@@ -198,7 +264,8 @@ function je() {
|
|
|
198
264
|
return this.init.prototype.extend(this);
|
|
199
265
|
}
|
|
200
266
|
};
|
|
201
|
-
}()
|
|
267
|
+
}();
|
|
268
|
+
var WordArray = C_lib.WordArray = Base.extend({
|
|
202
269
|
/**
|
|
203
270
|
* Initializes a newly created word array.
|
|
204
271
|
*
|
|
@@ -211,8 +278,13 @@ function je() {
|
|
|
211
278
|
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
|
|
212
279
|
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
|
|
213
280
|
*/
|
|
214
|
-
init: function(
|
|
215
|
-
|
|
281
|
+
init: function(words, sigBytes) {
|
|
282
|
+
words = this.words = words || [];
|
|
283
|
+
if (sigBytes != undefined$1) {
|
|
284
|
+
this.sigBytes = sigBytes;
|
|
285
|
+
} else {
|
|
286
|
+
this.sigBytes = words.length * 4;
|
|
287
|
+
}
|
|
216
288
|
},
|
|
217
289
|
/**
|
|
218
290
|
* Converts this word array to a string.
|
|
@@ -227,8 +299,8 @@ function je() {
|
|
|
227
299
|
* var string = wordArray.toString();
|
|
228
300
|
* var string = wordArray.toString(CryptoJS.enc.Utf8);
|
|
229
301
|
*/
|
|
230
|
-
toString: function(
|
|
231
|
-
return (
|
|
302
|
+
toString: function(encoder) {
|
|
303
|
+
return (encoder || Hex).stringify(this);
|
|
232
304
|
},
|
|
233
305
|
/**
|
|
234
306
|
* Concatenates a word array to this word array.
|
|
@@ -241,17 +313,24 @@ function je() {
|
|
|
241
313
|
*
|
|
242
314
|
* wordArray1.concat(wordArray2);
|
|
243
315
|
*/
|
|
244
|
-
concat: function(
|
|
245
|
-
var
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
316
|
+
concat: function(wordArray) {
|
|
317
|
+
var thisWords = this.words;
|
|
318
|
+
var thatWords = wordArray.words;
|
|
319
|
+
var thisSigBytes = this.sigBytes;
|
|
320
|
+
var thatSigBytes = wordArray.sigBytes;
|
|
321
|
+
this.clamp();
|
|
322
|
+
if (thisSigBytes % 4) {
|
|
323
|
+
for (var i = 0; i < thatSigBytes; i++) {
|
|
324
|
+
var thatByte = thatWords[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
|
325
|
+
thisWords[thisSigBytes + i >>> 2] |= thatByte << 24 - (thisSigBytes + i) % 4 * 8;
|
|
250
326
|
}
|
|
251
|
-
else
|
|
252
|
-
for (var
|
|
253
|
-
|
|
254
|
-
|
|
327
|
+
} else {
|
|
328
|
+
for (var j = 0; j < thatSigBytes; j += 4) {
|
|
329
|
+
thisWords[thisSigBytes + j >>> 2] = thatWords[j >>> 2];
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
this.sigBytes += thatSigBytes;
|
|
333
|
+
return this;
|
|
255
334
|
},
|
|
256
335
|
/**
|
|
257
336
|
* Removes insignificant bits.
|
|
@@ -261,8 +340,10 @@ function je() {
|
|
|
261
340
|
* wordArray.clamp();
|
|
262
341
|
*/
|
|
263
342
|
clamp: function() {
|
|
264
|
-
var
|
|
265
|
-
|
|
343
|
+
var words = this.words;
|
|
344
|
+
var sigBytes = this.sigBytes;
|
|
345
|
+
words[sigBytes >>> 2] &= 4294967295 << 32 - sigBytes % 4 * 8;
|
|
346
|
+
words.length = Math2.ceil(sigBytes / 4);
|
|
266
347
|
},
|
|
267
348
|
/**
|
|
268
349
|
* Creates a copy of this word array.
|
|
@@ -274,8 +355,9 @@ function je() {
|
|
|
274
355
|
* var clone = wordArray.clone();
|
|
275
356
|
*/
|
|
276
357
|
clone: function() {
|
|
277
|
-
var
|
|
278
|
-
|
|
358
|
+
var clone = Base.clone.call(this);
|
|
359
|
+
clone.words = this.words.slice(0);
|
|
360
|
+
return clone;
|
|
279
361
|
},
|
|
280
362
|
/**
|
|
281
363
|
* Creates a word array filled with random bytes.
|
|
@@ -290,12 +372,16 @@ function je() {
|
|
|
290
372
|
*
|
|
291
373
|
* var wordArray = CryptoJS.lib.WordArray.random(16);
|
|
292
374
|
*/
|
|
293
|
-
random: function(
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
375
|
+
random: function(nBytes) {
|
|
376
|
+
var words = [];
|
|
377
|
+
for (var i = 0; i < nBytes; i += 4) {
|
|
378
|
+
words.push(cryptoSecureRandomInt());
|
|
379
|
+
}
|
|
380
|
+
return new WordArray.init(words, nBytes);
|
|
297
381
|
}
|
|
298
|
-
})
|
|
382
|
+
});
|
|
383
|
+
var C_enc = C.enc = {};
|
|
384
|
+
var Hex = C_enc.Hex = {
|
|
299
385
|
/**
|
|
300
386
|
* Converts a word array to a hex string.
|
|
301
387
|
*
|
|
@@ -309,12 +395,16 @@ function je() {
|
|
|
309
395
|
*
|
|
310
396
|
* var hexString = CryptoJS.enc.Hex.stringify(wordArray);
|
|
311
397
|
*/
|
|
312
|
-
stringify: function(
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
398
|
+
stringify: function(wordArray) {
|
|
399
|
+
var words = wordArray.words;
|
|
400
|
+
var sigBytes = wordArray.sigBytes;
|
|
401
|
+
var hexChars = [];
|
|
402
|
+
for (var i = 0; i < sigBytes; i++) {
|
|
403
|
+
var bite = words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
|
404
|
+
hexChars.push((bite >>> 4).toString(16));
|
|
405
|
+
hexChars.push((bite & 15).toString(16));
|
|
316
406
|
}
|
|
317
|
-
return
|
|
407
|
+
return hexChars.join("");
|
|
318
408
|
},
|
|
319
409
|
/**
|
|
320
410
|
* Converts a hex string to a word array.
|
|
@@ -329,12 +419,16 @@ function je() {
|
|
|
329
419
|
*
|
|
330
420
|
* var wordArray = CryptoJS.enc.Hex.parse(hexString);
|
|
331
421
|
*/
|
|
332
|
-
parse: function(
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
422
|
+
parse: function(hexStr) {
|
|
423
|
+
var hexStrLength = hexStr.length;
|
|
424
|
+
var words = [];
|
|
425
|
+
for (var i = 0; i < hexStrLength; i += 2) {
|
|
426
|
+
words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << 24 - i % 8 * 4;
|
|
427
|
+
}
|
|
428
|
+
return new WordArray.init(words, hexStrLength / 2);
|
|
336
429
|
}
|
|
337
|
-
}
|
|
430
|
+
};
|
|
431
|
+
var Latin1 = C_enc.Latin1 = {
|
|
338
432
|
/**
|
|
339
433
|
* Converts a word array to a Latin1 string.
|
|
340
434
|
*
|
|
@@ -348,12 +442,15 @@ function je() {
|
|
|
348
442
|
*
|
|
349
443
|
* var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
|
|
350
444
|
*/
|
|
351
|
-
stringify: function(
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
445
|
+
stringify: function(wordArray) {
|
|
446
|
+
var words = wordArray.words;
|
|
447
|
+
var sigBytes = wordArray.sigBytes;
|
|
448
|
+
var latin1Chars = [];
|
|
449
|
+
for (var i = 0; i < sigBytes; i++) {
|
|
450
|
+
var bite = words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
|
451
|
+
latin1Chars.push(String.fromCharCode(bite));
|
|
355
452
|
}
|
|
356
|
-
return
|
|
453
|
+
return latin1Chars.join("");
|
|
357
454
|
},
|
|
358
455
|
/**
|
|
359
456
|
* Converts a Latin1 string to a word array.
|
|
@@ -368,12 +465,16 @@ function je() {
|
|
|
368
465
|
*
|
|
369
466
|
* var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
|
|
370
467
|
*/
|
|
371
|
-
parse: function(
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
468
|
+
parse: function(latin1Str) {
|
|
469
|
+
var latin1StrLength = latin1Str.length;
|
|
470
|
+
var words = [];
|
|
471
|
+
for (var i = 0; i < latin1StrLength; i++) {
|
|
472
|
+
words[i >>> 2] |= (latin1Str.charCodeAt(i) & 255) << 24 - i % 4 * 8;
|
|
473
|
+
}
|
|
474
|
+
return new WordArray.init(words, latin1StrLength);
|
|
375
475
|
}
|
|
376
|
-
}
|
|
476
|
+
};
|
|
477
|
+
var Utf8 = C_enc.Utf8 = {
|
|
377
478
|
/**
|
|
378
479
|
* Converts a word array to a UTF-8 string.
|
|
379
480
|
*
|
|
@@ -387,10 +488,10 @@ function je() {
|
|
|
387
488
|
*
|
|
388
489
|
* var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
|
|
389
490
|
*/
|
|
390
|
-
stringify: function(
|
|
491
|
+
stringify: function(wordArray) {
|
|
391
492
|
try {
|
|
392
|
-
return decodeURIComponent(escape(
|
|
393
|
-
} catch {
|
|
493
|
+
return decodeURIComponent(escape(Latin1.stringify(wordArray)));
|
|
494
|
+
} catch (e2) {
|
|
394
495
|
throw new Error("Malformed UTF-8 data");
|
|
395
496
|
}
|
|
396
497
|
},
|
|
@@ -407,10 +508,11 @@ function je() {
|
|
|
407
508
|
*
|
|
408
509
|
* var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
|
|
409
510
|
*/
|
|
410
|
-
parse: function(
|
|
411
|
-
return
|
|
511
|
+
parse: function(utf8Str) {
|
|
512
|
+
return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
|
|
412
513
|
}
|
|
413
|
-
}
|
|
514
|
+
};
|
|
515
|
+
var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
|
|
414
516
|
/**
|
|
415
517
|
* Resets this block algorithm's data buffer to its initial state.
|
|
416
518
|
*
|
|
@@ -419,7 +521,8 @@ function je() {
|
|
|
419
521
|
* bufferedBlockAlgorithm.reset();
|
|
420
522
|
*/
|
|
421
523
|
reset: function() {
|
|
422
|
-
this._data = new
|
|
524
|
+
this._data = new WordArray.init();
|
|
525
|
+
this._nDataBytes = 0;
|
|
423
526
|
},
|
|
424
527
|
/**
|
|
425
528
|
* Adds new data to this block algorithm's buffer.
|
|
@@ -431,8 +534,12 @@ function je() {
|
|
|
431
534
|
* bufferedBlockAlgorithm._append('data');
|
|
432
535
|
* bufferedBlockAlgorithm._append(wordArray);
|
|
433
536
|
*/
|
|
434
|
-
_append: function(
|
|
435
|
-
typeof
|
|
537
|
+
_append: function(data) {
|
|
538
|
+
if (typeof data == "string") {
|
|
539
|
+
data = Utf8.parse(data);
|
|
540
|
+
}
|
|
541
|
+
this._data.concat(data);
|
|
542
|
+
this._nDataBytes += data.sigBytes;
|
|
436
543
|
},
|
|
437
544
|
/**
|
|
438
545
|
* Processes available data blocks.
|
|
@@ -448,16 +555,29 @@ function je() {
|
|
|
448
555
|
* var processedData = bufferedBlockAlgorithm._process();
|
|
449
556
|
* var processedData = bufferedBlockAlgorithm._process(!!'flush');
|
|
450
557
|
*/
|
|
451
|
-
_process: function(
|
|
452
|
-
var
|
|
453
|
-
|
|
454
|
-
var
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
558
|
+
_process: function(doFlush) {
|
|
559
|
+
var processedWords;
|
|
560
|
+
var data = this._data;
|
|
561
|
+
var dataWords = data.words;
|
|
562
|
+
var dataSigBytes = data.sigBytes;
|
|
563
|
+
var blockSize = this.blockSize;
|
|
564
|
+
var blockSizeBytes = blockSize * 4;
|
|
565
|
+
var nBlocksReady = dataSigBytes / blockSizeBytes;
|
|
566
|
+
if (doFlush) {
|
|
567
|
+
nBlocksReady = Math2.ceil(nBlocksReady);
|
|
568
|
+
} else {
|
|
569
|
+
nBlocksReady = Math2.max((nBlocksReady | 0) - this._minBufferSize, 0);
|
|
459
570
|
}
|
|
460
|
-
|
|
571
|
+
var nWordsReady = nBlocksReady * blockSize;
|
|
572
|
+
var nBytesReady = Math2.min(nWordsReady * 4, dataSigBytes);
|
|
573
|
+
if (nWordsReady) {
|
|
574
|
+
for (var offset = 0; offset < nWordsReady; offset += blockSize) {
|
|
575
|
+
this._doProcessBlock(dataWords, offset);
|
|
576
|
+
}
|
|
577
|
+
processedWords = dataWords.splice(0, nWordsReady);
|
|
578
|
+
data.sigBytes -= nBytesReady;
|
|
579
|
+
}
|
|
580
|
+
return new WordArray.init(processedWords, nBytesReady);
|
|
461
581
|
},
|
|
462
582
|
/**
|
|
463
583
|
* Creates a copy of this object.
|
|
@@ -469,16 +589,17 @@ function je() {
|
|
|
469
589
|
* var clone = bufferedBlockAlgorithm.clone();
|
|
470
590
|
*/
|
|
471
591
|
clone: function() {
|
|
472
|
-
var
|
|
473
|
-
|
|
592
|
+
var clone = Base.clone.call(this);
|
|
593
|
+
clone._data = this._data.clone();
|
|
594
|
+
return clone;
|
|
474
595
|
},
|
|
475
596
|
_minBufferSize: 0
|
|
476
597
|
});
|
|
477
|
-
|
|
598
|
+
C_lib.Hasher = BufferedBlockAlgorithm.extend({
|
|
478
599
|
/**
|
|
479
600
|
* Configuration options.
|
|
480
601
|
*/
|
|
481
|
-
cfg:
|
|
602
|
+
cfg: Base.extend(),
|
|
482
603
|
/**
|
|
483
604
|
* Initializes a newly created hasher.
|
|
484
605
|
*
|
|
@@ -488,8 +609,9 @@ function je() {
|
|
|
488
609
|
*
|
|
489
610
|
* var hasher = CryptoJS.algo.SHA256.create();
|
|
490
611
|
*/
|
|
491
|
-
init: function(
|
|
492
|
-
this.cfg = this.cfg.extend(
|
|
612
|
+
init: function(cfg) {
|
|
613
|
+
this.cfg = this.cfg.extend(cfg);
|
|
614
|
+
this.reset();
|
|
493
615
|
},
|
|
494
616
|
/**
|
|
495
617
|
* Resets this hasher to its initial state.
|
|
@@ -499,7 +621,8 @@ function je() {
|
|
|
499
621
|
* hasher.reset();
|
|
500
622
|
*/
|
|
501
623
|
reset: function() {
|
|
502
|
-
|
|
624
|
+
BufferedBlockAlgorithm.reset.call(this);
|
|
625
|
+
this._doReset();
|
|
503
626
|
},
|
|
504
627
|
/**
|
|
505
628
|
* Updates this hasher with a message.
|
|
@@ -513,8 +636,10 @@ function je() {
|
|
|
513
636
|
* hasher.update('message');
|
|
514
637
|
* hasher.update(wordArray);
|
|
515
638
|
*/
|
|
516
|
-
update: function(
|
|
517
|
-
|
|
639
|
+
update: function(messageUpdate) {
|
|
640
|
+
this._append(messageUpdate);
|
|
641
|
+
this._process();
|
|
642
|
+
return this;
|
|
518
643
|
},
|
|
519
644
|
/**
|
|
520
645
|
* Finalizes the hash computation.
|
|
@@ -530,12 +655,14 @@ function je() {
|
|
|
530
655
|
* var hash = hasher.finalize('message');
|
|
531
656
|
* var hash = hasher.finalize(wordArray);
|
|
532
657
|
*/
|
|
533
|
-
finalize: function(
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
658
|
+
finalize: function(messageUpdate) {
|
|
659
|
+
if (messageUpdate) {
|
|
660
|
+
this._append(messageUpdate);
|
|
661
|
+
}
|
|
662
|
+
var hash = this._doFinalize();
|
|
663
|
+
return hash;
|
|
537
664
|
},
|
|
538
|
-
blockSize:
|
|
665
|
+
blockSize: 512 / 32,
|
|
539
666
|
/**
|
|
540
667
|
* Creates a shortcut function to a hasher's object interface.
|
|
541
668
|
*
|
|
@@ -549,9 +676,9 @@ function je() {
|
|
|
549
676
|
*
|
|
550
677
|
* var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
|
|
551
678
|
*/
|
|
552
|
-
_createHelper: function(
|
|
553
|
-
return function(
|
|
554
|
-
return new
|
|
679
|
+
_createHelper: function(hasher) {
|
|
680
|
+
return function(message, cfg) {
|
|
681
|
+
return new hasher.init(cfg).finalize(message);
|
|
555
682
|
};
|
|
556
683
|
},
|
|
557
684
|
/**
|
|
@@ -567,83 +694,154 @@ function je() {
|
|
|
567
694
|
*
|
|
568
695
|
* var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
|
|
569
696
|
*/
|
|
570
|
-
_createHmacHelper: function(
|
|
571
|
-
return function(
|
|
572
|
-
return new
|
|
697
|
+
_createHmacHelper: function(hasher) {
|
|
698
|
+
return function(message, key) {
|
|
699
|
+
return new C_algo.HMAC.init(hasher, key).finalize(message);
|
|
573
700
|
};
|
|
574
701
|
}
|
|
575
702
|
});
|
|
576
|
-
var
|
|
577
|
-
return
|
|
703
|
+
var C_algo = C.algo = {};
|
|
704
|
+
return C;
|
|
578
705
|
}(Math);
|
|
579
|
-
return
|
|
706
|
+
return CryptoJS;
|
|
580
707
|
});
|
|
581
|
-
}(
|
|
708
|
+
})(core);
|
|
709
|
+
return coreExports;
|
|
582
710
|
}
|
|
583
|
-
(function(
|
|
584
|
-
(function(
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
711
|
+
(function(module, exports) {
|
|
712
|
+
(function(root, factory) {
|
|
713
|
+
{
|
|
714
|
+
module.exports = factory(requireCore());
|
|
715
|
+
}
|
|
716
|
+
})(commonjsGlobal, function(CryptoJS) {
|
|
717
|
+
(function(Math2) {
|
|
718
|
+
var C = CryptoJS;
|
|
719
|
+
var C_lib = C.lib;
|
|
720
|
+
var WordArray = C_lib.WordArray;
|
|
721
|
+
var Hasher = C_lib.Hasher;
|
|
722
|
+
var C_algo = C.algo;
|
|
723
|
+
var H = [];
|
|
724
|
+
var K = [];
|
|
589
725
|
(function() {
|
|
590
|
-
function
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
726
|
+
function isPrime(n3) {
|
|
727
|
+
var sqrtN = Math2.sqrt(n3);
|
|
728
|
+
for (var factor = 2; factor <= sqrtN; factor++) {
|
|
729
|
+
if (!(n3 % factor)) {
|
|
730
|
+
return false;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
return true;
|
|
734
|
+
}
|
|
735
|
+
function getFractionalBits(n3) {
|
|
736
|
+
return (n3 - (n3 | 0)) * 4294967296 | 0;
|
|
595
737
|
}
|
|
596
|
-
|
|
597
|
-
|
|
738
|
+
var n2 = 2;
|
|
739
|
+
var nPrime = 0;
|
|
740
|
+
while (nPrime < 64) {
|
|
741
|
+
if (isPrime(n2)) {
|
|
742
|
+
if (nPrime < 8) {
|
|
743
|
+
H[nPrime] = getFractionalBits(Math2.pow(n2, 1 / 2));
|
|
744
|
+
}
|
|
745
|
+
K[nPrime] = getFractionalBits(Math2.pow(n2, 1 / 3));
|
|
746
|
+
nPrime++;
|
|
747
|
+
}
|
|
748
|
+
n2++;
|
|
598
749
|
}
|
|
599
|
-
for (var E = 2, _ = 0; _ < 64; )
|
|
600
|
-
f(E) && (_ < 8 && (y[_] = N(n.pow(E, 1 / 2))), I[_] = N(n.pow(E, 1 / 3)), _++), E++;
|
|
601
750
|
})();
|
|
602
|
-
var
|
|
751
|
+
var W = [];
|
|
752
|
+
var SHA256 = C_algo.SHA256 = Hasher.extend({
|
|
603
753
|
_doReset: function() {
|
|
604
|
-
this._hash = new
|
|
754
|
+
this._hash = new WordArray.init(H.slice(0));
|
|
605
755
|
},
|
|
606
|
-
_doProcessBlock: function(
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
756
|
+
_doProcessBlock: function(M, offset) {
|
|
757
|
+
var H2 = this._hash.words;
|
|
758
|
+
var a = H2[0];
|
|
759
|
+
var b = H2[1];
|
|
760
|
+
var c = H2[2];
|
|
761
|
+
var d = H2[3];
|
|
762
|
+
var e2 = H2[4];
|
|
763
|
+
var f = H2[5];
|
|
764
|
+
var g = H2[6];
|
|
765
|
+
var h = H2[7];
|
|
766
|
+
for (var i = 0; i < 64; i++) {
|
|
767
|
+
if (i < 16) {
|
|
768
|
+
W[i] = M[offset + i] | 0;
|
|
769
|
+
} else {
|
|
770
|
+
var gamma0x = W[i - 15];
|
|
771
|
+
var gamma0 = (gamma0x << 25 | gamma0x >>> 7) ^ (gamma0x << 14 | gamma0x >>> 18) ^ gamma0x >>> 3;
|
|
772
|
+
var gamma1x = W[i - 2];
|
|
773
|
+
var gamma1 = (gamma1x << 15 | gamma1x >>> 17) ^ (gamma1x << 13 | gamma1x >>> 19) ^ gamma1x >>> 10;
|
|
774
|
+
W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
|
|
613
775
|
}
|
|
614
|
-
var
|
|
615
|
-
|
|
776
|
+
var ch = e2 & f ^ ~e2 & g;
|
|
777
|
+
var maj = a & b ^ a & c ^ b & c;
|
|
778
|
+
var sigma0 = (a << 30 | a >>> 2) ^ (a << 19 | a >>> 13) ^ (a << 10 | a >>> 22);
|
|
779
|
+
var sigma1 = (e2 << 26 | e2 >>> 6) ^ (e2 << 21 | e2 >>> 11) ^ (e2 << 7 | e2 >>> 25);
|
|
780
|
+
var t1 = h + sigma1 + ch + K[i] + W[i];
|
|
781
|
+
var t2 = sigma0 + maj;
|
|
782
|
+
h = g;
|
|
783
|
+
g = f;
|
|
784
|
+
f = e2;
|
|
785
|
+
e2 = d + t1 | 0;
|
|
786
|
+
d = c;
|
|
787
|
+
c = b;
|
|
788
|
+
b = a;
|
|
789
|
+
a = t1 + t2 | 0;
|
|
616
790
|
}
|
|
617
|
-
|
|
791
|
+
H2[0] = H2[0] + a | 0;
|
|
792
|
+
H2[1] = H2[1] + b | 0;
|
|
793
|
+
H2[2] = H2[2] + c | 0;
|
|
794
|
+
H2[3] = H2[3] + d | 0;
|
|
795
|
+
H2[4] = H2[4] + e2 | 0;
|
|
796
|
+
H2[5] = H2[5] + f | 0;
|
|
797
|
+
H2[6] = H2[6] + g | 0;
|
|
798
|
+
H2[7] = H2[7] + h | 0;
|
|
618
799
|
},
|
|
619
800
|
_doFinalize: function() {
|
|
620
|
-
var
|
|
621
|
-
|
|
801
|
+
var data = this._data;
|
|
802
|
+
var dataWords = data.words;
|
|
803
|
+
var nBitsTotal = this._nDataBytes * 8;
|
|
804
|
+
var nBitsLeft = data.sigBytes * 8;
|
|
805
|
+
dataWords[nBitsLeft >>> 5] |= 128 << 24 - nBitsLeft % 32;
|
|
806
|
+
dataWords[(nBitsLeft + 64 >>> 9 << 4) + 14] = Math2.floor(nBitsTotal / 4294967296);
|
|
807
|
+
dataWords[(nBitsLeft + 64 >>> 9 << 4) + 15] = nBitsTotal;
|
|
808
|
+
data.sigBytes = dataWords.length * 4;
|
|
809
|
+
this._process();
|
|
810
|
+
return this._hash;
|
|
622
811
|
},
|
|
623
812
|
clone: function() {
|
|
624
|
-
var
|
|
625
|
-
|
|
813
|
+
var clone = Hasher.clone.call(this);
|
|
814
|
+
clone._hash = this._hash.clone();
|
|
815
|
+
return clone;
|
|
626
816
|
}
|
|
627
817
|
});
|
|
628
|
-
|
|
629
|
-
|
|
818
|
+
C.SHA256 = Hasher._createHelper(SHA256);
|
|
819
|
+
C.HmacSHA256 = Hasher._createHmacHelper(SHA256);
|
|
820
|
+
})(Math);
|
|
821
|
+
return CryptoJS.SHA256;
|
|
630
822
|
});
|
|
631
|
-
})(
|
|
632
|
-
var
|
|
823
|
+
})(sha256);
|
|
824
|
+
var encBase64Exports = {};
|
|
825
|
+
var encBase64 = {
|
|
633
826
|
get exports() {
|
|
634
|
-
return
|
|
827
|
+
return encBase64Exports;
|
|
635
828
|
},
|
|
636
|
-
set exports(
|
|
637
|
-
|
|
829
|
+
set exports(v) {
|
|
830
|
+
encBase64Exports = v;
|
|
638
831
|
}
|
|
639
832
|
};
|
|
640
|
-
(function(
|
|
641
|
-
(function(
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
833
|
+
(function(module, exports) {
|
|
834
|
+
(function(root, factory) {
|
|
835
|
+
{
|
|
836
|
+
module.exports = factory(requireCore());
|
|
837
|
+
}
|
|
838
|
+
})(commonjsGlobal, function(CryptoJS) {
|
|
839
|
+
(function() {
|
|
840
|
+
var C = CryptoJS;
|
|
841
|
+
var C_lib = C.lib;
|
|
842
|
+
var WordArray = C_lib.WordArray;
|
|
843
|
+
var C_enc = C.enc;
|
|
844
|
+
C_enc.Base64 = {
|
|
647
845
|
/**
|
|
648
846
|
* Converts a word array to a Base64 string.
|
|
649
847
|
*
|
|
@@ -657,17 +855,28 @@ var Be = {}, yr = {
|
|
|
657
855
|
*
|
|
658
856
|
* var base64String = CryptoJS.enc.Base64.stringify(wordArray);
|
|
659
857
|
*/
|
|
660
|
-
stringify: function(
|
|
661
|
-
var
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
var
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
858
|
+
stringify: function(wordArray) {
|
|
859
|
+
var words = wordArray.words;
|
|
860
|
+
var sigBytes = wordArray.sigBytes;
|
|
861
|
+
var map = this._map;
|
|
862
|
+
wordArray.clamp();
|
|
863
|
+
var base64Chars = [];
|
|
864
|
+
for (var i = 0; i < sigBytes; i += 3) {
|
|
865
|
+
var byte1 = words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
|
866
|
+
var byte2 = words[i + 1 >>> 2] >>> 24 - (i + 1) % 4 * 8 & 255;
|
|
867
|
+
var byte3 = words[i + 2 >>> 2] >>> 24 - (i + 2) % 4 * 8 & 255;
|
|
868
|
+
var triplet = byte1 << 16 | byte2 << 8 | byte3;
|
|
869
|
+
for (var j = 0; j < 4 && i + j * 0.75 < sigBytes; j++) {
|
|
870
|
+
base64Chars.push(map.charAt(triplet >>> 6 * (3 - j) & 63));
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
var paddingChar = map.charAt(64);
|
|
874
|
+
if (paddingChar) {
|
|
875
|
+
while (base64Chars.length % 4) {
|
|
876
|
+
base64Chars.push(paddingChar);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
return base64Chars.join("");
|
|
671
880
|
},
|
|
672
881
|
/**
|
|
673
882
|
* Converts a Base64 string to a word array.
|
|
@@ -682,152 +891,227 @@ var Be = {}, yr = {
|
|
|
682
891
|
*
|
|
683
892
|
* var wordArray = CryptoJS.enc.Base64.parse(base64String);
|
|
684
893
|
*/
|
|
685
|
-
parse: function(
|
|
686
|
-
var
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
894
|
+
parse: function(base64Str) {
|
|
895
|
+
var base64StrLength = base64Str.length;
|
|
896
|
+
var map = this._map;
|
|
897
|
+
var reverseMap = this._reverseMap;
|
|
898
|
+
if (!reverseMap) {
|
|
899
|
+
reverseMap = this._reverseMap = [];
|
|
900
|
+
for (var j = 0; j < map.length; j++) {
|
|
901
|
+
reverseMap[map.charCodeAt(j)] = j;
|
|
902
|
+
}
|
|
691
903
|
}
|
|
692
|
-
var
|
|
693
|
-
if (
|
|
694
|
-
var
|
|
695
|
-
|
|
904
|
+
var paddingChar = map.charAt(64);
|
|
905
|
+
if (paddingChar) {
|
|
906
|
+
var paddingIndex = base64Str.indexOf(paddingChar);
|
|
907
|
+
if (paddingIndex !== -1) {
|
|
908
|
+
base64StrLength = paddingIndex;
|
|
909
|
+
}
|
|
696
910
|
}
|
|
697
|
-
return
|
|
911
|
+
return parseLoop(base64Str, base64StrLength, reverseMap);
|
|
698
912
|
},
|
|
699
913
|
_map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
|
|
700
914
|
};
|
|
701
|
-
function
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
915
|
+
function parseLoop(base64Str, base64StrLength, reverseMap) {
|
|
916
|
+
var words = [];
|
|
917
|
+
var nBytes = 0;
|
|
918
|
+
for (var i = 0; i < base64StrLength; i++) {
|
|
919
|
+
if (i % 4) {
|
|
920
|
+
var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << i % 4 * 2;
|
|
921
|
+
var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> 6 - i % 4 * 2;
|
|
922
|
+
var bitsCombined = bits1 | bits2;
|
|
923
|
+
words[nBytes >>> 2] |= bitsCombined << 24 - nBytes % 4 * 8;
|
|
924
|
+
nBytes++;
|
|
706
925
|
}
|
|
707
|
-
|
|
926
|
+
}
|
|
927
|
+
return WordArray.create(words, nBytes);
|
|
708
928
|
}
|
|
709
|
-
}()
|
|
929
|
+
})();
|
|
930
|
+
return CryptoJS.enc.Base64;
|
|
710
931
|
});
|
|
711
|
-
})(
|
|
712
|
-
|
|
713
|
-
class Xe {
|
|
932
|
+
})(encBase64);
|
|
933
|
+
class CryptoUtils {
|
|
714
934
|
constructor() {
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
const
|
|
718
|
-
return
|
|
935
|
+
__privateAdd(this, _crypto, void 0);
|
|
936
|
+
__publicField(this, "DigestMessage", async function(message) {
|
|
937
|
+
const hashDigest = sha256Exports(message);
|
|
938
|
+
return encBase64Exports.stringify(hashDigest);
|
|
719
939
|
});
|
|
720
|
-
|
|
721
|
-
const
|
|
722
|
-
|
|
940
|
+
__publicField(this, "CreateRandomString", (size = 43) => {
|
|
941
|
+
const randomValues = Array.from(__privateGet(this, _crypto).getRandomValues(new Uint8Array(size)));
|
|
942
|
+
const b64 = btoa(String.fromCharCode(...randomValues));
|
|
943
|
+
return b64;
|
|
723
944
|
});
|
|
724
945
|
try {
|
|
725
|
-
|
|
946
|
+
__privateSet(this, _crypto, crypto);
|
|
726
947
|
} catch {
|
|
727
|
-
|
|
948
|
+
__privateSet(this, _crypto, require("crypto"));
|
|
728
949
|
}
|
|
729
950
|
}
|
|
730
951
|
}
|
|
731
|
-
|
|
732
|
-
class
|
|
952
|
+
_crypto = new WeakMap();
|
|
953
|
+
class QueryParams {
|
|
733
954
|
constructor() {
|
|
734
|
-
|
|
735
|
-
const
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
})
|
|
955
|
+
__publicField(this, "DecodeQueryParams", (params) => {
|
|
956
|
+
const retObj = {};
|
|
957
|
+
Object.keys(params).filter((k) => typeof params[k] !== "undefined").map((k) => {
|
|
958
|
+
retObj[decodeURIComponent(k)] = decodeURIComponent(params[k]);
|
|
959
|
+
});
|
|
960
|
+
return retObj;
|
|
961
|
+
});
|
|
962
|
+
__publicField(this, "CreateQueryParams", (params) => {
|
|
963
|
+
return Object.keys(params).filter((k) => typeof params[k] !== "undefined").map((k) => {
|
|
964
|
+
if (Array.isArray(params[k])) {
|
|
965
|
+
return encodeURIComponent(k) + "=" + encodeURIComponent(params[k].join(" "));
|
|
966
|
+
} else {
|
|
967
|
+
return encodeURIComponent(k) + "=" + encodeURIComponent(params[k]);
|
|
968
|
+
}
|
|
969
|
+
}).join("&");
|
|
739
970
|
});
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
const
|
|
746
|
-
let
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
971
|
+
__publicField(this, "_GetQueryParams", (param) => {
|
|
972
|
+
let retVal = {};
|
|
973
|
+
const uri = param.split("?");
|
|
974
|
+
if (uri.length == 2) {
|
|
975
|
+
const vars = uri[1].split("&");
|
|
976
|
+
const getVars = {};
|
|
977
|
+
let tmp;
|
|
978
|
+
vars.forEach(function(v) {
|
|
979
|
+
tmp = v.split("=");
|
|
980
|
+
if (tmp.length == 2)
|
|
981
|
+
getVars[tmp[0]] = tmp[1];
|
|
982
|
+
});
|
|
983
|
+
retVal = this.DecodeQueryParams(getVars);
|
|
750
984
|
}
|
|
751
|
-
return
|
|
985
|
+
return retVal;
|
|
986
|
+
});
|
|
987
|
+
__publicField(this, "GetQueryParams", () => {
|
|
988
|
+
return this._GetQueryParams(window.location.href);
|
|
752
989
|
});
|
|
753
|
-
D(this, "GetQueryParams", () => this._GetQueryParams(window.location.href));
|
|
754
990
|
}
|
|
755
991
|
}
|
|
756
|
-
var
|
|
757
|
-
|
|
758
|
-
|
|
992
|
+
var AuthorizeOptionsResponseType = /* @__PURE__ */ ((AuthorizeOptionsResponseType2) => {
|
|
993
|
+
AuthorizeOptionsResponseType2["CODE"] = "code";
|
|
994
|
+
AuthorizeOptionsResponseType2["ID_TOKEN"] = "id_token";
|
|
995
|
+
AuthorizeOptionsResponseType2["TOKEN"] = "token";
|
|
996
|
+
return AuthorizeOptionsResponseType2;
|
|
997
|
+
})(AuthorizeOptionsResponseType || {});
|
|
998
|
+
var AuthorizeOptionsResponseMode = /* @__PURE__ */ ((AuthorizeOptionsResponseMode2) => {
|
|
999
|
+
AuthorizeOptionsResponseMode2["QUERY"] = "query";
|
|
1000
|
+
AuthorizeOptionsResponseMode2["FRAGMENT"] = "fragment";
|
|
1001
|
+
AuthorizeOptionsResponseMode2["FORM_POST"] = "form_post";
|
|
1002
|
+
return AuthorizeOptionsResponseMode2;
|
|
1003
|
+
})(AuthorizeOptionsResponseMode || {});
|
|
1004
|
+
var OAuthGrantTypes = /* @__PURE__ */ ((OAuthGrantTypes2) => {
|
|
1005
|
+
OAuthGrantTypes2["CLIENT_CREDENTIALS"] = "client_credentials";
|
|
1006
|
+
OAuthGrantTypes2["AUTHORIZATION_CODE"] = "authorization_code";
|
|
1007
|
+
OAuthGrantTypes2["REFRESH_TOKEN"] = "refresh_token";
|
|
1008
|
+
return OAuthGrantTypes2;
|
|
1009
|
+
})(OAuthGrantTypes || {});
|
|
1010
|
+
var IOauth2ListenerCommand = /* @__PURE__ */ ((IOauth2ListenerCommand2) => {
|
|
1011
|
+
IOauth2ListenerCommand2["RESTORE_SESSION"] = "RestoreSession";
|
|
1012
|
+
IOauth2ListenerCommand2["AUTHORIZE"] = "Authorize";
|
|
1013
|
+
IOauth2ListenerCommand2["HANDLE_REDIRECT"] = "HandleRedirect";
|
|
1014
|
+
IOauth2ListenerCommand2["LOGOUT"] = "Logout";
|
|
1015
|
+
IOauth2ListenerCommand2["AUTHENTICATE_EVENT"] = "AuthenticateEvent";
|
|
1016
|
+
IOauth2ListenerCommand2["ERROR"] = "Error";
|
|
1017
|
+
IOauth2ListenerCommand2["LOG"] = "__LOG";
|
|
1018
|
+
IOauth2ListenerCommand2["UPDATE_INSTRUMENT"] = "__UPDATE_INSTRUMENT";
|
|
1019
|
+
IOauth2ListenerCommand2["ID_TOKEN"] = "__ID_TOKEN";
|
|
1020
|
+
IOauth2ListenerCommand2["ACCESS_TOKEN"] = "__ACCESS_TOKEN";
|
|
1021
|
+
IOauth2ListenerCommand2["COOKIES"] = "__COOKIES";
|
|
1022
|
+
IOauth2ListenerCommand2["EXECUTE_REFRESH_TOKEN"] = "__EXECUTE_REFRESH_TOKEN";
|
|
1023
|
+
return IOauth2ListenerCommand2;
|
|
1024
|
+
})(IOauth2ListenerCommand || {});
|
|
1025
|
+
function e(e2) {
|
|
1026
|
+
this.message = e2;
|
|
759
1027
|
}
|
|
760
|
-
|
|
761
|
-
var
|
|
762
|
-
var
|
|
763
|
-
if (
|
|
764
|
-
throw new
|
|
765
|
-
for (var
|
|
766
|
-
|
|
767
|
-
return
|
|
1028
|
+
e.prototype = new Error(), e.prototype.name = "InvalidCharacterError";
|
|
1029
|
+
var r = "undefined" != typeof window && window.atob && window.atob.bind(window) || function(r2) {
|
|
1030
|
+
var t2 = String(r2).replace(/=+$/, "");
|
|
1031
|
+
if (t2.length % 4 == 1)
|
|
1032
|
+
throw new e("'atob' failed: The string to be decoded is not correctly encoded.");
|
|
1033
|
+
for (var n2, o2, a = 0, i = 0, c = ""; o2 = t2.charAt(i++); ~o2 && (n2 = a % 4 ? 64 * n2 + o2 : o2, a++ % 4) ? c += String.fromCharCode(255 & n2 >> (-2 * a & 6)) : 0)
|
|
1034
|
+
o2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o2);
|
|
1035
|
+
return c;
|
|
768
1036
|
};
|
|
769
|
-
function
|
|
770
|
-
var
|
|
771
|
-
switch (
|
|
1037
|
+
function t(e2) {
|
|
1038
|
+
var t2 = e2.replace(/-/g, "+").replace(/_/g, "/");
|
|
1039
|
+
switch (t2.length % 4) {
|
|
772
1040
|
case 0:
|
|
773
1041
|
break;
|
|
774
1042
|
case 2:
|
|
775
|
-
|
|
1043
|
+
t2 += "==";
|
|
776
1044
|
break;
|
|
777
1045
|
case 3:
|
|
778
|
-
|
|
1046
|
+
t2 += "=";
|
|
779
1047
|
break;
|
|
780
1048
|
default:
|
|
781
1049
|
throw "Illegal base64url string!";
|
|
782
1050
|
}
|
|
783
1051
|
try {
|
|
784
|
-
return function(
|
|
785
|
-
return decodeURIComponent(
|
|
786
|
-
var
|
|
787
|
-
return
|
|
1052
|
+
return function(e3) {
|
|
1053
|
+
return decodeURIComponent(r(e3).replace(/(.)/g, function(e4, r2) {
|
|
1054
|
+
var t3 = r2.charCodeAt(0).toString(16).toUpperCase();
|
|
1055
|
+
return t3.length < 2 && (t3 = "0" + t3), "%" + t3;
|
|
788
1056
|
}));
|
|
789
|
-
}(
|
|
790
|
-
} catch {
|
|
791
|
-
return
|
|
1057
|
+
}(t2);
|
|
1058
|
+
} catch (e3) {
|
|
1059
|
+
return r(t2);
|
|
792
1060
|
}
|
|
793
1061
|
}
|
|
794
|
-
function
|
|
795
|
-
this.message =
|
|
1062
|
+
function n(e2) {
|
|
1063
|
+
this.message = e2;
|
|
796
1064
|
}
|
|
797
|
-
function
|
|
798
|
-
if (
|
|
799
|
-
throw new
|
|
800
|
-
var
|
|
1065
|
+
function o(e2, r2) {
|
|
1066
|
+
if ("string" != typeof e2)
|
|
1067
|
+
throw new n("Invalid token specified");
|
|
1068
|
+
var o2 = true === (r2 = r2 || {}).header ? 0 : 1;
|
|
801
1069
|
try {
|
|
802
|
-
return JSON.parse(
|
|
803
|
-
} catch (
|
|
804
|
-
throw new
|
|
1070
|
+
return JSON.parse(t(e2.split(".")[o2]));
|
|
1071
|
+
} catch (e3) {
|
|
1072
|
+
throw new n("Invalid token specified: " + e3.message);
|
|
805
1073
|
}
|
|
806
1074
|
}
|
|
807
|
-
|
|
808
|
-
const
|
|
809
|
-
state: () =>
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
1075
|
+
n.prototype = new Error(), n.prototype.name = "InvalidTokenError";
|
|
1076
|
+
const STSOauth2Store = defineStore("__sts__STSOauth2Store", {
|
|
1077
|
+
state: () => {
|
|
1078
|
+
return {
|
|
1079
|
+
id_token: null,
|
|
1080
|
+
error: null
|
|
1081
|
+
};
|
|
1082
|
+
},
|
|
813
1083
|
actions: {
|
|
814
|
-
UpdateIdToken(
|
|
815
|
-
this.id_token =
|
|
1084
|
+
UpdateIdToken(id_token) {
|
|
1085
|
+
this.id_token = id_token;
|
|
816
1086
|
},
|
|
817
|
-
UpdateError(
|
|
818
|
-
|
|
819
|
-
message
|
|
820
|
-
}
|
|
1087
|
+
UpdateError(error) {
|
|
1088
|
+
if (this.error) {
|
|
1089
|
+
this.error.message = error;
|
|
1090
|
+
} else {
|
|
1091
|
+
this.error = {
|
|
1092
|
+
message: error
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
821
1095
|
}
|
|
822
1096
|
},
|
|
823
1097
|
getters: {
|
|
824
|
-
LoggedIn: (
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
1098
|
+
LoggedIn: (state) => {
|
|
1099
|
+
if (typeof state.id_token === "undefined") {
|
|
1100
|
+
return false;
|
|
1101
|
+
}
|
|
1102
|
+
if (state.id_token === null) {
|
|
1103
|
+
return false;
|
|
1104
|
+
}
|
|
1105
|
+
return true;
|
|
1106
|
+
},
|
|
1107
|
+
UserDetails: (state) => {
|
|
1108
|
+
if (state.id_token) {
|
|
1109
|
+
const id_token = state.id_token;
|
|
1110
|
+
const decodedIdToken = o(id_token);
|
|
1111
|
+
return decodedIdToken;
|
|
1112
|
+
} else {
|
|
830
1113
|
return null;
|
|
1114
|
+
}
|
|
831
1115
|
}
|
|
832
1116
|
}
|
|
833
1117
|
/*
|
|
@@ -836,281 +1120,363 @@ const Sr = qe("__sts__STSOauth2Store", {
|
|
|
836
1120
|
}
|
|
837
1121
|
*/
|
|
838
1122
|
});
|
|
839
|
-
let
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
1123
|
+
let debug$1;
|
|
1124
|
+
if (isNode) {
|
|
1125
|
+
debug$1 = Debug(`proc:${process.pid}:stsoauth2manager.ts`);
|
|
1126
|
+
} else {
|
|
1127
|
+
debug$1 = Debug(`proc:0:stsoauth2manager.ts`);
|
|
1128
|
+
}
|
|
1129
|
+
class STSOAuth2Manager {
|
|
843
1130
|
// ms
|
|
844
|
-
constructor(
|
|
1131
|
+
constructor(app, options) {
|
|
845
1132
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
1133
|
+
__privateAdd(this, _router, null);
|
|
1134
|
+
__privateAdd(this, _cUtils, new CryptoUtils());
|
|
1135
|
+
__privateAdd(this, _qParams, new QueryParams());
|
|
1136
|
+
__privateAdd(this, _STORAGE_AUTHORIZE_OPTIONS_KEY, "authorize_options.stsmda.com.au");
|
|
1137
|
+
__privateAdd(this, _STORAGE_SESSION_KEY, "session.stsmda.com.au");
|
|
1138
|
+
__privateAdd(this, _aic, null);
|
|
1139
|
+
__privateAdd(this, _options, void 0);
|
|
1140
|
+
__privateAdd(this, _messages, {});
|
|
1141
|
+
__privateAdd(this, _oauth2ManagerPort, void 0);
|
|
1142
|
+
__privateAdd(this, _messageId, 0);
|
|
856
1143
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
857
|
-
|
|
1144
|
+
__privateAdd(this, _messageHandlers, {});
|
|
858
1145
|
// keyed by messageId
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
1146
|
+
__privateAdd(this, _messageTimeout, 1e4);
|
|
1147
|
+
__privateAdd(this, _worker, void 0);
|
|
1148
|
+
__privateAdd(this, _transactionStore, void 0);
|
|
862
1149
|
// Transient transaction data used to establish a session via OAuth2 authorize handshake
|
|
863
|
-
|
|
864
|
-
|
|
1150
|
+
__privateAdd(this, _operationSemaphore, false);
|
|
1151
|
+
__privateAdd(this, _maxSemaphoreRetries, 100);
|
|
865
1152
|
// 100 retries, i.e. allow 100 x 50 = 5000ms to unblock
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
const
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
1153
|
+
__privateAdd(this, _semaphoreRetrySleep, 50);
|
|
1154
|
+
__privateAdd(this, _ProcessMessageResponse, (data) => {
|
|
1155
|
+
const messageResponse = data;
|
|
1156
|
+
debug$1(`STSOAuth2Manager:#ProcessMessageResponse: message data = [${JSON.stringify(messageResponse)}]`.yellow);
|
|
1157
|
+
if (messageResponse.messageId === -1) {
|
|
1158
|
+
switch (messageResponse.command) {
|
|
1159
|
+
case IOauth2ListenerCommand.AUTHENTICATE_EVENT:
|
|
1160
|
+
__privateGet(this, _HandleAuthenticateEvent).call(this, messageResponse.payload);
|
|
873
1161
|
break;
|
|
874
|
-
case
|
|
875
|
-
|
|
1162
|
+
case IOauth2ListenerCommand.ERROR:
|
|
1163
|
+
__privateGet(this, _HandleErrorEvent).call(this, messageResponse.payload);
|
|
876
1164
|
break;
|
|
877
|
-
case
|
|
878
|
-
|
|
1165
|
+
case IOauth2ListenerCommand.LOG:
|
|
1166
|
+
__privateGet(this, _HandleLogEvent).call(this, messageResponse.payload);
|
|
879
1167
|
break;
|
|
880
|
-
case
|
|
881
|
-
|
|
1168
|
+
case IOauth2ListenerCommand.UPDATE_INSTRUMENT:
|
|
1169
|
+
__privateGet(this, _HandleUpdateInstrumentEvent).call(this, messageResponse.payload.instrumentName, messageResponse.payload.telemetry);
|
|
882
1170
|
break;
|
|
883
1171
|
default:
|
|
884
|
-
throw new Error(`ProcessMessageResponse command [${
|
|
1172
|
+
throw new Error(`ProcessMessageResponse command [${messageResponse.command}] not valid.`);
|
|
1173
|
+
}
|
|
1174
|
+
} else {
|
|
1175
|
+
const callBack = __privateGet(this, _messageHandlers)[messageResponse.messageId];
|
|
1176
|
+
if (callBack) {
|
|
1177
|
+
callBack(messageResponse);
|
|
1178
|
+
} else {
|
|
1179
|
+
throw new Error(`Message: [${messageResponse.messageId}] does not exists in callBacks.`);
|
|
885
1180
|
}
|
|
886
|
-
else {
|
|
887
|
-
const n = r(this, Y)[o.messageId];
|
|
888
|
-
if (n)
|
|
889
|
-
n(o);
|
|
890
|
-
else
|
|
891
|
-
throw new Error(`Message: [${o.messageId}] does not exists in callBacks.`);
|
|
892
1181
|
}
|
|
893
1182
|
});
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
1183
|
+
__privateAdd(this, _PostMessage, (message) => {
|
|
1184
|
+
message.messageId = __privateWrapper(this, _messageId)._++;
|
|
1185
|
+
return new Promise((resolve, reject) => {
|
|
1186
|
+
const timeout = setTimeout(() => {
|
|
1187
|
+
delete __privateGet(this, _messageHandlers)[message.messageId];
|
|
1188
|
+
reject(`Message: [${message.messageId}] timeout error after: [${__privateGet(this, _messageTimeout)}] ms.`);
|
|
1189
|
+
}, __privateGet(this, _messageTimeout));
|
|
1190
|
+
__privateGet(this, _messageHandlers)[message.messageId] = (response) => {
|
|
1191
|
+
clearTimeout(timeout);
|
|
1192
|
+
delete __privateGet(this, _messageHandlers)[message.messageId];
|
|
1193
|
+
debug$1(`STSOAuth2Manager:#PostMessage: resolve callback response= [${JSON.stringify(response)}]`.yellow);
|
|
1194
|
+
resolve(response);
|
|
1195
|
+
};
|
|
1196
|
+
debug$1(`STSOAuth2Manager:#PostMessage: posting message = [${JSON.stringify(message)}]`.yellow);
|
|
1197
|
+
__privateGet(this, _oauth2ManagerPort).postMessage(message);
|
|
1198
|
+
});
|
|
1199
|
+
});
|
|
1200
|
+
__privateAdd(this, _HandleLogEvent, (message) => {
|
|
1201
|
+
if (__privateGet(this, _aic)) {
|
|
1202
|
+
__privateGet(this, _aic).LogEx(message);
|
|
1203
|
+
}
|
|
1204
|
+
debug$1(message);
|
|
904
1205
|
});
|
|
905
1206
|
// UpdateInstrument = (instrumentName: Gauge, telemetry: InstrumentBaseTelemetry): void => {
|
|
906
|
-
|
|
907
|
-
|
|
1207
|
+
__privateAdd(this, _HandleUpdateInstrumentEvent, (instrumentName, telemetry) => {
|
|
1208
|
+
if (__privateGet(this, _aic)) {
|
|
1209
|
+
__privateGet(this, _aic).UpdateInstrument(instrumentName, telemetry);
|
|
1210
|
+
}
|
|
1211
|
+
});
|
|
1212
|
+
__privateAdd(this, _GetStore, () => {
|
|
1213
|
+
return STSOauth2Store(__privateGet(this, _options).pinia);
|
|
908
1214
|
});
|
|
909
|
-
l(this, V, () => Sr(r(this, $).pinia));
|
|
910
1215
|
// Will come from message channel
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
1216
|
+
__privateAdd(this, _HandleErrorEvent, (error) => {
|
|
1217
|
+
if (isNode)
|
|
1218
|
+
;
|
|
1219
|
+
else {
|
|
1220
|
+
__privateGet(this, _GetStore).call(this).UpdateError({
|
|
1221
|
+
// Authorize applications store
|
|
1222
|
+
message: error
|
|
1223
|
+
});
|
|
1224
|
+
setTimeout(() => {
|
|
1225
|
+
__privateGet(this, _router).replace("/error");
|
|
1226
|
+
}, 0);
|
|
1227
|
+
}
|
|
918
1228
|
});
|
|
919
|
-
|
|
920
|
-
|
|
1229
|
+
__privateAdd(this, _HandleAuthenticateEvent, (id_token) => {
|
|
1230
|
+
if (isNode)
|
|
1231
|
+
;
|
|
1232
|
+
else {
|
|
1233
|
+
if (__privateGet(this, _options).authenticateEvent) {
|
|
1234
|
+
__privateGet(this, _options).authenticateEvent(id_token);
|
|
1235
|
+
}
|
|
1236
|
+
__privateGet(this, _GetStore).call(this).UpdateIdToken(id_token);
|
|
1237
|
+
}
|
|
921
1238
|
});
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
1239
|
+
__privateAdd(this, _SetupRoute, (app, router) => {
|
|
1240
|
+
debug$1(`STSOAuth2Manager:#SetupRoute`.gray);
|
|
1241
|
+
router.beforeEach(async (to, from, next) => {
|
|
1242
|
+
const oAuth2Manager = app.config.globalProperties.$sts[STSOAuth2ManagerPluginKey];
|
|
1243
|
+
debug$1(`beforeEach: from: [${from.path}], to: [${to.path}]`.gray);
|
|
1244
|
+
if (__privateGet(this, _GetStore).call(this).LoggedIn === false) {
|
|
1245
|
+
console.log(`Not logged in`);
|
|
1246
|
+
if (to.path.localeCompare("/authorize") === 0) {
|
|
1247
|
+
console.log(`to = /authorize`);
|
|
1248
|
+
next();
|
|
931
1249
|
return;
|
|
1250
|
+
} else if (to.path.localeCompare("/consent") === 0) {
|
|
1251
|
+
if (__privateGet(this, _GetStore).call(this).id_token) {
|
|
1252
|
+
next();
|
|
1253
|
+
return;
|
|
1254
|
+
}
|
|
932
1255
|
}
|
|
933
|
-
if (
|
|
934
|
-
|
|
1256
|
+
if (to.path.localeCompare("/logout") === 0) {
|
|
1257
|
+
next();
|
|
935
1258
|
return;
|
|
936
1259
|
}
|
|
937
|
-
if (
|
|
938
|
-
|
|
1260
|
+
if (to.path.localeCompare("/error") === 0) {
|
|
1261
|
+
next();
|
|
939
1262
|
return;
|
|
940
1263
|
}
|
|
941
|
-
if (
|
|
942
|
-
|
|
1264
|
+
if (to.path.localeCompare("/config") === 0) {
|
|
1265
|
+
next();
|
|
943
1266
|
return;
|
|
944
1267
|
}
|
|
945
|
-
if (
|
|
946
|
-
|
|
1268
|
+
if (to.path.localeCompare("/redirected") === 0) {
|
|
1269
|
+
next();
|
|
947
1270
|
return;
|
|
948
1271
|
}
|
|
949
|
-
const
|
|
950
|
-
if (
|
|
951
|
-
|
|
952
|
-
const
|
|
953
|
-
|
|
954
|
-
|
|
1272
|
+
const str = to.query;
|
|
1273
|
+
if (str[OAuth2ParameterType.CODE] || str[OAuth2ParameterType.ERROR]) {
|
|
1274
|
+
debug$1(`STSOAuth2Manager:#SetupRoute:Processing redirect: [${JSON.stringify(str)}]`.magenta);
|
|
1275
|
+
const retVal = await oAuth2Manager.HandleRedirect(str);
|
|
1276
|
+
debug$1(`STSOAuth2Manager:#SetupRoute:Redirect result: [${retVal}]`.magenta);
|
|
1277
|
+
if (retVal) {
|
|
1278
|
+
next({
|
|
955
1279
|
path: "/",
|
|
956
|
-
replace:
|
|
1280
|
+
replace: true
|
|
957
1281
|
});
|
|
958
1282
|
return;
|
|
959
1283
|
} else {
|
|
960
|
-
|
|
1284
|
+
next({
|
|
961
1285
|
path: "/error",
|
|
962
|
-
replace:
|
|
1286
|
+
replace: true
|
|
963
1287
|
});
|
|
964
1288
|
return;
|
|
965
1289
|
}
|
|
966
1290
|
}
|
|
967
|
-
|
|
968
|
-
const
|
|
969
|
-
|
|
970
|
-
|
|
1291
|
+
debug$1(`STSOAuth2Manager:#SetupRoute:Restoring session`);
|
|
1292
|
+
const sessionRestored = await oAuth2Manager.RestoreSession();
|
|
1293
|
+
debug$1(`STSOAuth2Manager:#SetupRoute:Session restored: [${sessionRestored}]`);
|
|
1294
|
+
if (sessionRestored !== true) {
|
|
1295
|
+
debug$1(`STSOAuth2Manager:#SetupRoute:Session not restored - need to authorize`);
|
|
1296
|
+
oAuth2Manager.Authorize();
|
|
1297
|
+
next();
|
|
971
1298
|
return;
|
|
972
1299
|
} else {
|
|
973
|
-
|
|
1300
|
+
next("/");
|
|
974
1301
|
return;
|
|
975
1302
|
}
|
|
976
1303
|
} else {
|
|
977
|
-
if (
|
|
978
|
-
|
|
1304
|
+
if (to.path.localeCompare("/consent") === 0) {
|
|
1305
|
+
next("/");
|
|
979
1306
|
return;
|
|
980
1307
|
}
|
|
981
|
-
if (
|
|
982
|
-
|
|
1308
|
+
if (to.path.localeCompare("/authorize") === 0) {
|
|
1309
|
+
next("/");
|
|
983
1310
|
return;
|
|
984
1311
|
}
|
|
985
|
-
if (
|
|
986
|
-
|
|
1312
|
+
if (to.path.localeCompare("/logout") === 0) {
|
|
1313
|
+
next("/");
|
|
987
1314
|
return;
|
|
988
1315
|
}
|
|
989
|
-
|
|
1316
|
+
next();
|
|
990
1317
|
}
|
|
991
1318
|
});
|
|
992
1319
|
});
|
|
993
1320
|
//@@ this needs to be re-implemented so that access_token never leaves the auth worker
|
|
994
|
-
|
|
1321
|
+
__publicField(this, "GetAccessToken", async () => {
|
|
1322
|
+
const response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.ACCESS_TOKEN });
|
|
1323
|
+
return response.payload;
|
|
1324
|
+
});
|
|
995
1325
|
// Update operation protected using operationSemaphore. This may occur when using workers and/or multiple async fetch operations.
|
|
996
|
-
|
|
997
|
-
if (
|
|
998
|
-
if (
|
|
999
|
-
throw new Error(`STSOAuth2Manager:ExecuteRefreshToken:maxSemaphoreRetries: [${
|
|
1000
|
-
|
|
1326
|
+
__publicField(this, "ExecuteRefreshToken", async (retryCount = 0) => {
|
|
1327
|
+
if (__privateGet(this, _operationSemaphore) === true) {
|
|
1328
|
+
if (retryCount > __privateGet(this, _maxSemaphoreRetries)) {
|
|
1329
|
+
throw new Error(`STSOAuth2Manager:ExecuteRefreshToken:maxSemaphoreRetries: [${__privateGet(this, _maxSemaphoreRetries)}] exceeded.`);
|
|
1330
|
+
}
|
|
1331
|
+
await Sleep(__privateGet(this, _semaphoreRetrySleep));
|
|
1332
|
+
debug$1(`STSOAuth2Manager:ExecuteRefreshToken:locked by operationSemaphore, retry count: [${retryCount}]`.cyan);
|
|
1333
|
+
return await this.ExecuteRefreshToken(retryCount + 1);
|
|
1001
1334
|
} else {
|
|
1002
|
-
|
|
1003
|
-
const
|
|
1004
|
-
|
|
1335
|
+
__privateSet(this, _operationSemaphore, true);
|
|
1336
|
+
const response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.EXECUTE_REFRESH_TOKEN });
|
|
1337
|
+
__privateSet(this, _operationSemaphore, false);
|
|
1338
|
+
return response.payload;
|
|
1005
1339
|
}
|
|
1006
1340
|
});
|
|
1007
1341
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1008
|
-
|
|
1009
|
-
|
|
1342
|
+
__publicField(this, "GetCookies", async () => {
|
|
1343
|
+
const response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.COOKIES });
|
|
1344
|
+
return response.payload;
|
|
1345
|
+
});
|
|
1346
|
+
__publicField(this, "RestoreSession", async () => {
|
|
1010
1347
|
try {
|
|
1011
|
-
|
|
1012
|
-
const
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1348
|
+
debug$1(`STSOAuth2Manager:RestoreSession:postMessage: [${IOauth2ListenerCommand.RESTORE_SESSION}]`);
|
|
1349
|
+
const response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.RESTORE_SESSION });
|
|
1350
|
+
debug$1(`STSOAuth2Manager:RestoreSession:response: [${JSON.stringify(response.payload)}]`);
|
|
1351
|
+
return response.payload;
|
|
1352
|
+
} catch (error) {
|
|
1353
|
+
console.log(`RestoreSession Error: ${error}`);
|
|
1354
|
+
return false;
|
|
1016
1355
|
}
|
|
1017
1356
|
});
|
|
1018
|
-
|
|
1357
|
+
__publicField(this, "Authorize", async () => {
|
|
1019
1358
|
try {
|
|
1020
|
-
const
|
|
1021
|
-
|
|
1022
|
-
const
|
|
1023
|
-
if (!
|
|
1024
|
-
window.location.replace(
|
|
1025
|
-
else
|
|
1026
|
-
return
|
|
1027
|
-
|
|
1028
|
-
|
|
1359
|
+
const response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.AUTHORIZE });
|
|
1360
|
+
__privateGet(this, _transactionStore).set(__privateGet(this, _STORAGE_AUTHORIZE_OPTIONS_KEY), response.payload.authorizeOptions);
|
|
1361
|
+
const url = response.payload.url;
|
|
1362
|
+
if (!isNode) {
|
|
1363
|
+
window.location.replace(url);
|
|
1364
|
+
} else {
|
|
1365
|
+
return response.payload.authorizeOptionsClientCopy;
|
|
1366
|
+
}
|
|
1367
|
+
} catch (error) {
|
|
1368
|
+
console.log(`Authorize Error: ${error}`);
|
|
1029
1369
|
}
|
|
1030
1370
|
return {};
|
|
1031
1371
|
});
|
|
1032
|
-
|
|
1372
|
+
__publicField(this, "HandleRedirect", async (queryVars) => {
|
|
1033
1373
|
try {
|
|
1034
|
-
|
|
1035
|
-
let
|
|
1036
|
-
if (
|
|
1037
|
-
const
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1374
|
+
debug$1(`STSOAuth2Manager:HandleRedirect`.magenta);
|
|
1375
|
+
let response = null;
|
|
1376
|
+
if (queryVars[OAuth2ParameterType.CODE]) {
|
|
1377
|
+
const authorizeOptions = __privateGet(this, _transactionStore).get(__privateGet(this, _STORAGE_AUTHORIZE_OPTIONS_KEY));
|
|
1378
|
+
__privateGet(this, _transactionStore).remove(__privateGet(this, _STORAGE_AUTHORIZE_OPTIONS_KEY));
|
|
1379
|
+
debug$1(`STSOAuth2Manager:HandleRedirect: sending HANDLE_REDIRECT command`.magenta);
|
|
1380
|
+
response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.HANDLE_REDIRECT, payload: {
|
|
1381
|
+
queryVars,
|
|
1382
|
+
authorizeOptions
|
|
1041
1383
|
} });
|
|
1042
|
-
} else
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
return
|
|
1384
|
+
} else {
|
|
1385
|
+
response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.HANDLE_REDIRECT, payload: queryVars });
|
|
1386
|
+
}
|
|
1387
|
+
debug$1(`STSOAuth2Manager:HandleRedirect: HANDLE_REDIRECT response: [${JSON.stringify(response)}]`.magenta);
|
|
1388
|
+
return response.payload;
|
|
1389
|
+
} catch (error) {
|
|
1390
|
+
console.log(`HandleRedirect Error: ${error}`);
|
|
1391
|
+
return false;
|
|
1047
1392
|
}
|
|
1048
1393
|
});
|
|
1049
|
-
|
|
1394
|
+
__publicField(this, "Logout", async () => {
|
|
1050
1395
|
try {
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1396
|
+
const response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.LOGOUT });
|
|
1397
|
+
return response.payload;
|
|
1398
|
+
} catch (error) {
|
|
1399
|
+
console.log(`Logout Error: ${error}`);
|
|
1400
|
+
return false;
|
|
1054
1401
|
}
|
|
1055
1402
|
});
|
|
1056
1403
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1057
|
-
|
|
1404
|
+
__publicField(this, "InvokeExternalAPI", async () => {
|
|
1058
1405
|
try {
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1406
|
+
const response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.LOGOUT });
|
|
1407
|
+
return response.payload;
|
|
1408
|
+
} catch (error) {
|
|
1409
|
+
console.log(`InvokeExternalAPI Error: ${error}`);
|
|
1410
|
+
return null;
|
|
1062
1411
|
}
|
|
1063
1412
|
});
|
|
1064
|
-
|
|
1413
|
+
__publicField(this, "LoggedIn", () => {
|
|
1065
1414
|
try {
|
|
1066
|
-
return
|
|
1067
|
-
} catch {
|
|
1068
|
-
return
|
|
1415
|
+
return __privateGet(this, _GetStore).call(this).LoggedIn;
|
|
1416
|
+
} catch (error) {
|
|
1417
|
+
return false;
|
|
1069
1418
|
}
|
|
1070
1419
|
});
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1420
|
+
__privateSet(this, _options, options);
|
|
1421
|
+
if (!isNode) {
|
|
1422
|
+
if (app.config.globalProperties.$sts[STSInstrumentControllerPluginKey]) {
|
|
1423
|
+
const STSInstrumentController = app.config.globalProperties.$sts[STSInstrumentControllerPluginKey];
|
|
1424
|
+
__privateSet(this, _aic, STSInstrumentController.PrimaryPublishInstrumentController);
|
|
1075
1425
|
}
|
|
1076
|
-
|
|
1426
|
+
__privateSet(this, _router, app.config.globalProperties.$router);
|
|
1077
1427
|
}
|
|
1078
|
-
if (
|
|
1079
|
-
|
|
1080
|
-
else
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
if (
|
|
1428
|
+
if (isNode) {
|
|
1429
|
+
__privateSet(this, _transactionStore, new ClientStorageFactory({ clientStorageType: ClientStorageType.MEMORY_STORAGE, usePrefix: false }).GetStorage());
|
|
1430
|
+
} else {
|
|
1431
|
+
__privateSet(this, _transactionStore, new ClientStorageFactory({ clientStorageType: ClientStorageType.SESSION_STORAGE, usePrefix: false }).GetStorage());
|
|
1432
|
+
}
|
|
1433
|
+
if (__privateGet(this, _options).workerFactory) {
|
|
1434
|
+
__privateSet(this, _worker, __privateGet(this, _options).workerFactory());
|
|
1435
|
+
} else {
|
|
1436
|
+
throw new Error(`STSOAuth2Manager:constructor: Cannot init STSOAuth2Manager - this.#options.workerFactory not specified`);
|
|
1437
|
+
}
|
|
1438
|
+
if (!isNode) {
|
|
1439
|
+
__privateGet(this, _worker).onmessage = (data) => {
|
|
1440
|
+
console.log(`this.#worker.onmessage = [${data}]`);
|
|
1441
|
+
};
|
|
1442
|
+
__privateGet(this, _worker).onerror = function(error) {
|
|
1443
|
+
console.log(`this.#worker.onerror = [${JSON.stringify(error)}]`);
|
|
1444
|
+
};
|
|
1445
|
+
}
|
|
1446
|
+
let workerMessage;
|
|
1447
|
+
if (isNode) {
|
|
1089
1448
|
const {
|
|
1090
|
-
port1:
|
|
1449
|
+
port1: oauth2ManagerPort,
|
|
1091
1450
|
// this process port
|
|
1092
|
-
port2:
|
|
1451
|
+
port2: oauth2WorkerPort
|
|
1093
1452
|
// worker port
|
|
1094
|
-
} = new
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1453
|
+
} = new wt.MessageChannel();
|
|
1454
|
+
__privateSet(this, _oauth2ManagerPort, oauth2ManagerPort);
|
|
1455
|
+
workerMessage = {
|
|
1456
|
+
workerPort: oauth2WorkerPort,
|
|
1457
|
+
options: __privateGet(this, _options).workerOptions
|
|
1458
|
+
};
|
|
1459
|
+
__privateGet(this, _worker).postMessage(workerMessage, [oauth2WorkerPort]);
|
|
1460
|
+
__privateGet(this, _oauth2ManagerPort).on("message", (payload) => {
|
|
1461
|
+
__privateGet(this, _ProcessMessageResponse).call(this, payload);
|
|
1100
1462
|
}).unref();
|
|
1101
1463
|
} else {
|
|
1102
1464
|
const {
|
|
1103
|
-
port1:
|
|
1465
|
+
port1: oauth2ManagerPort,
|
|
1104
1466
|
// this process port
|
|
1105
|
-
port2:
|
|
1467
|
+
port2: oauth2WorkerPort
|
|
1106
1468
|
// worker port
|
|
1107
1469
|
} = new MessageChannel();
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1470
|
+
__privateSet(this, _oauth2ManagerPort, oauth2ManagerPort);
|
|
1471
|
+
workerMessage = {
|
|
1472
|
+
workerPort: oauth2WorkerPort,
|
|
1473
|
+
options: __privateGet(this, _options).workerOptions
|
|
1474
|
+
};
|
|
1475
|
+
__privateGet(this, _worker).postMessage(workerMessage, [oauth2WorkerPort]);
|
|
1476
|
+
__privateGet(this, _oauth2ManagerPort).onmessage = (data) => {
|
|
1477
|
+
__privateGet(this, _ProcessMessageResponse).call(this, data.data);
|
|
1478
|
+
};
|
|
1479
|
+
__privateGet(this, _SetupRoute).call(this, app, __privateGet(this, _router));
|
|
1114
1480
|
}
|
|
1115
1481
|
}
|
|
1116
1482
|
/*
|
|
@@ -1125,25 +1491,107 @@ class Ir {
|
|
|
1125
1491
|
}
|
|
1126
1492
|
*/
|
|
1127
1493
|
}
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
(
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1494
|
+
_router = new WeakMap();
|
|
1495
|
+
_cUtils = new WeakMap();
|
|
1496
|
+
_qParams = new WeakMap();
|
|
1497
|
+
_STORAGE_AUTHORIZE_OPTIONS_KEY = new WeakMap();
|
|
1498
|
+
_STORAGE_SESSION_KEY = new WeakMap();
|
|
1499
|
+
_aic = new WeakMap();
|
|
1500
|
+
_options = new WeakMap();
|
|
1501
|
+
_messages = new WeakMap();
|
|
1502
|
+
_oauth2ManagerPort = new WeakMap();
|
|
1503
|
+
_messageId = new WeakMap();
|
|
1504
|
+
_messageHandlers = new WeakMap();
|
|
1505
|
+
_messageTimeout = new WeakMap();
|
|
1506
|
+
_worker = new WeakMap();
|
|
1507
|
+
_transactionStore = new WeakMap();
|
|
1508
|
+
_operationSemaphore = new WeakMap();
|
|
1509
|
+
_maxSemaphoreRetries = new WeakMap();
|
|
1510
|
+
_semaphoreRetrySleep = new WeakMap();
|
|
1511
|
+
_ProcessMessageResponse = new WeakMap();
|
|
1512
|
+
_PostMessage = new WeakMap();
|
|
1513
|
+
_HandleLogEvent = new WeakMap();
|
|
1514
|
+
_HandleUpdateInstrumentEvent = new WeakMap();
|
|
1515
|
+
_GetStore = new WeakMap();
|
|
1516
|
+
_HandleErrorEvent = new WeakMap();
|
|
1517
|
+
_HandleAuthenticateEvent = new WeakMap();
|
|
1518
|
+
_SetupRoute = new WeakMap();
|
|
1519
|
+
var StatusCodes;
|
|
1520
|
+
(function(StatusCodes2) {
|
|
1521
|
+
StatusCodes2[StatusCodes2["ACCEPTED"] = 202] = "ACCEPTED";
|
|
1522
|
+
StatusCodes2[StatusCodes2["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
|
|
1523
|
+
StatusCodes2[StatusCodes2["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
1524
|
+
StatusCodes2[StatusCodes2["CONFLICT"] = 409] = "CONFLICT";
|
|
1525
|
+
StatusCodes2[StatusCodes2["CONTINUE"] = 100] = "CONTINUE";
|
|
1526
|
+
StatusCodes2[StatusCodes2["CREATED"] = 201] = "CREATED";
|
|
1527
|
+
StatusCodes2[StatusCodes2["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
|
|
1528
|
+
StatusCodes2[StatusCodes2["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
|
|
1529
|
+
StatusCodes2[StatusCodes2["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
1530
|
+
StatusCodes2[StatusCodes2["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
|
|
1531
|
+
StatusCodes2[StatusCodes2["GONE"] = 410] = "GONE";
|
|
1532
|
+
StatusCodes2[StatusCodes2["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
|
|
1533
|
+
StatusCodes2[StatusCodes2["IM_A_TEAPOT"] = 418] = "IM_A_TEAPOT";
|
|
1534
|
+
StatusCodes2[StatusCodes2["INSUFFICIENT_SPACE_ON_RESOURCE"] = 419] = "INSUFFICIENT_SPACE_ON_RESOURCE";
|
|
1535
|
+
StatusCodes2[StatusCodes2["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
|
|
1536
|
+
StatusCodes2[StatusCodes2["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
1537
|
+
StatusCodes2[StatusCodes2["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
|
|
1538
|
+
StatusCodes2[StatusCodes2["LOCKED"] = 423] = "LOCKED";
|
|
1539
|
+
StatusCodes2[StatusCodes2["METHOD_FAILURE"] = 420] = "METHOD_FAILURE";
|
|
1540
|
+
StatusCodes2[StatusCodes2["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
|
|
1541
|
+
StatusCodes2[StatusCodes2["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
|
|
1542
|
+
StatusCodes2[StatusCodes2["MOVED_TEMPORARILY"] = 302] = "MOVED_TEMPORARILY";
|
|
1543
|
+
StatusCodes2[StatusCodes2["MULTI_STATUS"] = 207] = "MULTI_STATUS";
|
|
1544
|
+
StatusCodes2[StatusCodes2["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
|
|
1545
|
+
StatusCodes2[StatusCodes2["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
|
|
1546
|
+
StatusCodes2[StatusCodes2["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
1547
|
+
StatusCodes2[StatusCodes2["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
|
|
1548
|
+
StatusCodes2[StatusCodes2["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
|
|
1549
|
+
StatusCodes2[StatusCodes2["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
1550
|
+
StatusCodes2[StatusCodes2["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
|
|
1551
|
+
StatusCodes2[StatusCodes2["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
|
|
1552
|
+
StatusCodes2[StatusCodes2["OK"] = 200] = "OK";
|
|
1553
|
+
StatusCodes2[StatusCodes2["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
|
|
1554
|
+
StatusCodes2[StatusCodes2["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
|
|
1555
|
+
StatusCodes2[StatusCodes2["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
|
|
1556
|
+
StatusCodes2[StatusCodes2["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
|
|
1557
|
+
StatusCodes2[StatusCodes2["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
|
|
1558
|
+
StatusCodes2[StatusCodes2["PROCESSING"] = 102] = "PROCESSING";
|
|
1559
|
+
StatusCodes2[StatusCodes2["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
|
|
1560
|
+
StatusCodes2[StatusCodes2["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
|
|
1561
|
+
StatusCodes2[StatusCodes2["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
|
|
1562
|
+
StatusCodes2[StatusCodes2["REQUEST_TOO_LONG"] = 413] = "REQUEST_TOO_LONG";
|
|
1563
|
+
StatusCodes2[StatusCodes2["REQUEST_URI_TOO_LONG"] = 414] = "REQUEST_URI_TOO_LONG";
|
|
1564
|
+
StatusCodes2[StatusCodes2["REQUESTED_RANGE_NOT_SATISFIABLE"] = 416] = "REQUESTED_RANGE_NOT_SATISFIABLE";
|
|
1565
|
+
StatusCodes2[StatusCodes2["RESET_CONTENT"] = 205] = "RESET_CONTENT";
|
|
1566
|
+
StatusCodes2[StatusCodes2["SEE_OTHER"] = 303] = "SEE_OTHER";
|
|
1567
|
+
StatusCodes2[StatusCodes2["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
1568
|
+
StatusCodes2[StatusCodes2["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
|
|
1569
|
+
StatusCodes2[StatusCodes2["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
|
|
1570
|
+
StatusCodes2[StatusCodes2["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
|
1571
|
+
StatusCodes2[StatusCodes2["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
1572
|
+
StatusCodes2[StatusCodes2["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
|
|
1573
|
+
StatusCodes2[StatusCodes2["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
|
|
1574
|
+
StatusCodes2[StatusCodes2["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
|
|
1575
|
+
StatusCodes2[StatusCodes2["USE_PROXY"] = 305] = "USE_PROXY";
|
|
1576
|
+
StatusCodes2[StatusCodes2["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
|
|
1577
|
+
})(StatusCodes || (StatusCodes = {}));
|
|
1578
|
+
let debug;
|
|
1579
|
+
if (isNode) {
|
|
1580
|
+
debug = Debug(`proc:${process.pid}:stsoauth2worker.ts`);
|
|
1581
|
+
} else {
|
|
1582
|
+
debug = Debug(`proc:0:stsoauth2worker.ts`);
|
|
1583
|
+
}
|
|
1584
|
+
class STSOAuth2Worker {
|
|
1585
|
+
constructor(workerPort, options) {
|
|
1138
1586
|
//#storageManager = null;
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1587
|
+
__privateAdd(this, _clientSessionStore, void 0);
|
|
1588
|
+
__privateAdd(this, _cUtils2, new CryptoUtils());
|
|
1589
|
+
__privateAdd(this, _qParams2, new QueryParams());
|
|
1590
|
+
__privateAdd(this, _STORAGE_SESSION_KEY2, "session.stsmda.com.au");
|
|
1143
1591
|
//@@#aic = null;
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1592
|
+
__privateAdd(this, _oauthWorkerPort, void 0);
|
|
1593
|
+
__privateAdd(this, _options2, void 0);
|
|
1594
|
+
__privateAdd(this, _httpsAgent, null);
|
|
1147
1595
|
// Attempt to restore a previous session using the STSBroker
|
|
1148
1596
|
/*
|
|
1149
1597
|
{ parameterType: OAuth2ParameterType.CLIENT_ID, errorType: authErrorType.CLIENT_ID_MISMATCH },
|
|
@@ -1172,81 +1620,92 @@ class Br {
|
|
|
1172
1620
|
}
|
|
1173
1621
|
|
|
1174
1622
|
*/
|
|
1175
|
-
|
|
1176
|
-
const
|
|
1623
|
+
__privateAdd(this, _HandleAuthenticateEvent2, (id_token) => {
|
|
1624
|
+
const message = {
|
|
1177
1625
|
messageId: -1,
|
|
1178
1626
|
// un-solicited message
|
|
1179
|
-
command:
|
|
1627
|
+
command: IOauth2ListenerCommand.AUTHENTICATE_EVENT
|
|
1180
1628
|
};
|
|
1181
|
-
|
|
1629
|
+
__privateGet(this, _ProcessCommand).call(this, message, id_token);
|
|
1182
1630
|
});
|
|
1183
1631
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1184
|
-
|
|
1185
|
-
const
|
|
1632
|
+
__privateAdd(this, _HandleErrorEvent2, (error) => {
|
|
1633
|
+
const message = {
|
|
1186
1634
|
messageId: -1,
|
|
1187
1635
|
// un-solicited message
|
|
1188
|
-
command:
|
|
1636
|
+
command: IOauth2ListenerCommand.ERROR
|
|
1189
1637
|
};
|
|
1190
|
-
|
|
1638
|
+
__privateGet(this, _ProcessCommand).call(this, message, error);
|
|
1191
1639
|
});
|
|
1192
|
-
|
|
1193
|
-
const
|
|
1640
|
+
__privateAdd(this, _LogMessage, (messageToSend) => {
|
|
1641
|
+
const message = {
|
|
1194
1642
|
messageId: -1,
|
|
1195
1643
|
// un-solicited message
|
|
1196
|
-
command:
|
|
1644
|
+
command: IOauth2ListenerCommand.LOG
|
|
1197
1645
|
};
|
|
1198
|
-
|
|
1646
|
+
__privateGet(this, _ProcessCommand).call(this, message, messageToSend);
|
|
1199
1647
|
});
|
|
1200
|
-
|
|
1201
|
-
const
|
|
1202
|
-
|
|
1648
|
+
__privateAdd(this, _GetAccessToken, () => {
|
|
1649
|
+
const sessionData = __privateGet(this, _clientSessionStore).get(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
1650
|
+
if (sessionData) {
|
|
1651
|
+
const tokens = sessionData.tokenResponse;
|
|
1652
|
+
return tokens.access_token;
|
|
1653
|
+
} else {
|
|
1654
|
+
return null;
|
|
1655
|
+
}
|
|
1203
1656
|
});
|
|
1204
1657
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1205
|
-
|
|
1206
|
-
if (
|
|
1207
|
-
const
|
|
1208
|
-
|
|
1209
|
-
|
|
1658
|
+
__privateAdd(this, _GetCookies, () => {
|
|
1659
|
+
if (isNode) {
|
|
1660
|
+
const sessionData = __privateGet(this, _clientSessionStore).get(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
1661
|
+
if (sessionData) {
|
|
1662
|
+
return sessionData.brokerCookie;
|
|
1663
|
+
} else {
|
|
1664
|
+
return null;
|
|
1665
|
+
}
|
|
1666
|
+
} else {
|
|
1210
1667
|
return null;
|
|
1668
|
+
}
|
|
1211
1669
|
});
|
|
1212
|
-
|
|
1213
|
-
const
|
|
1670
|
+
__privateAdd(this, _UpdateInstrument, (instrumentName, telemetry) => {
|
|
1671
|
+
const message = {
|
|
1214
1672
|
messageId: -1,
|
|
1215
1673
|
// un-solicited message
|
|
1216
|
-
command:
|
|
1674
|
+
command: IOauth2ListenerCommand.UPDATE_INSTRUMENT
|
|
1217
1675
|
};
|
|
1218
|
-
|
|
1219
|
-
instrumentName
|
|
1220
|
-
telemetry
|
|
1676
|
+
__privateGet(this, _ProcessCommand).call(this, message, {
|
|
1677
|
+
instrumentName,
|
|
1678
|
+
telemetry
|
|
1221
1679
|
});
|
|
1222
1680
|
});
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
const
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1681
|
+
__publicField(this, "SetupListener", () => {
|
|
1682
|
+
__privateGet(this, _oauthWorkerPort).onmessage = async (data) => {
|
|
1683
|
+
const auth2ListenerMessage = data.data;
|
|
1684
|
+
debug(`STSOAuth2Worker:SetupListener:onmessage: [${auth2ListenerMessage.command}]`);
|
|
1685
|
+
switch (auth2ListenerMessage.command) {
|
|
1686
|
+
case IOauth2ListenerCommand.RESTORE_SESSION:
|
|
1687
|
+
__privateGet(this, _ProcessCommand).call(this, auth2ListenerMessage, await __privateGet(this, _RestoreSession).call(this));
|
|
1229
1688
|
break;
|
|
1230
|
-
case
|
|
1231
|
-
|
|
1689
|
+
case IOauth2ListenerCommand.AUTHORIZE:
|
|
1690
|
+
__privateGet(this, _ProcessCommand).call(this, auth2ListenerMessage, await __privateGet(this, _Authorize).call(this));
|
|
1232
1691
|
break;
|
|
1233
|
-
case
|
|
1234
|
-
|
|
1692
|
+
case IOauth2ListenerCommand.HANDLE_REDIRECT:
|
|
1693
|
+
__privateGet(this, _ProcessCommand).call(this, auth2ListenerMessage, await __privateGet(this, _HandleRedirect).call(this, auth2ListenerMessage.payload));
|
|
1235
1694
|
break;
|
|
1236
|
-
case
|
|
1237
|
-
|
|
1695
|
+
case IOauth2ListenerCommand.LOGOUT:
|
|
1696
|
+
__privateGet(this, _ProcessCommand).call(this, auth2ListenerMessage, await __privateGet(this, _Logout).call(this));
|
|
1238
1697
|
break;
|
|
1239
|
-
case
|
|
1240
|
-
|
|
1698
|
+
case IOauth2ListenerCommand.ACCESS_TOKEN:
|
|
1699
|
+
__privateGet(this, _ProcessCommand).call(this, auth2ListenerMessage, await __privateGet(this, _GetAccessToken).call(this));
|
|
1241
1700
|
break;
|
|
1242
|
-
case
|
|
1243
|
-
|
|
1701
|
+
case IOauth2ListenerCommand.EXECUTE_REFRESH_TOKEN:
|
|
1702
|
+
__privateGet(this, _ProcessCommand).call(this, auth2ListenerMessage, await __privateGet(this, _RefreshToken).call(this));
|
|
1244
1703
|
break;
|
|
1245
|
-
case
|
|
1246
|
-
|
|
1704
|
+
case IOauth2ListenerCommand.COOKIES:
|
|
1705
|
+
__privateGet(this, _ProcessCommand).call(this, auth2ListenerMessage, await __privateGet(this, _GetCookies).call(this));
|
|
1247
1706
|
break;
|
|
1248
1707
|
default:
|
|
1249
|
-
throw new Error(`Command: [${
|
|
1708
|
+
throw new Error(`Command: [${auth2ListenerMessage.command}'] not found.`);
|
|
1250
1709
|
}
|
|
1251
1710
|
};
|
|
1252
1711
|
});
|
|
@@ -1256,83 +1715,142 @@ class Br {
|
|
|
1256
1715
|
}
|
|
1257
1716
|
*/
|
|
1258
1717
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1259
|
-
|
|
1260
|
-
const
|
|
1261
|
-
messageId:
|
|
1262
|
-
command:
|
|
1263
|
-
payload:
|
|
1718
|
+
__privateAdd(this, _ProcessCommand, async (auth2ListenerMessage, response) => {
|
|
1719
|
+
const messageResponse = {
|
|
1720
|
+
messageId: auth2ListenerMessage.messageId,
|
|
1721
|
+
command: auth2ListenerMessage.command,
|
|
1722
|
+
payload: response
|
|
1264
1723
|
};
|
|
1265
|
-
|
|
1724
|
+
__privateGet(this, _oauthWorkerPort).postMessage(messageResponse);
|
|
1266
1725
|
});
|
|
1267
|
-
|
|
1268
|
-
let
|
|
1269
|
-
const
|
|
1270
|
-
if (
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1726
|
+
__privateAdd(this, _RestoreSession, async () => {
|
|
1727
|
+
let restoredSessionData = null;
|
|
1728
|
+
const sessionData = __privateGet(this, _clientSessionStore).get(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
1729
|
+
if (sessionData) {
|
|
1730
|
+
restoredSessionData = sessionData.tokenResponse;
|
|
1731
|
+
console.log("Session restored from client storage.");
|
|
1732
|
+
__privateGet(this, _LogMessage).call(this, "Session restored from client storage.");
|
|
1733
|
+
} else {
|
|
1734
|
+
const url = `${__privateGet(this, _options2).brokerendpoint}:${__privateGet(this, _options2).brokerport}${__privateGet(this, _options2).brokerapiroot}/session`;
|
|
1735
|
+
console.log("RestoreSession");
|
|
1736
|
+
console.log(url);
|
|
1737
|
+
__privateGet(this, _LogMessage).call(this, "RestoreSession.");
|
|
1738
|
+
__privateGet(this, _LogMessage).call(this, url);
|
|
1275
1739
|
try {
|
|
1276
|
-
const
|
|
1740
|
+
const rConfig = {
|
|
1277
1741
|
method: "post",
|
|
1278
|
-
url
|
|
1742
|
+
url,
|
|
1279
1743
|
data: {
|
|
1280
|
-
[
|
|
1281
|
-
[
|
|
1282
|
-
[
|
|
1283
|
-
[
|
|
1744
|
+
[OAuth2ParameterType.CLIENT_ID]: __privateGet(this, _options2).client_id,
|
|
1745
|
+
[OAuth2ParameterType.SCOPE]: __privateGet(this, _options2).scope,
|
|
1746
|
+
[OAuth2ParameterType.REDIRECT_URI]: __privateGet(this, _options2).redirect_uri,
|
|
1747
|
+
[OAuth2ParameterType.AUDIENCE]: __privateGet(this, _options2).audience
|
|
1284
1748
|
},
|
|
1285
|
-
withCredentials:
|
|
1749
|
+
withCredentials: true,
|
|
1286
1750
|
// Ensure cookies are passed to the service
|
|
1287
|
-
timeout:
|
|
1751
|
+
timeout: __privateGet(this, _options2).timeout
|
|
1288
1752
|
};
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1753
|
+
debug(`#RestoreSession:session request detail: [${JSON.stringify(rConfig)}]`.magenta);
|
|
1754
|
+
if (isNode) {
|
|
1755
|
+
rConfig.httpsAgent = __privateGet(this, _httpsAgent);
|
|
1756
|
+
}
|
|
1757
|
+
const retVal = await axios(rConfig);
|
|
1758
|
+
if (retVal.data.status === StatusCodes.OK) {
|
|
1759
|
+
restoredSessionData = retVal.data.detail;
|
|
1760
|
+
if (restoredSessionData) {
|
|
1761
|
+
const newSessionData = {
|
|
1762
|
+
tokenResponse: restoredSessionData
|
|
1295
1763
|
};
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1764
|
+
if (isNode) {
|
|
1765
|
+
newSessionData.brokerCookie = retVal.headers["set-cookie"];
|
|
1766
|
+
}
|
|
1767
|
+
__privateGet(this, _clientSessionStore).set(__privateGet(this, _STORAGE_SESSION_KEY2), newSessionData);
|
|
1768
|
+
console.log("Session restored from server side cookie.");
|
|
1769
|
+
} else {
|
|
1770
|
+
console.log(`Could not restore previous session. No restoredSessionData available.`);
|
|
1771
|
+
console.log(JSON.stringify(retVal.data));
|
|
1772
|
+
}
|
|
1773
|
+
} else {
|
|
1774
|
+
console.log("Could not restore previous session:-");
|
|
1775
|
+
console.log(JSON.stringify(retVal.data));
|
|
1776
|
+
}
|
|
1777
|
+
} catch (error) {
|
|
1778
|
+
console.log("Could not restore previous session (error state):-");
|
|
1779
|
+
console.log(error);
|
|
1780
|
+
console.log(JSON.stringify(error));
|
|
1303
1781
|
}
|
|
1304
1782
|
}
|
|
1305
|
-
|
|
1783
|
+
if (restoredSessionData !== null) {
|
|
1784
|
+
__privateGet(this, _HandleAuthenticateEvent2).call(this, restoredSessionData.id_token);
|
|
1785
|
+
console.log("Refreshing tokens ...");
|
|
1786
|
+
return await __privateGet(this, _RefreshToken).call(this);
|
|
1787
|
+
} else {
|
|
1788
|
+
__privateGet(this, _HandleAuthenticateEvent2).call(this, null);
|
|
1789
|
+
return false;
|
|
1790
|
+
}
|
|
1306
1791
|
});
|
|
1307
|
-
|
|
1792
|
+
__privateAdd(this, _Authorize, async () => {
|
|
1308
1793
|
console.log("Authorize ...");
|
|
1309
|
-
const
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1794
|
+
const client_id = __privateGet(this, _options2).client_id;
|
|
1795
|
+
const nonce = __privateGet(this, _cUtils2).CreateRandomString();
|
|
1796
|
+
const response_type = [AuthorizeOptionsResponseType.CODE];
|
|
1797
|
+
const redirect_uri = __privateGet(this, _options2).redirect_uri;
|
|
1798
|
+
const response_mode = AuthorizeOptionsResponseMode.QUERY;
|
|
1799
|
+
const scope = __privateGet(this, _options2).scope;
|
|
1800
|
+
const state = __privateGet(this, _cUtils2).CreateRandomString();
|
|
1801
|
+
const code_verifier = __privateGet(this, _cUtils2).CreateRandomString();
|
|
1802
|
+
const code_challenge = await __privateGet(this, _cUtils2).DigestMessage(code_verifier);
|
|
1803
|
+
const code_challenge_method = "S256";
|
|
1804
|
+
const authorizeOptions = {
|
|
1805
|
+
client_id,
|
|
1806
|
+
nonce,
|
|
1807
|
+
response_type,
|
|
1808
|
+
redirect_uri,
|
|
1809
|
+
response_mode,
|
|
1810
|
+
scope,
|
|
1811
|
+
state,
|
|
1812
|
+
code_challenge,
|
|
1813
|
+
code_challenge_method
|
|
1814
|
+
};
|
|
1815
|
+
const authorizeOptionsClientCopy = { ...authorizeOptions };
|
|
1816
|
+
const url = `${__privateGet(this, _options2).authorizeendpoint}:${__privateGet(this, _options2).authorizeport}${__privateGet(this, _options2).authorizeapiroot}${__privateGet(this, _options2).authorizeapi}?${__privateGet(this, _qParams2).CreateQueryParams(authorizeOptions)}`;
|
|
1817
|
+
console.log(url);
|
|
1818
|
+
authorizeOptions.code_verifier = code_verifier;
|
|
1819
|
+
console.log(`Authorize:authorizeOptions: [${JSON.stringify(authorizeOptions)}]`);
|
|
1820
|
+
return {
|
|
1821
|
+
url,
|
|
1822
|
+
authorizeOptions,
|
|
1823
|
+
authorizeOptionsClientCopy
|
|
1324
1824
|
};
|
|
1325
1825
|
});
|
|
1326
1826
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1327
|
-
|
|
1328
|
-
const
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1827
|
+
__privateAdd(this, _HandleRedirect, async (payload) => {
|
|
1828
|
+
const queryVars = payload.queryVars;
|
|
1829
|
+
const authorizeOptions = payload.authorizeOptions;
|
|
1830
|
+
debug(`#HandleRedirect: HandleRedirect`.magenta);
|
|
1831
|
+
debug(`#HandleRedirect: HandleRedirect:Query Vars: [${JSON.stringify(queryVars)}]`.magenta);
|
|
1832
|
+
if (queryVars[OAuth2ParameterType.CODE]) {
|
|
1833
|
+
const response = queryVars;
|
|
1834
|
+
console.log(`authorizeOptions from transaction state: [${JSON.stringify(authorizeOptions)}]`);
|
|
1835
|
+
const redirectState = response.state;
|
|
1836
|
+
const authorizeOptionsState = authorizeOptions.state;
|
|
1837
|
+
if (authorizeOptionsState.localeCompare(redirectState) === 0) {
|
|
1838
|
+
console.log("redirected state (from queryVars) matched previously saved transaction authorizeOptions state");
|
|
1839
|
+
return await __privateGet(this, _GetToken).call(this, authorizeOptions, response);
|
|
1840
|
+
} else {
|
|
1841
|
+
console.log("redirected state (from queryVars) did NOT match previously saved transaction authorizeOptions state");
|
|
1842
|
+
console.log(`authorizeOptionsState: [${authorizeOptionsState}]`);
|
|
1843
|
+
console.log(`redirectState: [${redirectState}]`);
|
|
1844
|
+
__privateGet(this, _HandleErrorEvent2).call(this, { message: "State un-matched" });
|
|
1845
|
+
return false;
|
|
1846
|
+
}
|
|
1847
|
+
} else if (queryVars[OAuth2ParameterType.ERROR]) {
|
|
1848
|
+
__privateGet(this, _HandleErrorEvent2).call(this, { message: "State un-matched" });
|
|
1849
|
+
return false;
|
|
1850
|
+
} else {
|
|
1851
|
+
__privateGet(this, _HandleErrorEvent2).call(this, { message: "State un-matched" });
|
|
1852
|
+
return false;
|
|
1853
|
+
}
|
|
1336
1854
|
});
|
|
1337
1855
|
/*
|
|
1338
1856
|
client_id=6731de76-14a6-49ae-97bc-6eba6914391e
|
|
@@ -1354,46 +1872,69 @@ class Br {
|
|
|
1354
1872
|
}
|
|
1355
1873
|
*/
|
|
1356
1874
|
// Get access_token, refresh_token and id_token using OAuth2 Authorization Code Flow
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1875
|
+
__privateAdd(this, _GetTokenFromBroker, async (authorizationCodeFlowParameters) => {
|
|
1876
|
+
debug(`#GetTokenFromBroker`.magenta);
|
|
1877
|
+
__privateGet(this, _clientSessionStore).remove(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
1878
|
+
const url = `${__privateGet(this, _options2).brokerendpoint}:${__privateGet(this, _options2).brokerport}${__privateGet(this, _options2).brokerapiroot}/token`;
|
|
1360
1879
|
try {
|
|
1361
|
-
const
|
|
1880
|
+
const rConfig = {
|
|
1362
1881
|
method: "post",
|
|
1363
|
-
url
|
|
1364
|
-
data:
|
|
1365
|
-
withCredentials:
|
|
1882
|
+
url,
|
|
1883
|
+
data: authorizationCodeFlowParameters,
|
|
1884
|
+
withCredentials: true,
|
|
1366
1885
|
// Ensure cookies are passed to the service
|
|
1367
|
-
timeout:
|
|
1886
|
+
timeout: __privateGet(this, _options2).timeout
|
|
1368
1887
|
};
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1888
|
+
debug(`#GetTokenFromBroker: request config: [${JSON.stringify(rConfig)}]`.magenta);
|
|
1889
|
+
if (isNode) {
|
|
1890
|
+
rConfig.httpsAgent = __privateGet(this, _httpsAgent);
|
|
1891
|
+
}
|
|
1892
|
+
debug(`#GetTokenFromBroker: axios API call`.magenta);
|
|
1893
|
+
const retVal = await axios(rConfig);
|
|
1894
|
+
debug(`#GetTokenFromBroker: axios API call result: [${retVal.status}]`.magenta);
|
|
1895
|
+
if (retVal.status === StatusCodes.OK) {
|
|
1896
|
+
debug(`#GetTokenFromBroker: storing tokens`.magenta);
|
|
1897
|
+
const tokenResponse = retVal.data;
|
|
1898
|
+
__privateGet(this, _HandleAuthenticateEvent2).call(this, tokenResponse.id_token);
|
|
1899
|
+
const newSessionData = {
|
|
1900
|
+
tokenResponse
|
|
1377
1901
|
};
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1902
|
+
if (isNode) {
|
|
1903
|
+
newSessionData.brokerCookie = retVal.headers["set-cookie"];
|
|
1904
|
+
}
|
|
1905
|
+
__privateGet(this, _clientSessionStore).set(__privateGet(this, _STORAGE_SESSION_KEY2), newSessionData);
|
|
1906
|
+
return true;
|
|
1907
|
+
} else if (retVal.status === StatusCodes.UNAUTHORIZED) {
|
|
1908
|
+
debug(`#GetTokenFromBroker: NOT storing tokens, status: [${retVal.status}]`.magenta);
|
|
1909
|
+
__privateGet(this, _HandleAuthenticateEvent2).call(this, null);
|
|
1910
|
+
return false;
|
|
1911
|
+
} else {
|
|
1912
|
+
debug(`#GetTokenFromBroker: NOT storing tokens (general error 1), status: [${retVal.status}]`.magenta);
|
|
1913
|
+
__privateGet(this, _HandleAuthenticateEvent2).call(this, null);
|
|
1914
|
+
console.log("Could not obtain access_token from token end-point:-");
|
|
1915
|
+
console.log(JSON.stringify(retVal.data));
|
|
1916
|
+
return false;
|
|
1917
|
+
}
|
|
1918
|
+
} catch (error) {
|
|
1919
|
+
debug(`#GetTokenFromBroker: NOT storing tokens (general error 2), status: [${error}]`.red);
|
|
1920
|
+
__privateGet(this, _HandleAuthenticateEvent2).call(this, null);
|
|
1921
|
+
return false;
|
|
1383
1922
|
}
|
|
1384
1923
|
});
|
|
1385
1924
|
// Get access_token, refresh_token and id_token using OAuth2 Authorization Code Flow
|
|
1386
|
-
|
|
1387
|
-
console.log("#GetToken")
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1925
|
+
__privateAdd(this, _GetToken, async (authorizeOptions, authorizeResponse) => {
|
|
1926
|
+
console.log("#GetToken");
|
|
1927
|
+
console.log(authorizeResponse);
|
|
1928
|
+
__privateGet(this, _clientSessionStore).remove(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
1929
|
+
const authorizationCodeFlowParameters = {
|
|
1930
|
+
client_id: __privateGet(this, _options2).client_id,
|
|
1931
|
+
scope: __privateGet(this, _options2).scope,
|
|
1932
|
+
code: authorizeResponse.code,
|
|
1933
|
+
redirect_uri: __privateGet(this, _options2).redirect_uri,
|
|
1934
|
+
grant_type: OAuthGrantTypes.AUTHORIZATION_CODE,
|
|
1935
|
+
code_verifier: authorizeOptions.code_verifier
|
|
1395
1936
|
};
|
|
1396
|
-
return await
|
|
1937
|
+
return await __privateGet(this, _GetTokenFromBroker).call(this, authorizationCodeFlowParameters);
|
|
1397
1938
|
});
|
|
1398
1939
|
/*
|
|
1399
1940
|
// Line breaks for legibility only
|
|
@@ -1420,106 +1961,166 @@ class Br {
|
|
|
1420
1961
|
"correlation_id": "fb3d2015-bc17-4bb9-bb85-30c5cf1aaaa7"
|
|
1421
1962
|
}
|
|
1422
1963
|
*/
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
const
|
|
1426
|
-
if (
|
|
1427
|
-
|
|
1428
|
-
const
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1964
|
+
__privateAdd(this, _RefreshToken, async () => {
|
|
1965
|
+
debug(`STSOAuth2Worker:#RefreshToken:start`.cyan);
|
|
1966
|
+
const sessionData = __privateGet(this, _clientSessionStore).get(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
1967
|
+
if (sessionData) {
|
|
1968
|
+
debug(`STSOAuth2Worker:#RefreshToken:sessionData: [${JSON.stringify(sessionData)}]`.cyan);
|
|
1969
|
+
const currentSessionData = sessionData.tokenResponse;
|
|
1970
|
+
const refreshFlowParameters = {
|
|
1971
|
+
client_id: __privateGet(this, _options2).client_id,
|
|
1972
|
+
scope: __privateGet(this, _options2).scope,
|
|
1973
|
+
refresh_token: currentSessionData.refresh_token,
|
|
1974
|
+
grant_type: OAuthGrantTypes.REFRESH_TOKEN
|
|
1433
1975
|
};
|
|
1434
|
-
return await
|
|
1435
|
-
} else
|
|
1436
|
-
|
|
1976
|
+
return await __privateGet(this, _GetTokenFromBroker).call(this, refreshFlowParameters);
|
|
1977
|
+
} else {
|
|
1978
|
+
debug(`STSOAuth2Worker:#RefreshToken:sessionData not found within clientSessionStore`.red);
|
|
1979
|
+
return false;
|
|
1980
|
+
}
|
|
1437
1981
|
});
|
|
1438
1982
|
// call broker to logout
|
|
1439
1983
|
// broker to logout of server
|
|
1440
1984
|
// delete cookie
|
|
1441
1985
|
// clear session storage
|
|
1442
1986
|
// clear all state from $store
|
|
1443
|
-
|
|
1987
|
+
__privateAdd(this, _Logout, async () => {
|
|
1444
1988
|
console.log("Logout");
|
|
1445
|
-
const
|
|
1446
|
-
console.log(
|
|
1447
|
-
const
|
|
1448
|
-
if (
|
|
1449
|
-
const
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1989
|
+
const url = `${__privateGet(this, _options2).brokerendpoint}:${__privateGet(this, _options2).brokerport}${__privateGet(this, _options2).brokerapiroot}/logout`;
|
|
1990
|
+
console.log(url);
|
|
1991
|
+
const sessionData = __privateGet(this, _clientSessionStore).get(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
1992
|
+
if (sessionData) {
|
|
1993
|
+
const currentSessionData = sessionData.tokenResponse;
|
|
1994
|
+
const refresh_token = currentSessionData.refresh_token;
|
|
1995
|
+
console.log(refresh_token);
|
|
1996
|
+
const decodedRefreshToken = o(refresh_token);
|
|
1997
|
+
console.log(decodedRefreshToken);
|
|
1998
|
+
const sessionId = decodedRefreshToken.sts_session;
|
|
1999
|
+
console.log(sessionId);
|
|
2000
|
+
__privateGet(this, _clientSessionStore).remove(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
2001
|
+
__privateGet(this, _HandleAuthenticateEvent2).call(this, null);
|
|
1455
2002
|
try {
|
|
1456
|
-
const
|
|
2003
|
+
const rConfig = {
|
|
1457
2004
|
method: "post",
|
|
1458
|
-
url
|
|
2005
|
+
url,
|
|
1459
2006
|
data: {
|
|
1460
|
-
sessionId
|
|
2007
|
+
sessionId
|
|
1461
2008
|
},
|
|
1462
|
-
withCredentials:
|
|
2009
|
+
withCredentials: true,
|
|
1463
2010
|
// Ensure cookies are passed to the service
|
|
1464
|
-
timeout:
|
|
2011
|
+
timeout: __privateGet(this, _options2).timeout
|
|
1465
2012
|
};
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
2013
|
+
debug(`#Logout: request config: [${rConfig}]`.magenta);
|
|
2014
|
+
if (isNode) {
|
|
2015
|
+
rConfig.httpsAgent = __privateGet(this, _httpsAgent);
|
|
2016
|
+
}
|
|
2017
|
+
const retVal = await axios(rConfig);
|
|
2018
|
+
if (retVal.data.status === StatusCodes.OK) {
|
|
2019
|
+
return true;
|
|
2020
|
+
} else {
|
|
2021
|
+
console.log("Error during logout (1: server side)");
|
|
2022
|
+
console.log(JSON.stringify(retVal.data));
|
|
2023
|
+
return false;
|
|
2024
|
+
}
|
|
2025
|
+
} catch (error) {
|
|
2026
|
+
console.log("Error during logout (2: server side)");
|
|
2027
|
+
console.log(error);
|
|
2028
|
+
console.log(JSON.stringify(error));
|
|
2029
|
+
return false;
|
|
1471
2030
|
}
|
|
1472
|
-
} else
|
|
1473
|
-
|
|
2031
|
+
} else {
|
|
2032
|
+
console.log("Error during logout. Could not restore session from session storage.");
|
|
2033
|
+
return false;
|
|
2034
|
+
}
|
|
1474
2035
|
});
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
2036
|
+
Debug.enable("proc:*");
|
|
2037
|
+
__privateSet(this, _options2, options);
|
|
2038
|
+
debug(`STSOAuth2Worker:constructor:#options: [${JSON.stringify(__privateGet(this, _options2))}]`);
|
|
2039
|
+
__privateSet(this, _clientSessionStore, new ClientStorageFactory({ clientStorageType: ClientStorageType.MEMORY_STORAGE, usePrefix: false }).GetStorage());
|
|
2040
|
+
__privateSet(this, _oauthWorkerPort, workerPort);
|
|
2041
|
+
debug(`STSOAuth2Worker:constructor:#oauthWorkerPort: [${JSON.stringify(__privateGet(this, _oauthWorkerPort))}]`);
|
|
2042
|
+
if (isNode && __privateGet(this, _options2).agentOptions) {
|
|
2043
|
+
__privateSet(this, _httpsAgent, new https.Agent({
|
|
2044
|
+
keepAlive: __privateGet(this, _options2).agentOptions.keepAlive,
|
|
2045
|
+
maxSockets: __privateGet(this, _options2).agentOptions.maxSockets,
|
|
2046
|
+
maxTotalSockets: __privateGet(this, _options2).agentOptions.maxTotalSockets,
|
|
2047
|
+
maxFreeSockets: __privateGet(this, _options2).agentOptions.maxFreeSockets,
|
|
2048
|
+
timeout: __privateGet(this, _options2).timeout,
|
|
2049
|
+
rejectUnauthorized: __privateGet(this, _options2).agentOptions.rejectUnauthorized
|
|
2050
|
+
// Allows self-signed certificates if non-production
|
|
2051
|
+
}));
|
|
2052
|
+
}
|
|
2053
|
+
this.SetupListener();
|
|
2054
|
+
__privateGet(this, _UpdateInstrument).call(this, Gauge.LOGGER, {
|
|
2055
|
+
LogMessage: `STSOauth2 Plugin - Successfully Loaded`
|
|
1485
2056
|
});
|
|
1486
2057
|
}
|
|
1487
2058
|
}
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
2059
|
+
_clientSessionStore = new WeakMap();
|
|
2060
|
+
_cUtils2 = new WeakMap();
|
|
2061
|
+
_qParams2 = new WeakMap();
|
|
2062
|
+
_STORAGE_SESSION_KEY2 = new WeakMap();
|
|
2063
|
+
_oauthWorkerPort = new WeakMap();
|
|
2064
|
+
_options2 = new WeakMap();
|
|
2065
|
+
_httpsAgent = new WeakMap();
|
|
2066
|
+
_HandleAuthenticateEvent2 = new WeakMap();
|
|
2067
|
+
_HandleErrorEvent2 = new WeakMap();
|
|
2068
|
+
_LogMessage = new WeakMap();
|
|
2069
|
+
_GetAccessToken = new WeakMap();
|
|
2070
|
+
_GetCookies = new WeakMap();
|
|
2071
|
+
_UpdateInstrument = new WeakMap();
|
|
2072
|
+
_ProcessCommand = new WeakMap();
|
|
2073
|
+
_RestoreSession = new WeakMap();
|
|
2074
|
+
_Authorize = new WeakMap();
|
|
2075
|
+
_HandleRedirect = new WeakMap();
|
|
2076
|
+
_GetTokenFromBroker = new WeakMap();
|
|
2077
|
+
_GetToken = new WeakMap();
|
|
2078
|
+
_RefreshToken = new WeakMap();
|
|
2079
|
+
_Logout = new WeakMap();
|
|
2080
|
+
const TestStore = defineStore("__sts__TestStore", {
|
|
2081
|
+
state: () => {
|
|
2082
|
+
return {
|
|
2083
|
+
count: 0
|
|
2084
|
+
};
|
|
2085
|
+
},
|
|
1493
2086
|
actions: {
|
|
1494
2087
|
UpdateCount() {
|
|
1495
2088
|
this.count++;
|
|
1496
2089
|
}
|
|
1497
2090
|
},
|
|
1498
2091
|
getters: {
|
|
1499
|
-
CountXX: (
|
|
2092
|
+
CountXX: (state) => {
|
|
2093
|
+
return state.count * 2;
|
|
2094
|
+
}
|
|
1500
2095
|
}
|
|
1501
2096
|
/*
|
|
1502
2097
|
persist: {
|
|
1503
2098
|
storage: globalThis.sessionStorage
|
|
1504
2099
|
}
|
|
1505
2100
|
*/
|
|
1506
|
-
})
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
2101
|
+
});
|
|
2102
|
+
const useSTSOAuth2ManagerPlugin = () => inject(STSOAuth2ManagerPluginKey);
|
|
2103
|
+
const STSOAuth2ManagerPlugin = {
|
|
2104
|
+
install: (app, options) => {
|
|
2105
|
+
const om = new STSOAuth2Manager(app, options);
|
|
2106
|
+
if (!app.config.globalProperties.$sts) {
|
|
2107
|
+
app.config.globalProperties.$sts = {};
|
|
2108
|
+
}
|
|
2109
|
+
app.config.globalProperties.$sts[STSOAuth2ManagerPluginKey] = om;
|
|
2110
|
+
app.provide(STSOAuth2ManagerPluginKey, om);
|
|
1510
2111
|
}
|
|
1511
2112
|
};
|
|
1512
2113
|
export {
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
2114
|
+
AuthorizeOptionsResponseMode,
|
|
2115
|
+
AuthorizeOptionsResponseType,
|
|
2116
|
+
IOauth2ListenerCommand,
|
|
2117
|
+
OAuthGrantTypes,
|
|
2118
|
+
STSOAuth2Manager,
|
|
2119
|
+
STSOAuth2ManagerPlugin,
|
|
2120
|
+
STSOAuth2ManagerPluginKey,
|
|
2121
|
+
STSOAuth2Worker,
|
|
2122
|
+
STSOauth2Store,
|
|
2123
|
+
TestStore,
|
|
2124
|
+
useSTSOAuth2ManagerPlugin
|
|
1524
2125
|
};
|
|
1525
2126
|
//# sourceMappingURL=stsoauth2plugin.mjs.map
|