@nsshunt/stsoauth2plugin 1.0.65 → 1.0.67
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 +108 -100
- package/dist/stsoauth2plugin.mjs.map +1 -1
- package/dist/stsoauth2plugin.umd.js +110 -101
- package/dist/stsoauth2plugin.umd.js.map +1 -1
- package/package.json +9 -9
- package/types/stsoauth2manager.d.ts +1 -0
- package/types/stsoauth2manager.d.ts.map +1 -1
- package/types/stsoauth2types.d.ts +2 -0
- package/types/stsoauth2types.d.ts.map +1 -1
package/dist/stsoauth2plugin.mjs
CHANGED
|
@@ -34,9 +34,8 @@ var __privateMethod = (obj, member, method) => {
|
|
|
34
34
|
__accessCheck(obj, member, "access private method");
|
|
35
35
|
return method;
|
|
36
36
|
};
|
|
37
|
-
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, _logger,
|
|
37
|
+
var _crypto, _router, _cUtils, _qParams, _STORAGE_AUTHORIZE_OPTIONS_KEY, _STORAGE_SESSION_KEY, _aic, _options, _messages, _oauth2ManagerPort, _messageId, _messageHandlers, _messageTimeout, _worker, _transactionStore, _operationSemaphore, _maxSemaphoreRetries, _semaphoreRetrySleep, _LogDebugMessage, LogDebugMessage_fn, _LogInfoMessage, LogInfoMessage_fn, _LogErrorMessage, LogErrorMessage_fn, _ProcessMessageResponse, _PostMessage, _HandleLogEvent, _HandleUpdateInstrumentEvent, _GetStore, _HandleErrorEvent, _HandleAuthenticateEvent, _SetupRoute, _clientSessionStore, _cUtils2, _qParams2, _STORAGE_SESSION_KEY2, _oauthWorkerPort, _options2, _httpsAgent, _logger, _LogDebugMessage2, LogDebugMessage_fn2, _LogInfoMessage2, LogInfoMessage_fn2, _LogErrorMessage2, LogErrorMessage_fn2, _HandleAuthenticateEvent2, _HandleErrorEvent2, _LogMessage, _GetAccessToken, _GetCookies, _UpdateInstrument, _ProcessCommand, _RestoreSession, _Authorize, _HandleRedirect, _GetTokenFromBroker, _GetToken, _RefreshToken, _Logout;
|
|
38
38
|
import { inject } from "vue";
|
|
39
|
-
import Debug from "debug";
|
|
40
39
|
import * as wt from "node:worker_threads";
|
|
41
40
|
import { OAuth2ParameterType, Sleep } from "@nsshunt/stsutils";
|
|
42
41
|
import { ClientStorageFactory, ClientStorageType } from "@nsshunt/stsvueutils";
|
|
@@ -2536,15 +2535,12 @@ const STSOauth2Store = defineStore("__sts__STSOauth2Store", {
|
|
|
2536
2535
|
}
|
|
2537
2536
|
*/
|
|
2538
2537
|
});
|
|
2539
|
-
let debug;
|
|
2540
|
-
if (isNode) {
|
|
2541
|
-
debug = Debug(`proc:${process.pid}:stsoauth2manager.ts`);
|
|
2542
|
-
} else {
|
|
2543
|
-
debug = Debug(`proc:0:stsoauth2manager.ts`);
|
|
2544
|
-
}
|
|
2545
2538
|
class STSOAuth2Manager {
|
|
2546
2539
|
// ms
|
|
2547
2540
|
constructor(app, options) {
|
|
2541
|
+
__privateAdd(this, _LogDebugMessage);
|
|
2542
|
+
__privateAdd(this, _LogInfoMessage);
|
|
2543
|
+
__privateAdd(this, _LogErrorMessage);
|
|
2548
2544
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2549
2545
|
__privateAdd(this, _router, null);
|
|
2550
2546
|
__privateAdd(this, _cUtils, new CryptoUtils());
|
|
@@ -2569,7 +2565,7 @@ class STSOAuth2Manager {
|
|
|
2569
2565
|
__privateAdd(this, _semaphoreRetrySleep, 50);
|
|
2570
2566
|
__privateAdd(this, _ProcessMessageResponse, (data) => {
|
|
2571
2567
|
const messageResponse = data;
|
|
2572
|
-
|
|
2568
|
+
__privateMethod(this, _LogDebugMessage, LogDebugMessage_fn).call(this, chalk$1.yellow(`STSOAuth2Manager:#ProcessMessageResponse: message data = [${JSON.stringify(messageResponse)}]`));
|
|
2573
2569
|
if (messageResponse.messageId === -1) {
|
|
2574
2570
|
switch (messageResponse.command) {
|
|
2575
2571
|
case IOauth2ListenerCommand.AUTHENTICATE_EVENT:
|
|
@@ -2606,10 +2602,10 @@ class STSOAuth2Manager {
|
|
|
2606
2602
|
__privateGet(this, _messageHandlers)[message.messageId] = (response) => {
|
|
2607
2603
|
clearTimeout(timeout);
|
|
2608
2604
|
delete __privateGet(this, _messageHandlers)[message.messageId];
|
|
2609
|
-
|
|
2605
|
+
__privateMethod(this, _LogDebugMessage, LogDebugMessage_fn).call(this, chalk$1.yellow(`STSOAuth2Manager:#PostMessage: resolve callback response= [${JSON.stringify(response)}]`));
|
|
2610
2606
|
resolve(response);
|
|
2611
2607
|
};
|
|
2612
|
-
|
|
2608
|
+
__privateMethod(this, _LogDebugMessage, LogDebugMessage_fn).call(this, chalk$1.yellow(`STSOAuth2Manager:#PostMessage: posting message = [${JSON.stringify(message)}]`));
|
|
2613
2609
|
__privateGet(this, _oauth2ManagerPort).postMessage(message);
|
|
2614
2610
|
});
|
|
2615
2611
|
});
|
|
@@ -2617,7 +2613,7 @@ class STSOAuth2Manager {
|
|
|
2617
2613
|
if (__privateGet(this, _aic)) {
|
|
2618
2614
|
__privateGet(this, _aic).LogEx(message);
|
|
2619
2615
|
}
|
|
2620
|
-
|
|
2616
|
+
__privateMethod(this, _LogDebugMessage, LogDebugMessage_fn).call(this, message);
|
|
2621
2617
|
});
|
|
2622
2618
|
// UpdateInstrument = (instrumentName: Gauge, telemetry: InstrumentBaseTelemetry): void => {
|
|
2623
2619
|
__privateAdd(this, _HandleUpdateInstrumentEvent, (instrumentName, telemetry) => {
|
|
@@ -2653,14 +2649,14 @@ class STSOAuth2Manager {
|
|
|
2653
2649
|
}
|
|
2654
2650
|
});
|
|
2655
2651
|
__privateAdd(this, _SetupRoute, (app, router) => {
|
|
2656
|
-
|
|
2652
|
+
__privateMethod(this, _LogDebugMessage, LogDebugMessage_fn).call(this, chalk$1.gray(`STSOAuth2Manager:#SetupRoute`));
|
|
2657
2653
|
router.beforeEach(async (to, from, next) => {
|
|
2658
2654
|
const oAuth2Manager = app.config.globalProperties.$sts[STSOAuth2ManagerPluginKey];
|
|
2659
|
-
|
|
2655
|
+
__privateMethod(this, _LogDebugMessage, LogDebugMessage_fn).call(this, chalk$1.gray(`beforeEach: from: [${from.path}], to: [${to.path}]`));
|
|
2660
2656
|
if (__privateGet(this, _GetStore).call(this).LoggedIn === false) {
|
|
2661
|
-
|
|
2657
|
+
__privateMethod(this, _LogInfoMessage, LogInfoMessage_fn).call(this, `Not logged in`);
|
|
2662
2658
|
if (to.path.localeCompare(`${__privateGet(this, _options).uriBase}authorize`) === 0) {
|
|
2663
|
-
|
|
2659
|
+
__privateMethod(this, _LogInfoMessage, LogInfoMessage_fn).call(this, `to = ${__privateGet(this, _options).uriBase}authorize`);
|
|
2664
2660
|
next();
|
|
2665
2661
|
return;
|
|
2666
2662
|
} else if (to.path.localeCompare(`${__privateGet(this, _options).uriBase}consent`) === 0) {
|
|
@@ -2687,9 +2683,9 @@ class STSOAuth2Manager {
|
|
|
2687
2683
|
}
|
|
2688
2684
|
const str = to.query;
|
|
2689
2685
|
if (str[OAuth2ParameterType.CODE] || str[OAuth2ParameterType.ERROR]) {
|
|
2690
|
-
|
|
2686
|
+
__privateMethod(this, _LogDebugMessage, LogDebugMessage_fn).call(this, chalk$1.magenta(`STSOAuth2Manager:#SetupRoute:Processing redirect: [${JSON.stringify(str)}]`));
|
|
2691
2687
|
const retVal = await oAuth2Manager.HandleRedirect(str);
|
|
2692
|
-
|
|
2688
|
+
__privateMethod(this, _LogDebugMessage, LogDebugMessage_fn).call(this, chalk$1.magenta(`STSOAuth2Manager:#SetupRoute:Redirect result: [${retVal}]`));
|
|
2693
2689
|
if (retVal) {
|
|
2694
2690
|
next({
|
|
2695
2691
|
path: `${__privateGet(this, _options).uriBase}`,
|
|
@@ -2704,11 +2700,11 @@ class STSOAuth2Manager {
|
|
|
2704
2700
|
return;
|
|
2705
2701
|
}
|
|
2706
2702
|
}
|
|
2707
|
-
|
|
2703
|
+
__privateMethod(this, _LogDebugMessage, LogDebugMessage_fn).call(this, `STSOAuth2Manager:#SetupRoute:Restoring session`);
|
|
2708
2704
|
const sessionRestored = await oAuth2Manager.RestoreSession();
|
|
2709
|
-
|
|
2705
|
+
__privateMethod(this, _LogDebugMessage, LogDebugMessage_fn).call(this, `STSOAuth2Manager:#SetupRoute:Session restored: [${sessionRestored}]`);
|
|
2710
2706
|
if (sessionRestored !== true) {
|
|
2711
|
-
|
|
2707
|
+
__privateMethod(this, _LogDebugMessage, LogDebugMessage_fn).call(this, `STSOAuth2Manager:#SetupRoute:Session not restored - need to authorize`);
|
|
2712
2708
|
oAuth2Manager.Authorize();
|
|
2713
2709
|
next();
|
|
2714
2710
|
return;
|
|
@@ -2745,7 +2741,7 @@ class STSOAuth2Manager {
|
|
|
2745
2741
|
throw new Error(`STSOAuth2Manager:ExecuteRefreshToken:maxSemaphoreRetries: [${__privateGet(this, _maxSemaphoreRetries)}] exceeded.`);
|
|
2746
2742
|
}
|
|
2747
2743
|
await Sleep(__privateGet(this, _semaphoreRetrySleep));
|
|
2748
|
-
|
|
2744
|
+
__privateMethod(this, _LogDebugMessage, LogDebugMessage_fn).call(this, chalk$1.cyan(`STSOAuth2Manager:ExecuteRefreshToken:locked by operationSemaphore, retry count: [${retryCount}]`));
|
|
2749
2745
|
return await this.ExecuteRefreshToken(retryCount + 1);
|
|
2750
2746
|
} else {
|
|
2751
2747
|
__privateSet(this, _operationSemaphore, true);
|
|
@@ -2761,12 +2757,12 @@ class STSOAuth2Manager {
|
|
|
2761
2757
|
});
|
|
2762
2758
|
__publicField(this, "RestoreSession", async () => {
|
|
2763
2759
|
try {
|
|
2764
|
-
|
|
2760
|
+
__privateMethod(this, _LogDebugMessage, LogDebugMessage_fn).call(this, `STSOAuth2Manager:RestoreSession:postMessage: [${IOauth2ListenerCommand.RESTORE_SESSION}]`);
|
|
2765
2761
|
const response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.RESTORE_SESSION });
|
|
2766
|
-
|
|
2762
|
+
__privateMethod(this, _LogDebugMessage, LogDebugMessage_fn).call(this, `STSOAuth2Manager:RestoreSession:response: [${JSON.stringify(response.payload)}]`);
|
|
2767
2763
|
return response.payload;
|
|
2768
2764
|
} catch (error) {
|
|
2769
|
-
|
|
2765
|
+
__privateMethod(this, _LogErrorMessage, LogErrorMessage_fn).call(this, chalk$1.red(`RestoreSession Error: ${error}`));
|
|
2770
2766
|
return false;
|
|
2771
2767
|
}
|
|
2772
2768
|
});
|
|
@@ -2781,18 +2777,18 @@ class STSOAuth2Manager {
|
|
|
2781
2777
|
return response.payload.authorizeOptionsClientCopy;
|
|
2782
2778
|
}
|
|
2783
2779
|
} catch (error) {
|
|
2784
|
-
|
|
2780
|
+
__privateMethod(this, _LogErrorMessage, LogErrorMessage_fn).call(this, chalk$1.red(`Authorize Error: ${error}`));
|
|
2785
2781
|
}
|
|
2786
2782
|
return {};
|
|
2787
2783
|
});
|
|
2788
2784
|
__publicField(this, "HandleRedirect", async (queryVars) => {
|
|
2789
2785
|
try {
|
|
2790
|
-
|
|
2786
|
+
__privateMethod(this, _LogDebugMessage, LogDebugMessage_fn).call(this, chalk$1.magenta(`STSOAuth2Manager:HandleRedirect`));
|
|
2791
2787
|
let response = null;
|
|
2792
2788
|
if (queryVars[OAuth2ParameterType.CODE]) {
|
|
2793
2789
|
const authorizeOptions = __privateGet(this, _transactionStore).get(__privateGet(this, _STORAGE_AUTHORIZE_OPTIONS_KEY));
|
|
2794
2790
|
__privateGet(this, _transactionStore).remove(__privateGet(this, _STORAGE_AUTHORIZE_OPTIONS_KEY));
|
|
2795
|
-
|
|
2791
|
+
__privateMethod(this, _LogDebugMessage, LogDebugMessage_fn).call(this, chalk$1.magenta(`STSOAuth2Manager:HandleRedirect: sending HANDLE_REDIRECT command`));
|
|
2796
2792
|
response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.HANDLE_REDIRECT, payload: {
|
|
2797
2793
|
queryVars,
|
|
2798
2794
|
authorizeOptions
|
|
@@ -2800,10 +2796,10 @@ class STSOAuth2Manager {
|
|
|
2800
2796
|
} else {
|
|
2801
2797
|
response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.HANDLE_REDIRECT, payload: queryVars });
|
|
2802
2798
|
}
|
|
2803
|
-
|
|
2799
|
+
__privateMethod(this, _LogDebugMessage, LogDebugMessage_fn).call(this, chalk$1.magenta(`STSOAuth2Manager:HandleRedirect: HANDLE_REDIRECT response: [${JSON.stringify(response)}]`));
|
|
2804
2800
|
return response.payload;
|
|
2805
2801
|
} catch (error) {
|
|
2806
|
-
|
|
2802
|
+
__privateMethod(this, _LogErrorMessage, LogErrorMessage_fn).call(this, chalk$1.red(`HandleRedirect Error: ${error}`));
|
|
2807
2803
|
return false;
|
|
2808
2804
|
}
|
|
2809
2805
|
});
|
|
@@ -2812,7 +2808,7 @@ class STSOAuth2Manager {
|
|
|
2812
2808
|
const response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.LOGOUT });
|
|
2813
2809
|
return response.payload;
|
|
2814
2810
|
} catch (error) {
|
|
2815
|
-
|
|
2811
|
+
__privateMethod(this, _LogErrorMessage, LogErrorMessage_fn).call(this, chalk$1.red(`Logout Error: ${error}`));
|
|
2816
2812
|
return false;
|
|
2817
2813
|
}
|
|
2818
2814
|
});
|
|
@@ -2822,7 +2818,7 @@ class STSOAuth2Manager {
|
|
|
2822
2818
|
const response = await __privateGet(this, _PostMessage).call(this, { command: IOauth2ListenerCommand.LOGOUT });
|
|
2823
2819
|
return response.payload;
|
|
2824
2820
|
} catch (error) {
|
|
2825
|
-
|
|
2821
|
+
__privateMethod(this, _LogErrorMessage, LogErrorMessage_fn).call(this, chalk$1.red(`InvokeExternalAPI Error: ${error}`));
|
|
2826
2822
|
return null;
|
|
2827
2823
|
}
|
|
2828
2824
|
});
|
|
@@ -2837,7 +2833,7 @@ class STSOAuth2Manager {
|
|
|
2837
2833
|
if (!isNode) {
|
|
2838
2834
|
if (app.config.globalProperties.$sts[STSInstrumentControllerPluginKey]) {
|
|
2839
2835
|
const STSInstrumentController = app.config.globalProperties.$sts[STSInstrumentControllerPluginKey];
|
|
2840
|
-
__privateSet(this, _aic, STSInstrumentController.
|
|
2836
|
+
__privateSet(this, _aic, STSInstrumentController.instrumentController);
|
|
2841
2837
|
}
|
|
2842
2838
|
__privateSet(this, _router, app.config.globalProperties.$router);
|
|
2843
2839
|
}
|
|
@@ -2853,10 +2849,10 @@ class STSOAuth2Manager {
|
|
|
2853
2849
|
}
|
|
2854
2850
|
if (!isNode) {
|
|
2855
2851
|
__privateGet(this, _worker).onmessage = (data) => {
|
|
2856
|
-
|
|
2852
|
+
__privateMethod(this, _LogInfoMessage, LogInfoMessage_fn).call(this, chalk$1.green(`this.#worker.onmessage = [${data}]`));
|
|
2857
2853
|
};
|
|
2858
|
-
__privateGet(this, _worker).onerror =
|
|
2859
|
-
|
|
2854
|
+
__privateGet(this, _worker).onerror = (error) => {
|
|
2855
|
+
__privateMethod(this, _LogInfoMessage, LogInfoMessage_fn).call(this, chalk$1.green(`this.#worker.onerror = [${JSON.stringify(error)}]`));
|
|
2860
2856
|
};
|
|
2861
2857
|
}
|
|
2862
2858
|
let workerMessage;
|
|
@@ -2913,6 +2909,18 @@ _transactionStore = new WeakMap();
|
|
|
2913
2909
|
_operationSemaphore = new WeakMap();
|
|
2914
2910
|
_maxSemaphoreRetries = new WeakMap();
|
|
2915
2911
|
_semaphoreRetrySleep = new WeakMap();
|
|
2912
|
+
_LogDebugMessage = new WeakSet();
|
|
2913
|
+
LogDebugMessage_fn = function(message) {
|
|
2914
|
+
__privateGet(this, _options).logger.debug(message);
|
|
2915
|
+
};
|
|
2916
|
+
_LogInfoMessage = new WeakSet();
|
|
2917
|
+
LogInfoMessage_fn = function(message) {
|
|
2918
|
+
__privateGet(this, _options).logger.info(message);
|
|
2919
|
+
};
|
|
2920
|
+
_LogErrorMessage = new WeakSet();
|
|
2921
|
+
LogErrorMessage_fn = function(message) {
|
|
2922
|
+
__privateGet(this, _options).logger.error(message);
|
|
2923
|
+
};
|
|
2916
2924
|
_ProcessMessageResponse = new WeakMap();
|
|
2917
2925
|
_PostMessage = new WeakMap();
|
|
2918
2926
|
_HandleLogEvent = new WeakMap();
|
|
@@ -2985,11 +2993,11 @@ var StatusCodes;
|
|
|
2985
2993
|
class STSOAuth2Worker {
|
|
2986
2994
|
constructor(workerPort, options, logger) {
|
|
2987
2995
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2988
|
-
__privateAdd(this,
|
|
2996
|
+
__privateAdd(this, _LogDebugMessage2);
|
|
2989
2997
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2990
|
-
__privateAdd(this,
|
|
2998
|
+
__privateAdd(this, _LogInfoMessage2);
|
|
2991
2999
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2992
|
-
__privateAdd(this,
|
|
3000
|
+
__privateAdd(this, _LogErrorMessage2);
|
|
2993
3001
|
//#storageManager = null;
|
|
2994
3002
|
__privateAdd(this, _clientSessionStore, void 0);
|
|
2995
3003
|
__privateAdd(this, _cUtils2, new CryptoUtils());
|
|
@@ -3089,7 +3097,7 @@ class STSOAuth2Worker {
|
|
|
3089
3097
|
__publicField(this, "SetupListener", () => {
|
|
3090
3098
|
__privateGet(this, _oauthWorkerPort).onmessage = async (data) => {
|
|
3091
3099
|
const auth2ListenerMessage = data.data;
|
|
3092
|
-
__privateMethod(this,
|
|
3100
|
+
__privateMethod(this, _LogDebugMessage2, LogDebugMessage_fn2).call(this, `STSOAuth2Worker:SetupListener:onmessage: [${auth2ListenerMessage.command}]`);
|
|
3093
3101
|
switch (auth2ListenerMessage.command) {
|
|
3094
3102
|
case IOauth2ListenerCommand.RESTORE_SESSION:
|
|
3095
3103
|
__privateGet(this, _ProcessCommand).call(this, auth2ListenerMessage, await __privateGet(this, _RestoreSession).call(this));
|
|
@@ -3131,12 +3139,12 @@ class STSOAuth2Worker {
|
|
|
3131
3139
|
const sessionData = __privateGet(this, _clientSessionStore).get(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
3132
3140
|
if (sessionData) {
|
|
3133
3141
|
restoredSessionData = sessionData.tokenResponse;
|
|
3134
|
-
__privateMethod(this,
|
|
3142
|
+
__privateMethod(this, _LogInfoMessage2, LogInfoMessage_fn2).call(this, "Session restored from client storage.");
|
|
3135
3143
|
__privateGet(this, _LogMessage).call(this, "Session restored from client storage.");
|
|
3136
3144
|
} else {
|
|
3137
3145
|
const url = `${__privateGet(this, _options2).brokerendpoint}:${__privateGet(this, _options2).brokerport}${__privateGet(this, _options2).brokerapiroot}/session`;
|
|
3138
|
-
__privateMethod(this,
|
|
3139
|
-
__privateMethod(this,
|
|
3146
|
+
__privateMethod(this, _LogInfoMessage2, LogInfoMessage_fn2).call(this, "RestoreSession");
|
|
3147
|
+
__privateMethod(this, _LogInfoMessage2, LogInfoMessage_fn2).call(this, url);
|
|
3140
3148
|
__privateGet(this, _LogMessage).call(this, "RestoreSession.");
|
|
3141
3149
|
__privateGet(this, _LogMessage).call(this, url);
|
|
3142
3150
|
try {
|
|
@@ -3153,7 +3161,7 @@ class STSOAuth2Worker {
|
|
|
3153
3161
|
// Ensure cookies are passed to the service
|
|
3154
3162
|
timeout: __privateGet(this, _options2).timeout
|
|
3155
3163
|
};
|
|
3156
|
-
__privateMethod(this,
|
|
3164
|
+
__privateMethod(this, _LogDebugMessage2, LogDebugMessage_fn2).call(this, chalk$1.magenta(`#RestoreSession:session request detail: [${JSON.stringify(rConfig)}]`));
|
|
3157
3165
|
if (isNode) {
|
|
3158
3166
|
rConfig.httpsAgent = __privateGet(this, _httpsAgent);
|
|
3159
3167
|
}
|
|
@@ -3168,24 +3176,24 @@ class STSOAuth2Worker {
|
|
|
3168
3176
|
newSessionData.brokerCookie = retVal.headers["set-cookie"];
|
|
3169
3177
|
}
|
|
3170
3178
|
__privateGet(this, _clientSessionStore).set(__privateGet(this, _STORAGE_SESSION_KEY2), newSessionData);
|
|
3171
|
-
__privateMethod(this,
|
|
3179
|
+
__privateMethod(this, _LogInfoMessage2, LogInfoMessage_fn2).call(this, "Session restored from server side cookie.");
|
|
3172
3180
|
} else {
|
|
3173
|
-
__privateMethod(this,
|
|
3174
|
-
__privateMethod(this,
|
|
3181
|
+
__privateMethod(this, _LogErrorMessage2, LogErrorMessage_fn2).call(this, `Could not restore previous session. No restoredSessionData available.`);
|
|
3182
|
+
__privateMethod(this, _LogErrorMessage2, LogErrorMessage_fn2).call(this, JSON.stringify(retVal.data));
|
|
3175
3183
|
}
|
|
3176
3184
|
} else {
|
|
3177
|
-
__privateMethod(this,
|
|
3178
|
-
__privateMethod(this,
|
|
3185
|
+
__privateMethod(this, _LogErrorMessage2, LogErrorMessage_fn2).call(this, "Could not restore previous session:-");
|
|
3186
|
+
__privateMethod(this, _LogErrorMessage2, LogErrorMessage_fn2).call(this, JSON.stringify(retVal.data));
|
|
3179
3187
|
}
|
|
3180
3188
|
} catch (error) {
|
|
3181
|
-
__privateMethod(this,
|
|
3182
|
-
__privateMethod(this,
|
|
3183
|
-
__privateMethod(this,
|
|
3189
|
+
__privateMethod(this, _LogErrorMessage2, LogErrorMessage_fn2).call(this, "Could not restore previous session (error state):-");
|
|
3190
|
+
__privateMethod(this, _LogErrorMessage2, LogErrorMessage_fn2).call(this, error);
|
|
3191
|
+
__privateMethod(this, _LogErrorMessage2, LogErrorMessage_fn2).call(this, JSON.stringify(error));
|
|
3184
3192
|
}
|
|
3185
3193
|
}
|
|
3186
3194
|
if (restoredSessionData !== null) {
|
|
3187
3195
|
__privateGet(this, _HandleAuthenticateEvent2).call(this, restoredSessionData.id_token);
|
|
3188
|
-
__privateMethod(this,
|
|
3196
|
+
__privateMethod(this, _LogInfoMessage2, LogInfoMessage_fn2).call(this, "Refreshing tokens ...");
|
|
3189
3197
|
return await __privateGet(this, _RefreshToken).call(this);
|
|
3190
3198
|
} else {
|
|
3191
3199
|
__privateGet(this, _HandleAuthenticateEvent2).call(this, null);
|
|
@@ -3193,7 +3201,7 @@ class STSOAuth2Worker {
|
|
|
3193
3201
|
}
|
|
3194
3202
|
});
|
|
3195
3203
|
__privateAdd(this, _Authorize, async () => {
|
|
3196
|
-
__privateMethod(this,
|
|
3204
|
+
__privateMethod(this, _LogInfoMessage2, LogInfoMessage_fn2).call(this, "Authorize ...");
|
|
3197
3205
|
const client_id = __privateGet(this, _options2).client_id;
|
|
3198
3206
|
const nonce = __privateGet(this, _cUtils2).CreateRandomString();
|
|
3199
3207
|
const response_type = [AuthorizeOptionsResponseType.CODE];
|
|
@@ -3217,9 +3225,9 @@ class STSOAuth2Worker {
|
|
|
3217
3225
|
};
|
|
3218
3226
|
const authorizeOptionsClientCopy = { ...authorizeOptions };
|
|
3219
3227
|
const url = `${__privateGet(this, _options2).authorizeendpoint}:${__privateGet(this, _options2).authorizeport}${__privateGet(this, _options2).authorizeapiroot}${__privateGet(this, _options2).authorizeapi}?${__privateGet(this, _qParams2).CreateQueryParams(authorizeOptions)}`;
|
|
3220
|
-
__privateMethod(this,
|
|
3228
|
+
__privateMethod(this, _LogInfoMessage2, LogInfoMessage_fn2).call(this, url);
|
|
3221
3229
|
authorizeOptions.code_verifier = code_verifier;
|
|
3222
|
-
__privateMethod(this,
|
|
3230
|
+
__privateMethod(this, _LogInfoMessage2, LogInfoMessage_fn2).call(this, `Authorize:authorizeOptions: [${JSON.stringify(authorizeOptions)}]`);
|
|
3223
3231
|
return {
|
|
3224
3232
|
url,
|
|
3225
3233
|
authorizeOptions,
|
|
@@ -3230,29 +3238,29 @@ class STSOAuth2Worker {
|
|
|
3230
3238
|
__privateAdd(this, _HandleRedirect, async (payload) => {
|
|
3231
3239
|
const queryVars = payload.queryVars;
|
|
3232
3240
|
const authorizeOptions = payload.authorizeOptions;
|
|
3233
|
-
__privateMethod(this,
|
|
3234
|
-
__privateMethod(this,
|
|
3241
|
+
__privateMethod(this, _LogDebugMessage2, LogDebugMessage_fn2).call(this, chalk$1.magenta(`#HandleRedirect: HandleRedirect`));
|
|
3242
|
+
__privateMethod(this, _LogDebugMessage2, LogDebugMessage_fn2).call(this, chalk$1.magenta(`#HandleRedirect: HandleRedirect:Query Vars: [${JSON.stringify(queryVars)}]`));
|
|
3235
3243
|
if (queryVars[OAuth2ParameterType.CODE]) {
|
|
3236
3244
|
const response = queryVars;
|
|
3237
|
-
__privateMethod(this,
|
|
3245
|
+
__privateMethod(this, _LogInfoMessage2, LogInfoMessage_fn2).call(this, `authorizeOptions from transaction state: [${JSON.stringify(authorizeOptions)}]`);
|
|
3238
3246
|
const redirectState = response.state;
|
|
3239
3247
|
const authorizeOptionsState = authorizeOptions.state;
|
|
3240
3248
|
if (authorizeOptionsState.localeCompare(redirectState) === 0) {
|
|
3241
|
-
__privateMethod(this,
|
|
3249
|
+
__privateMethod(this, _LogInfoMessage2, LogInfoMessage_fn2).call(this, chalk$1.green("redirected state (from queryVars) matched previously saved transaction authorizeOptions state"));
|
|
3242
3250
|
return await __privateGet(this, _GetToken).call(this, authorizeOptions, response);
|
|
3243
3251
|
} else {
|
|
3244
|
-
__privateMethod(this,
|
|
3245
|
-
__privateMethod(this,
|
|
3246
|
-
__privateMethod(this,
|
|
3252
|
+
__privateMethod(this, _LogErrorMessage2, LogErrorMessage_fn2).call(this, chalk$1.red("redirected state (from queryVars) did NOT match previously saved transaction authorizeOptions state"));
|
|
3253
|
+
__privateMethod(this, _LogErrorMessage2, LogErrorMessage_fn2).call(this, chalk$1.red(`authorizeOptionsState: [${authorizeOptionsState}]`));
|
|
3254
|
+
__privateMethod(this, _LogErrorMessage2, LogErrorMessage_fn2).call(this, chalk$1.red(`redirectState: [${redirectState}]`));
|
|
3247
3255
|
__privateGet(this, _HandleErrorEvent2).call(this, { message: "State un-matched" });
|
|
3248
3256
|
return false;
|
|
3249
3257
|
}
|
|
3250
3258
|
} else if (queryVars[OAuth2ParameterType.ERROR]) {
|
|
3251
|
-
__privateMethod(this,
|
|
3259
|
+
__privateMethod(this, _LogErrorMessage2, LogErrorMessage_fn2).call(this, chalk$1.red(`State un-matched (1)`));
|
|
3252
3260
|
__privateGet(this, _HandleErrorEvent2).call(this, { message: "State un-matched" });
|
|
3253
3261
|
return false;
|
|
3254
3262
|
} else {
|
|
3255
|
-
__privateMethod(this,
|
|
3263
|
+
__privateMethod(this, _LogErrorMessage2, LogErrorMessage_fn2).call(this, chalk$1.red(`State un-matched (2)`));
|
|
3256
3264
|
__privateGet(this, _HandleErrorEvent2).call(this, { message: "State un-matched" });
|
|
3257
3265
|
return false;
|
|
3258
3266
|
}
|
|
@@ -3278,7 +3286,7 @@ class STSOAuth2Worker {
|
|
|
3278
3286
|
*/
|
|
3279
3287
|
// Get access_token, refresh_token and id_token using OAuth2 Authorization Code Flow
|
|
3280
3288
|
__privateAdd(this, _GetTokenFromBroker, async (authorizationCodeFlowParameters) => {
|
|
3281
|
-
__privateMethod(this,
|
|
3289
|
+
__privateMethod(this, _LogDebugMessage2, LogDebugMessage_fn2).call(this, chalk$1.magenta(`#GetTokenFromBroker`));
|
|
3282
3290
|
__privateGet(this, _clientSessionStore).remove(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
3283
3291
|
const url = `${__privateGet(this, _options2).brokerendpoint}:${__privateGet(this, _options2).brokerport}${__privateGet(this, _options2).brokerapiroot}/token`;
|
|
3284
3292
|
try {
|
|
@@ -3290,15 +3298,15 @@ class STSOAuth2Worker {
|
|
|
3290
3298
|
// Ensure cookies are passed to the service
|
|
3291
3299
|
timeout: __privateGet(this, _options2).timeout
|
|
3292
3300
|
};
|
|
3293
|
-
__privateMethod(this,
|
|
3301
|
+
__privateMethod(this, _LogDebugMessage2, LogDebugMessage_fn2).call(this, chalk$1.magenta(`#GetTokenFromBroker: request config: [${JSON.stringify(rConfig)}]`));
|
|
3294
3302
|
if (isNode) {
|
|
3295
3303
|
rConfig.httpsAgent = __privateGet(this, _httpsAgent);
|
|
3296
3304
|
}
|
|
3297
|
-
__privateMethod(this,
|
|
3305
|
+
__privateMethod(this, _LogDebugMessage2, LogDebugMessage_fn2).call(this, chalk$1.magenta(`#GetTokenFromBroker: axios API call`));
|
|
3298
3306
|
const retVal = await axios(rConfig);
|
|
3299
|
-
__privateMethod(this,
|
|
3307
|
+
__privateMethod(this, _LogDebugMessage2, LogDebugMessage_fn2).call(this, chalk$1.magenta(`#GetTokenFromBroker: axios API call result: [${retVal.status}]`));
|
|
3300
3308
|
if (retVal.status === StatusCodes.OK) {
|
|
3301
|
-
__privateMethod(this,
|
|
3309
|
+
__privateMethod(this, _LogDebugMessage2, LogDebugMessage_fn2).call(this, chalk$1.magenta(`#GetTokenFromBroker: storing tokens`));
|
|
3302
3310
|
const tokenResponse = retVal.data;
|
|
3303
3311
|
__privateGet(this, _HandleAuthenticateEvent2).call(this, tokenResponse.id_token);
|
|
3304
3312
|
const newSessionData = {
|
|
@@ -3310,26 +3318,26 @@ class STSOAuth2Worker {
|
|
|
3310
3318
|
__privateGet(this, _clientSessionStore).set(__privateGet(this, _STORAGE_SESSION_KEY2), newSessionData);
|
|
3311
3319
|
return true;
|
|
3312
3320
|
} else if (retVal.status === StatusCodes.UNAUTHORIZED) {
|
|
3313
|
-
__privateMethod(this,
|
|
3321
|
+
__privateMethod(this, _LogDebugMessage2, LogDebugMessage_fn2).call(this, chalk$1.magenta(`#GetTokenFromBroker: NOT storing tokens, status: [${retVal.status}]`));
|
|
3314
3322
|
__privateGet(this, _HandleAuthenticateEvent2).call(this, null);
|
|
3315
3323
|
return false;
|
|
3316
3324
|
} else {
|
|
3317
|
-
__privateMethod(this,
|
|
3325
|
+
__privateMethod(this, _LogDebugMessage2, LogDebugMessage_fn2).call(this, chalk$1.magenta(`#GetTokenFromBroker: NOT storing tokens (general error 1), status: [${retVal.status}]`));
|
|
3318
3326
|
__privateGet(this, _HandleAuthenticateEvent2).call(this, null);
|
|
3319
|
-
__privateMethod(this,
|
|
3320
|
-
__privateMethod(this,
|
|
3327
|
+
__privateMethod(this, _LogErrorMessage2, LogErrorMessage_fn2).call(this, chalk$1.red("Could not obtain access_token from token end-point:-"));
|
|
3328
|
+
__privateMethod(this, _LogErrorMessage2, LogErrorMessage_fn2).call(this, chalk$1.red(JSON.stringify(retVal.data)));
|
|
3321
3329
|
return false;
|
|
3322
3330
|
}
|
|
3323
3331
|
} catch (error) {
|
|
3324
|
-
__privateMethod(this,
|
|
3332
|
+
__privateMethod(this, _LogErrorMessage2, LogErrorMessage_fn2).call(this, chalk$1.red(`#GetTokenFromBroker: NOT storing tokens (general error 2), status: [${error}]`));
|
|
3325
3333
|
__privateGet(this, _HandleAuthenticateEvent2).call(this, null);
|
|
3326
3334
|
return false;
|
|
3327
3335
|
}
|
|
3328
3336
|
});
|
|
3329
3337
|
// Get access_token, refresh_token and id_token using OAuth2 Authorization Code Flow
|
|
3330
3338
|
__privateAdd(this, _GetToken, async (authorizeOptions, authorizeResponse) => {
|
|
3331
|
-
__privateMethod(this,
|
|
3332
|
-
__privateMethod(this,
|
|
3339
|
+
__privateMethod(this, _LogInfoMessage2, LogInfoMessage_fn2).call(this, "#GetToken");
|
|
3340
|
+
__privateMethod(this, _LogInfoMessage2, LogInfoMessage_fn2).call(this, authorizeResponse);
|
|
3333
3341
|
__privateGet(this, _clientSessionStore).remove(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
3334
3342
|
const authorizationCodeFlowParameters = {
|
|
3335
3343
|
client_id: __privateGet(this, _options2).client_id,
|
|
@@ -3367,10 +3375,10 @@ class STSOAuth2Worker {
|
|
|
3367
3375
|
}
|
|
3368
3376
|
*/
|
|
3369
3377
|
__privateAdd(this, _RefreshToken, async () => {
|
|
3370
|
-
__privateMethod(this,
|
|
3378
|
+
__privateMethod(this, _LogDebugMessage2, LogDebugMessage_fn2).call(this, chalk$1.cyan(`STSOAuth2Worker:#RefreshToken:start`));
|
|
3371
3379
|
const sessionData = __privateGet(this, _clientSessionStore).get(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
3372
3380
|
if (sessionData) {
|
|
3373
|
-
__privateMethod(this,
|
|
3381
|
+
__privateMethod(this, _LogDebugMessage2, LogDebugMessage_fn2).call(this, chalk$1.cyan(`STSOAuth2Worker:#RefreshToken:sessionData: [${JSON.stringify(sessionData)}]`));
|
|
3374
3382
|
const currentSessionData = sessionData.tokenResponse;
|
|
3375
3383
|
const refreshFlowParameters = {
|
|
3376
3384
|
client_id: __privateGet(this, _options2).client_id,
|
|
@@ -3380,7 +3388,7 @@ class STSOAuth2Worker {
|
|
|
3380
3388
|
};
|
|
3381
3389
|
return await __privateGet(this, _GetTokenFromBroker).call(this, refreshFlowParameters);
|
|
3382
3390
|
} else {
|
|
3383
|
-
__privateMethod(this,
|
|
3391
|
+
__privateMethod(this, _LogErrorMessage2, LogErrorMessage_fn2).call(this, chalk$1.red(`STSOAuth2Worker:#RefreshToken:sessionData not found within clientSessionStore`));
|
|
3384
3392
|
return false;
|
|
3385
3393
|
}
|
|
3386
3394
|
});
|
|
@@ -3390,18 +3398,18 @@ class STSOAuth2Worker {
|
|
|
3390
3398
|
// clear session storage
|
|
3391
3399
|
// clear all state from $store
|
|
3392
3400
|
__privateAdd(this, _Logout, async () => {
|
|
3393
|
-
__privateMethod(this,
|
|
3401
|
+
__privateMethod(this, _LogInfoMessage2, LogInfoMessage_fn2).call(this, "Logout");
|
|
3394
3402
|
const url = `${__privateGet(this, _options2).brokerendpoint}:${__privateGet(this, _options2).brokerport}${__privateGet(this, _options2).brokerapiroot}/logout`;
|
|
3395
|
-
__privateMethod(this,
|
|
3403
|
+
__privateMethod(this, _LogInfoMessage2, LogInfoMessage_fn2).call(this, url);
|
|
3396
3404
|
const sessionData = __privateGet(this, _clientSessionStore).get(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
3397
3405
|
if (sessionData) {
|
|
3398
3406
|
const currentSessionData = sessionData.tokenResponse;
|
|
3399
3407
|
const refresh_token = currentSessionData.refresh_token;
|
|
3400
|
-
__privateMethod(this,
|
|
3408
|
+
__privateMethod(this, _LogInfoMessage2, LogInfoMessage_fn2).call(this, refresh_token);
|
|
3401
3409
|
const decodedRefreshToken = jwtDecode(refresh_token);
|
|
3402
|
-
__privateMethod(this,
|
|
3410
|
+
__privateMethod(this, _LogInfoMessage2, LogInfoMessage_fn2).call(this, decodedRefreshToken);
|
|
3403
3411
|
const sessionId = decodedRefreshToken.sts_session;
|
|
3404
|
-
__privateMethod(this,
|
|
3412
|
+
__privateMethod(this, _LogInfoMessage2, LogInfoMessage_fn2).call(this, sessionId);
|
|
3405
3413
|
__privateGet(this, _clientSessionStore).remove(__privateGet(this, _STORAGE_SESSION_KEY2));
|
|
3406
3414
|
__privateGet(this, _HandleAuthenticateEvent2).call(this, null);
|
|
3407
3415
|
try {
|
|
@@ -3415,7 +3423,7 @@ class STSOAuth2Worker {
|
|
|
3415
3423
|
// Ensure cookies are passed to the service
|
|
3416
3424
|
timeout: __privateGet(this, _options2).timeout
|
|
3417
3425
|
};
|
|
3418
|
-
__privateMethod(this,
|
|
3426
|
+
__privateMethod(this, _LogDebugMessage2, LogDebugMessage_fn2).call(this, chalk$1.magenta(`#Logout: request config: [${rConfig}]`));
|
|
3419
3427
|
if (isNode) {
|
|
3420
3428
|
rConfig.httpsAgent = __privateGet(this, _httpsAgent);
|
|
3421
3429
|
}
|
|
@@ -3423,27 +3431,27 @@ class STSOAuth2Worker {
|
|
|
3423
3431
|
if (retVal.data.status === StatusCodes.OK) {
|
|
3424
3432
|
return true;
|
|
3425
3433
|
} else {
|
|
3426
|
-
__privateMethod(this,
|
|
3427
|
-
__privateMethod(this,
|
|
3434
|
+
__privateMethod(this, _LogErrorMessage2, LogErrorMessage_fn2).call(this, chalk$1.red("Error during logout (1: server side)"));
|
|
3435
|
+
__privateMethod(this, _LogErrorMessage2, LogErrorMessage_fn2).call(this, chalk$1.red(JSON.stringify(retVal.data)));
|
|
3428
3436
|
return false;
|
|
3429
3437
|
}
|
|
3430
3438
|
} catch (error) {
|
|
3431
|
-
__privateMethod(this,
|
|
3432
|
-
__privateMethod(this,
|
|
3433
|
-
__privateMethod(this,
|
|
3439
|
+
__privateMethod(this, _LogErrorMessage2, LogErrorMessage_fn2).call(this, chalk$1.red("Error during logout (2: server side)"));
|
|
3440
|
+
__privateMethod(this, _LogErrorMessage2, LogErrorMessage_fn2).call(this, chalk$1.red(error));
|
|
3441
|
+
__privateMethod(this, _LogErrorMessage2, LogErrorMessage_fn2).call(this, chalk$1.red(JSON.stringify(error)));
|
|
3434
3442
|
return false;
|
|
3435
3443
|
}
|
|
3436
3444
|
} else {
|
|
3437
|
-
__privateMethod(this,
|
|
3445
|
+
__privateMethod(this, _LogInfoMessage2, LogInfoMessage_fn2).call(this, "Error during logout. Could not restore session from session storage.");
|
|
3438
3446
|
return false;
|
|
3439
3447
|
}
|
|
3440
3448
|
});
|
|
3441
3449
|
__privateSet(this, _options2, options);
|
|
3442
3450
|
__privateSet(this, _logger, logger);
|
|
3443
|
-
__privateMethod(this,
|
|
3451
|
+
__privateMethod(this, _LogDebugMessage2, LogDebugMessage_fn2).call(this, `STSOAuth2Worker:constructor:#options: [${JSON.stringify(__privateGet(this, _options2))}]`);
|
|
3444
3452
|
__privateSet(this, _clientSessionStore, new ClientStorageFactory({ clientStorageType: ClientStorageType.MEMORY_STORAGE, usePrefix: false }).GetStorage());
|
|
3445
3453
|
__privateSet(this, _oauthWorkerPort, workerPort);
|
|
3446
|
-
__privateMethod(this,
|
|
3454
|
+
__privateMethod(this, _LogDebugMessage2, LogDebugMessage_fn2).call(this, `STSOAuth2Worker:constructor:#oauthWorkerPort: [${JSON.stringify(__privateGet(this, _oauthWorkerPort))}]`);
|
|
3447
3455
|
if (isNode && __privateGet(this, _options2).agentOptions) {
|
|
3448
3456
|
__privateSet(this, _httpsAgent, new https.Agent({
|
|
3449
3457
|
keepAlive: __privateGet(this, _options2).agentOptions.keepAlive,
|
|
@@ -3469,16 +3477,16 @@ _oauthWorkerPort = new WeakMap();
|
|
|
3469
3477
|
_options2 = new WeakMap();
|
|
3470
3478
|
_httpsAgent = new WeakMap();
|
|
3471
3479
|
_logger = new WeakMap();
|
|
3472
|
-
|
|
3473
|
-
|
|
3480
|
+
_LogDebugMessage2 = new WeakSet();
|
|
3481
|
+
LogDebugMessage_fn2 = function(message) {
|
|
3474
3482
|
__privateGet(this, _logger).debug(message);
|
|
3475
3483
|
};
|
|
3476
|
-
|
|
3477
|
-
|
|
3484
|
+
_LogInfoMessage2 = new WeakSet();
|
|
3485
|
+
LogInfoMessage_fn2 = function(message) {
|
|
3478
3486
|
__privateGet(this, _logger).info(message);
|
|
3479
3487
|
};
|
|
3480
|
-
|
|
3481
|
-
|
|
3488
|
+
_LogErrorMessage2 = new WeakSet();
|
|
3489
|
+
LogErrorMessage_fn2 = function(message) {
|
|
3482
3490
|
__privateGet(this, _logger).error(message);
|
|
3483
3491
|
};
|
|
3484
3492
|
_HandleAuthenticateEvent2 = new WeakMap();
|