@nsshunt/stsoauth2plugin 1.0.163 → 1.0.164
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/index.cjs +14 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +15 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -7
- package/types/stsoauth2manager.d.ts.map +1 -1
- package/types/stsoauth2worker.d.ts.map +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { inject } from "vue";
|
|
2
2
|
import * as wt from "node:worker_threads";
|
|
3
|
-
import { OAuth2ParameterType, STSAxiosConfig, Sleep, createAgentManager } from "@nsshunt/stsutils";
|
|
3
|
+
import { OAuth2ParameterType, STSAxiosConfig, Sleep, createAgentManager, isNode } from "@nsshunt/stsutils";
|
|
4
4
|
import { ClientStorageFactory, ClientStorageType } from "@nsshunt/stsvueutils";
|
|
5
5
|
import { defineStore } from "pinia";
|
|
6
6
|
import axios from "axios";
|
|
@@ -373,9 +373,6 @@ var chalk$1 = createChalk$1();
|
|
|
373
373
|
createChalk$1({ level: stderrColor$1 ? stderrColor$1.level : 0 });
|
|
374
374
|
//#endregion
|
|
375
375
|
//#region src/stsoauth2types.ts
|
|
376
|
-
var import_browser = /* @__PURE__ */ __toESM$1((/* @__PURE__ */ __commonJSMin$1(((exports, module) => {
|
|
377
|
-
module.exports = false;
|
|
378
|
-
})))(), 1);
|
|
379
376
|
var AuthorizeOptionsResponseType = /* @__PURE__ */ function(AuthorizeOptionsResponseType) {
|
|
380
377
|
AuthorizeOptionsResponseType["CODE"] = "code";
|
|
381
378
|
AuthorizeOptionsResponseType["ID_TOKEN"] = "id_token";
|
|
@@ -3118,11 +3115,11 @@ var STSOAuth2Manager = class {
|
|
|
3118
3115
|
#semaphoreRetrySleep = 50;
|
|
3119
3116
|
constructor(app, options) {
|
|
3120
3117
|
this.#options = options;
|
|
3121
|
-
if (!
|
|
3118
|
+
if (!isNode) {
|
|
3122
3119
|
if (app.config.globalProperties.$sts[STSInstrumentControllerPluginKey]) this.#aic = app.config.globalProperties.$sts[STSInstrumentControllerPluginKey];
|
|
3123
3120
|
this.#router = app.config.globalProperties.$router;
|
|
3124
3121
|
}
|
|
3125
|
-
if (
|
|
3122
|
+
if (isNode) this.#transactionStore = new ClientStorageFactory({
|
|
3126
3123
|
clientStorageType: ClientStorageType.MEMORY_STORAGE,
|
|
3127
3124
|
usePrefix: false
|
|
3128
3125
|
}).GetStorage();
|
|
@@ -3132,7 +3129,7 @@ var STSOAuth2Manager = class {
|
|
|
3132
3129
|
}).GetStorage();
|
|
3133
3130
|
if (this.#options.workerFactory) this.#worker = this.#options.workerFactory();
|
|
3134
3131
|
else throw new Error(`STSOAuth2Manager:constructor: Cannot init STSOAuth2Manager - this.#options.workerFactory not specified`);
|
|
3135
|
-
if (!
|
|
3132
|
+
if (!isNode) {
|
|
3136
3133
|
this.#worker.onmessage = (data) => {
|
|
3137
3134
|
this.#LogInfoMessage(chalk$1.green(`this.#worker.onmessage = [${data}]`));
|
|
3138
3135
|
};
|
|
@@ -3141,7 +3138,7 @@ var STSOAuth2Manager = class {
|
|
|
3141
3138
|
};
|
|
3142
3139
|
}
|
|
3143
3140
|
let workerMessage;
|
|
3144
|
-
if (
|
|
3141
|
+
if (isNode) {
|
|
3145
3142
|
const { port1: oauth2ManagerPort, port2: oauth2WorkerPort } = new wt.MessageChannel();
|
|
3146
3143
|
this.#oauth2ManagerPort = oauth2ManagerPort;
|
|
3147
3144
|
workerMessage = {
|
|
@@ -3227,7 +3224,7 @@ var STSOAuth2Manager = class {
|
|
|
3227
3224
|
return STSOauth2Store(this.#options.pinia);
|
|
3228
3225
|
};
|
|
3229
3226
|
#HandleErrorEvent = (error) => {
|
|
3230
|
-
if (
|
|
3227
|
+
if (isNode) {} else {
|
|
3231
3228
|
this.#GetStore().UpdateError({ message: error });
|
|
3232
3229
|
setTimeout(() => {
|
|
3233
3230
|
this.#router.replace(`${this.#options.uriBase}error`);
|
|
@@ -3235,7 +3232,7 @@ var STSOAuth2Manager = class {
|
|
|
3235
3232
|
}
|
|
3236
3233
|
};
|
|
3237
3234
|
#HandleAuthenticateEvent = (id_token) => {
|
|
3238
|
-
if (
|
|
3235
|
+
if (isNode) {} else {
|
|
3239
3236
|
if (this.#options.authenticateEvent) this.#options.authenticateEvent(id_token);
|
|
3240
3237
|
this.#GetStore().UpdateIdToken(id_token);
|
|
3241
3238
|
}
|
|
@@ -3356,7 +3353,7 @@ var STSOAuth2Manager = class {
|
|
|
3356
3353
|
const response = await this.#PostMessage({ command: IOauth2ListenerCommand.AUTHORIZE });
|
|
3357
3354
|
this.#transactionStore.set(this.#STORAGE_AUTHORIZE_OPTIONS_KEY, response.payload.authorizeOptions);
|
|
3358
3355
|
const url = response.payload.url;
|
|
3359
|
-
if (!
|
|
3356
|
+
if (!isNode) window.location.replace(url);
|
|
3360
3357
|
else return response.payload.authorizeOptionsClientCopy;
|
|
3361
3358
|
} catch (error) {
|
|
3362
3359
|
this.#LogErrorMessage(chalk$1.red(`Authorize Error: ${error}`));
|
|
@@ -4320,7 +4317,7 @@ var STSOAuth2Worker = class {
|
|
|
4320
4317
|
}).GetStorage();
|
|
4321
4318
|
this.#oauthWorkerPort = workerPort;
|
|
4322
4319
|
this.#LogDebugMessage(`STSOAuth2Worker:constructor:#oauthWorkerPort: [${JSON.stringify(this.#oauthWorkerPort)}]`);
|
|
4323
|
-
if (
|
|
4320
|
+
if (isNode && this.#options.agentOptions) this.#agentManager = createAgentManager({
|
|
4324
4321
|
agentOptions: this.#options.agentOptions,
|
|
4325
4322
|
httpAgentFactory(options) {
|
|
4326
4323
|
return new http.Agent(options);
|
|
@@ -4368,7 +4365,7 @@ var STSOAuth2Worker = class {
|
|
|
4368
4365
|
else return null;
|
|
4369
4366
|
};
|
|
4370
4367
|
#GetCookies = () => {
|
|
4371
|
-
if (
|
|
4368
|
+
if (isNode) {
|
|
4372
4369
|
const sessionData = this.#clientSessionStore.get(this.#STORAGE_SESSION_KEY);
|
|
4373
4370
|
if (sessionData) return sessionData.brokerCookie;
|
|
4374
4371
|
else return null;
|
|
@@ -4443,13 +4440,13 @@ var STSOAuth2Worker = class {
|
|
|
4443
4440
|
[OAuth2ParameterType.AUDIENCE]: this.#options.audience
|
|
4444
4441
|
}).withDefaultHeaders().withCredentials().withTimeout(this.#options.timeout);
|
|
4445
4442
|
this.#LogDebugMessage(chalk$1.magenta(`#RestoreSession:session request detail: [${JSON.stringify(rConfig)}]`));
|
|
4446
|
-
if (
|
|
4443
|
+
if (isNode && this.#agentManager) rConfig.withAgentManager(this.#agentManager);
|
|
4447
4444
|
const retVal = await axios(rConfig.config);
|
|
4448
4445
|
if (retVal.data.status === StatusCodes.OK) {
|
|
4449
4446
|
restoredSessionData = retVal.data.detail;
|
|
4450
4447
|
if (restoredSessionData) {
|
|
4451
4448
|
const newSessionData = { tokenResponse: restoredSessionData };
|
|
4452
|
-
if (
|
|
4449
|
+
if (isNode) newSessionData.brokerCookie = retVal.headers["set-cookie"];
|
|
4453
4450
|
this.#clientSessionStore.set(this.#STORAGE_SESSION_KEY, newSessionData);
|
|
4454
4451
|
this.#LogInfoMessage("Session restored from server side cookie.");
|
|
4455
4452
|
} else {
|
|
@@ -4544,7 +4541,7 @@ var STSOAuth2Worker = class {
|
|
|
4544
4541
|
try {
|
|
4545
4542
|
const rConfig = new STSAxiosConfig(url, "post").withDefaultHeaders().withData(authorizationCodeFlowParameters).withCredentials().withTimeout(this.#options.timeout);
|
|
4546
4543
|
this.#LogDebugMessage(chalk$1.magenta(`#GetTokenFromBroker: request config: [${JSON.stringify(rConfig)}]`));
|
|
4547
|
-
if (
|
|
4544
|
+
if (isNode && this.#agentManager) rConfig.withAgentManager(this.#agentManager);
|
|
4548
4545
|
this.#LogDebugMessage(chalk$1.magenta(`#GetTokenFromBroker: axios API call`));
|
|
4549
4546
|
const retVal = await axios(rConfig.config);
|
|
4550
4547
|
this.#LogDebugMessage(chalk$1.magenta(`#GetTokenFromBroker: axios API call result: [${retVal.status}]`));
|
|
@@ -4553,7 +4550,7 @@ var STSOAuth2Worker = class {
|
|
|
4553
4550
|
const tokenResponse = retVal.data;
|
|
4554
4551
|
this.#HandleAuthenticateEvent(tokenResponse.id_token);
|
|
4555
4552
|
const newSessionData = { tokenResponse };
|
|
4556
|
-
if (
|
|
4553
|
+
if (isNode) newSessionData.brokerCookie = retVal.headers["set-cookie"];
|
|
4557
4554
|
this.#clientSessionStore.set(this.#STORAGE_SESSION_KEY, newSessionData);
|
|
4558
4555
|
return true;
|
|
4559
4556
|
} else if (retVal.status === StatusCodes.UNAUTHORIZED) {
|
|
@@ -4621,7 +4618,7 @@ var STSOAuth2Worker = class {
|
|
|
4621
4618
|
this.#HandleAuthenticateEvent(null);
|
|
4622
4619
|
try {
|
|
4623
4620
|
const rConfig = new STSAxiosConfig(url, "post").withData({ sessionId }).withDefaultHeaders().withCredentials().withTimeout(this.#options.timeout);
|
|
4624
|
-
if (
|
|
4621
|
+
if (isNode && this.#agentManager) rConfig.withAgentManager(this.#agentManager);
|
|
4625
4622
|
this.#LogDebugMessage(chalk$1.magenta(`#Logout: request config: [${rConfig}]`));
|
|
4626
4623
|
const retVal = await axios(rConfig.config);
|
|
4627
4624
|
if (retVal.data.status === StatusCodes.OK) return true;
|