@nsshunt/stsoauth2plugin 0.1.96 → 0.1.99
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/Utils/CryptoUtils.js +32 -30
- package/dist/Utils/CryptoUtils.js.map +1 -1
- package/dist/Utils/QueryParams.js +43 -43
- package/dist/Utils/QueryParams.js.map +1 -1
- package/dist/index.js +27 -11
- package/dist/index.js.map +1 -1
- package/dist/stores/stsoauth2store.js +10 -4
- package/dist/stores/stsoauth2store.js.map +1 -1
- package/dist/stores/testStore.js +5 -2
- package/dist/stores/testStore.js.map +1 -1
- package/dist/stsStorage.js +125 -117
- package/dist/stsStorage.js.map +1 -1
- package/dist/stsoauth2launcher.js +4 -2
- package/dist/stsoauth2launcher.js.map +1 -1
- package/dist/stsoauth2manager.js +289 -302
- package/dist/stsoauth2manager.js.map +1 -1
- package/dist/stsoauth2types.js +11 -8
- package/dist/stsoauth2types.js.map +1 -1
- package/dist/stsoauth2worker.js +471 -532
- package/dist/stsoauth2worker.js.map +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +4 -0
- package/types/index.d.ts.map +1 -1
package/dist/stsoauth2manager.js
CHANGED
|
@@ -1,335 +1,322 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
4
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
import CryptoUtils from './Utils/CryptoUtils';
|
|
17
|
-
import QueryParams from './Utils/QueryParams';
|
|
18
|
-
import { IOauth2ListenerCommand } from './stsoauth2types';
|
|
19
|
-
import { ClientStorageType, ClientStorageFactory } from './stsStorage';
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.STSOAuth2Manager = void 0;
|
|
7
|
+
const debug_1 = __importDefault(require("debug"));
|
|
8
|
+
const debug = (0, debug_1.default)(`proc:${process.pid}:stsoauth2manager.ts`);
|
|
9
|
+
const stsutils_1 = require("@nsshunt/stsutils");
|
|
10
|
+
const CryptoUtils_1 = __importDefault(require("./Utils/CryptoUtils"));
|
|
11
|
+
const QueryParams_1 = __importDefault(require("./Utils/QueryParams"));
|
|
12
|
+
const stsoauth2types_1 = require("./stsoauth2types");
|
|
13
|
+
const stsStorage_1 = require("./stsStorage");
|
|
20
14
|
//import piniaPersist from 'pinia-plugin-persist'
|
|
21
|
-
|
|
15
|
+
const stsoauth2store_1 = require("./stores/stsoauth2store");
|
|
22
16
|
// STS Client SDK for SPAs
|
|
23
|
-
|
|
17
|
+
class STSOAuth2Manager {
|
|
18
|
+
#storageManager = null;
|
|
19
|
+
#router = null;
|
|
20
|
+
#cUtils = new CryptoUtils_1.default();
|
|
21
|
+
#qParams = new QueryParams_1.default();
|
|
22
|
+
#STORAGE_AUTHORIZE_OPTIONS_KEY = 'authorize_options.stsmda.com.au';
|
|
23
|
+
#STORAGE_SESSION_KEY = 'session.stsmda.com.au';
|
|
24
|
+
#aic = null;
|
|
25
|
+
#options = null;
|
|
26
|
+
#messages = {};
|
|
27
|
+
#oauth2ManagerPort;
|
|
28
|
+
#messageId = 0;
|
|
29
|
+
#messageHandlers = {}; // keyed by messageId
|
|
30
|
+
#messageTimeout = 1000;
|
|
31
|
+
#worker = null;
|
|
32
|
+
#transactionStore = null; // Transient transaction data used to establish a session via OAuth2 authorize handshake
|
|
33
|
+
#stsOauth2Store = null;
|
|
24
34
|
constructor(app, options) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
case IOauth2ListenerCommand.UPDATE_INSTRUMENT:
|
|
56
|
-
__classPrivateFieldGet(this, _STSOAuth2Manager_HandleUpdateInstrumentEvent, "f").call(this, messageResponse.payload.instrumentName, messageResponse.payload.telemetry);
|
|
57
|
-
break;
|
|
58
|
-
default:
|
|
59
|
-
throw new Error(`ProcessMessageResponse command [${messageResponse.command}] not valid.`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
const callBack = __classPrivateFieldGet(this, _STSOAuth2Manager_messageHandlers, "f")[messageResponse.messageId];
|
|
64
|
-
if (callBack) {
|
|
65
|
-
callBack(messageResponse);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
throw new Error(`Message: [${messageResponse.messageId}] does not exists in callBacks.`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
_STSOAuth2Manager_PostMessage.set(this, (message) => {
|
|
73
|
-
var _a, _b;
|
|
74
|
-
message.messageId = (__classPrivateFieldSet(this, _STSOAuth2Manager_messageId, (_b = __classPrivateFieldGet(this, _STSOAuth2Manager_messageId, "f"), _a = _b++, _b), "f"), _a);
|
|
75
|
-
return new Promise((resolve, reject) => {
|
|
76
|
-
// Setup message timeout
|
|
77
|
-
const timeout = setTimeout(() => {
|
|
78
|
-
delete __classPrivateFieldGet(this, _STSOAuth2Manager_messageHandlers, "f")[message.messageId];
|
|
79
|
-
reject(`Message: [${message.messageId}] timeout error after: [${__classPrivateFieldGet(this, _STSOAuth2Manager_messageTimeout, "f")}] ms.`);
|
|
80
|
-
}, __classPrivateFieldGet(this, _STSOAuth2Manager_messageTimeout, "f"));
|
|
81
|
-
// Setup message callback based on messageId
|
|
82
|
-
__classPrivateFieldGet(this, _STSOAuth2Manager_messageHandlers, "f")[message.messageId] = (response) => {
|
|
83
|
-
clearTimeout(timeout);
|
|
84
|
-
delete __classPrivateFieldGet(this, _STSOAuth2Manager_messageHandlers, "f")[message.messageId];
|
|
85
|
-
resolve(response);
|
|
86
|
-
};
|
|
87
|
-
// Send the message
|
|
88
|
-
__classPrivateFieldGet(this, _STSOAuth2Manager_oauth2ManagerPort, "f").postMessage(message);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
_STSOAuth2Manager_HandleLogEvent.set(this, (message) => {
|
|
92
|
-
if (__classPrivateFieldGet(this, _STSOAuth2Manager_aic, "f")) {
|
|
93
|
-
__classPrivateFieldGet(this, _STSOAuth2Manager_aic, "f").LogEx(message);
|
|
94
|
-
}
|
|
95
|
-
debug(message);
|
|
35
|
+
this.#options = options;
|
|
36
|
+
this.#storageManager = app.config.globalProperties.$sts.storage;
|
|
37
|
+
this.#aic = app.config.globalProperties.$sts.aic.PrimaryPublishInstrumentController;
|
|
38
|
+
this.#router = app.config.globalProperties.$router;
|
|
39
|
+
if (!this.#options.workerOptions.nodeMode) {
|
|
40
|
+
this.#stsOauth2Store = (0, stsoauth2store_1.STSOauth2Store)();
|
|
41
|
+
}
|
|
42
|
+
// Use session storage for the transient nature of the OAuth2 authorize handshake. Once completed, the storage will be removed.
|
|
43
|
+
this.#transactionStore = new stsStorage_1.ClientStorageFactory({ clientStorageType: stsStorage_1.ClientStorageType.SESSION_STORAGE }).GetStorage();
|
|
44
|
+
this.#worker = this.#options.workerFactory();
|
|
45
|
+
this.#worker.onmessage = (data) => {
|
|
46
|
+
console.log(`this.#worker.onmessage = [${data}]`); // green
|
|
47
|
+
};
|
|
48
|
+
this.#worker.onerror = function (error) {
|
|
49
|
+
console.log(`this.#worker.onerror = [${JSON.stringify(error)}]`); // green
|
|
50
|
+
};
|
|
51
|
+
const { port1: oauth2ManagerPort, // this process port
|
|
52
|
+
port2: oauth2WorkerPort // worker port
|
|
53
|
+
} = new MessageChannel();
|
|
54
|
+
this.#oauth2ManagerPort = oauth2ManagerPort;
|
|
55
|
+
const workerMessage = {
|
|
56
|
+
workerPort: oauth2WorkerPort,
|
|
57
|
+
options: this.#options.workerOptions
|
|
58
|
+
};
|
|
59
|
+
this.#worker.postMessage(workerMessage, [oauth2WorkerPort]);
|
|
60
|
+
this.#oauth2ManagerPort.onmessage = (data) => {
|
|
61
|
+
this.#ProcessMessageResponse(data);
|
|
62
|
+
};
|
|
63
|
+
if (!this.#options.workerOptions.nodeMode) {
|
|
64
|
+
this.#SetupRoute(app, this.#router);
|
|
96
65
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
66
|
+
}
|
|
67
|
+
#ProcessMessageResponse = (data) => {
|
|
68
|
+
const messageResponse = data.data;
|
|
69
|
+
if (messageResponse.messageId === -1) {
|
|
70
|
+
// unsolicted message
|
|
71
|
+
switch (messageResponse.command) {
|
|
72
|
+
case stsoauth2types_1.IOauth2ListenerCommand.AUTHENTICATE_EVENT:
|
|
73
|
+
this.#HandleAuthenticateEvent(messageResponse.payload);
|
|
74
|
+
break;
|
|
75
|
+
case stsoauth2types_1.IOauth2ListenerCommand.ERROR:
|
|
76
|
+
this.#HandleErrorEvent(messageResponse.payload);
|
|
77
|
+
break;
|
|
78
|
+
case stsoauth2types_1.IOauth2ListenerCommand.LOG:
|
|
79
|
+
this.#HandleLogEvent(messageResponse.payload);
|
|
80
|
+
break;
|
|
81
|
+
case stsoauth2types_1.IOauth2ListenerCommand.UPDATE_INSTRUMENT:
|
|
82
|
+
this.#HandleUpdateInstrumentEvent(messageResponse.payload.instrumentName, messageResponse.payload.telemetry);
|
|
83
|
+
break;
|
|
84
|
+
default:
|
|
85
|
+
throw new Error(`ProcessMessageResponse command [${messageResponse.command}] not valid.`);
|
|
103
86
|
}
|
|
104
87
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (__classPrivateFieldGet(this, _STSOAuth2Manager_options, "f").workerOptions.nodeMode) {
|
|
110
|
-
// Node Mode ...
|
|
88
|
+
else {
|
|
89
|
+
const callBack = this.#messageHandlers[messageResponse.messageId];
|
|
90
|
+
if (callBack) {
|
|
91
|
+
callBack(messageResponse);
|
|
111
92
|
}
|
|
112
93
|
else {
|
|
113
|
-
|
|
114
|
-
__classPrivateFieldGet(this, _STSOAuth2Manager_stsOauth2Store, "f").UpdateError({
|
|
115
|
-
message: error
|
|
116
|
-
});
|
|
117
|
-
// plugin to do this ...
|
|
118
|
-
setTimeout(() => {
|
|
119
|
-
__classPrivateFieldGet(this, _STSOAuth2Manager_router, "f").replace('/error'); //@@ was push
|
|
120
|
-
}, 0);
|
|
94
|
+
throw new Error(`Message: [${messageResponse.messageId}] does not exists in callBacks.`);
|
|
121
95
|
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
#PostMessage = (message) => {
|
|
99
|
+
message.messageId = this.#messageId++;
|
|
100
|
+
return new Promise((resolve, reject) => {
|
|
101
|
+
// Setup message timeout
|
|
102
|
+
const timeout = setTimeout(() => {
|
|
103
|
+
delete this.#messageHandlers[message.messageId];
|
|
104
|
+
reject(`Message: [${message.messageId}] timeout error after: [${this.#messageTimeout}] ms.`);
|
|
105
|
+
}, this.#messageTimeout);
|
|
106
|
+
// Setup message callback based on messageId
|
|
107
|
+
this.#messageHandlers[message.messageId] = (response) => {
|
|
108
|
+
clearTimeout(timeout);
|
|
109
|
+
delete this.#messageHandlers[message.messageId];
|
|
110
|
+
resolve(response);
|
|
111
|
+
};
|
|
112
|
+
// Send the message
|
|
113
|
+
this.#oauth2ManagerPort.postMessage(message);
|
|
122
114
|
});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
115
|
+
};
|
|
116
|
+
#HandleLogEvent = (message) => {
|
|
117
|
+
if (this.#aic) {
|
|
118
|
+
this.#aic.LogEx(message);
|
|
119
|
+
}
|
|
120
|
+
debug(message);
|
|
121
|
+
};
|
|
122
|
+
// UpdateInstrument = (instrumentName: Gauge, telemetry: InstrumentBaseTelemetry): void => {
|
|
123
|
+
#HandleUpdateInstrumentEvent = (instrumentName, telemetry) => {
|
|
124
|
+
if (this.#aic) {
|
|
125
|
+
this.#aic.UpdateInstrument(instrumentName, telemetry);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
// Will come from message channel
|
|
129
|
+
#HandleErrorEvent = (error) => {
|
|
130
|
+
if (this.#options.workerOptions.nodeMode) {
|
|
131
|
+
// Node Mode ...
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
// User Agent Mode
|
|
135
|
+
this.#stsOauth2Store.UpdateError({
|
|
136
|
+
message: error
|
|
137
|
+
});
|
|
138
|
+
// plugin to do this ...
|
|
139
|
+
setTimeout(() => {
|
|
140
|
+
this.#router.replace('/error'); //@@ was push
|
|
141
|
+
}, 0);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
#HandleAuthenticateEvent = (id_token) => {
|
|
145
|
+
if (this.#options.workerOptions.nodeMode) {
|
|
146
|
+
// Node Mode ...
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
// User Agent Mode
|
|
150
|
+
if (this.#options.authenticateEvent) {
|
|
151
|
+
this.#options.authenticateEvent(id_token);
|
|
126
152
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
153
|
+
this.#stsOauth2Store.UpdateIdToken(id_token);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
#SetupRoute = (app, router) => {
|
|
157
|
+
router.beforeEach(async (to, from) => {
|
|
158
|
+
const sts = app.config.globalProperties.$sts;
|
|
159
|
+
debug(`beforeEach: from: [${from.path}], to: [${to.path}]`); // gray
|
|
160
|
+
if (this.#stsOauth2Store.LoggedIn === false) {
|
|
161
|
+
//if (store.getters['stsOAuth2SDK/LoggedIn'] === false) {
|
|
162
|
+
console.log(`Not logged in`);
|
|
163
|
+
// Not logged in
|
|
164
|
+
if (to.path.localeCompare('/authorize') === 0) {
|
|
165
|
+
console.log(`to = /authorize`);
|
|
166
|
+
return true;
|
|
131
167
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
router.beforeEach(async (to, from) => {
|
|
137
|
-
const sts = app.config.globalProperties.$sts;
|
|
138
|
-
debug(`beforeEach: from: [${from.path}], to: [${to.path}]`); // gray
|
|
139
|
-
if (__classPrivateFieldGet(this, _STSOAuth2Manager_stsOauth2Store, "f").LoggedIn === false) {
|
|
140
|
-
//if (store.getters['stsOAuth2SDK/LoggedIn'] === false) {
|
|
141
|
-
console.log(`Not logged in`);
|
|
142
|
-
// Not logged in
|
|
143
|
-
if (to.path.localeCompare('/authorize') === 0) {
|
|
144
|
-
console.log(`to = /authorize`);
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
else if (to.path.localeCompare('/consent') === 0) {
|
|
148
|
-
// Need to check if we are in the correct state, if not - drop back to the start of the process
|
|
149
|
-
if (__classPrivateFieldGet(this, _STSOAuth2Manager_stsOauth2Store, "f").id_token) {
|
|
150
|
-
//if (typeof store.getters.Session.sessionId !== 'undefined') {
|
|
151
|
-
return true;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (to.path.localeCompare('/logout') === 0) {
|
|
155
|
-
return true;
|
|
156
|
-
}
|
|
157
|
-
if (to.path.localeCompare('/error') === 0) {
|
|
158
|
-
return true;
|
|
159
|
-
}
|
|
160
|
-
if (to.path.localeCompare('/logout') === 0) {
|
|
168
|
+
else if (to.path.localeCompare('/consent') === 0) {
|
|
169
|
+
// Need to check if we are in the correct state, if not - drop back to the start of the process
|
|
170
|
+
if (this.#stsOauth2Store.id_token) {
|
|
171
|
+
//if (typeof store.getters.Session.sessionId !== 'undefined') {
|
|
161
172
|
return true;
|
|
162
173
|
}
|
|
163
|
-
const str = to.query;
|
|
164
|
-
// Check if this route is from a redirect from the authorization server
|
|
165
|
-
if (str[OAuth2ParameterType.CODE] || str[OAuth2ParameterType.ERROR]) {
|
|
166
|
-
debug(`STSOAuth2Manager:#SetupRoute:Processing redirect: [${str}]`);
|
|
167
|
-
const retVal = await sts.om.HandleRedirect(str);
|
|
168
|
-
debug(`STSOAuth2Manager:#SetupRoute:Redirect result: [${retVal}]`);
|
|
169
|
-
if (retVal) {
|
|
170
|
-
// Success
|
|
171
|
-
setTimeout(() => {
|
|
172
|
-
window.history.replaceState({}, document.title, window.location.origin + '/');
|
|
173
|
-
}, 0);
|
|
174
|
-
return true;
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
// Error
|
|
178
|
-
//@@ need the error data here - or use the vuex store ?
|
|
179
|
-
__classPrivateFieldGet(this, _STSOAuth2Manager_router, "f").replace('/error'); //@@ was push
|
|
180
|
-
//@@ should replaceState be used as in above?
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
debug(`STSOAuth2Manager:#SetupRoute:Restoring session`);
|
|
185
|
-
const sessionRestored = await sts.om.RestoreSession();
|
|
186
|
-
debug(`STSOAuth2Manager:#SetupRoute:Session restored: [${sessionRestored}]`);
|
|
187
|
-
if (sessionRestored !== true) {
|
|
188
|
-
debug(`STSOAuth2Manager:#SetupRoute:Session not restored - need to authorize`);
|
|
189
|
-
sts.om.Authorize();
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
return '/';
|
|
194
|
-
//router.replace({ path: '/' })
|
|
195
|
-
}
|
|
196
174
|
}
|
|
197
|
-
|
|
198
|
-
// Prevent pages if already logged in
|
|
199
|
-
if (to.path.localeCompare('/consent') === 0) {
|
|
200
|
-
return '/';
|
|
201
|
-
/*
|
|
202
|
-
router.replace({ path: '/' })
|
|
203
|
-
return false;
|
|
204
|
-
*/
|
|
205
|
-
}
|
|
206
|
-
if (to.path.localeCompare('/authorize') === 0) {
|
|
207
|
-
router.replace({ path: '/' });
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
if (to.path.localeCompare('/logout') === 0) {
|
|
211
|
-
router.replace({ path: '/' });
|
|
212
|
-
return false;
|
|
213
|
-
}
|
|
175
|
+
if (to.path.localeCompare('/logout') === 0) {
|
|
214
176
|
return true;
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
177
|
+
}
|
|
178
|
+
if (to.path.localeCompare('/error') === 0) {
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
if (to.path.localeCompare('/logout') === 0) {
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
const str = to.query;
|
|
185
|
+
// Check if this route is from a redirect from the authorization server
|
|
186
|
+
if (str[stsutils_1.OAuth2ParameterType.CODE] || str[stsutils_1.OAuth2ParameterType.ERROR]) {
|
|
187
|
+
debug(`STSOAuth2Manager:#SetupRoute:Processing redirect: [${str}]`);
|
|
188
|
+
const retVal = await sts.om.HandleRedirect(str);
|
|
189
|
+
debug(`STSOAuth2Manager:#SetupRoute:Redirect result: [${retVal}]`);
|
|
190
|
+
if (retVal) {
|
|
191
|
+
// Success
|
|
218
192
|
setTimeout(() => {
|
|
219
|
-
window.history.replaceState(
|
|
220
|
-
{},
|
|
221
|
-
document.title,
|
|
222
|
-
window.location.origin + '/');
|
|
193
|
+
window.history.replaceState({}, document.title, window.location.origin + '/');
|
|
223
194
|
}, 0);
|
|
224
195
|
return true;
|
|
225
196
|
}
|
|
226
|
-
|
|
197
|
+
else {
|
|
198
|
+
// Error
|
|
199
|
+
//@@ need the error data here - or use the vuex store ?
|
|
200
|
+
this.#router.replace('/error'); //@@ was push
|
|
201
|
+
//@@ should replaceState be used as in above?
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
227
204
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
return response.payload;
|
|
236
|
-
};
|
|
237
|
-
this.RestoreSession = async () => {
|
|
238
|
-
try {
|
|
239
|
-
debug(`STSOAuth2Manager:RestoreSession:postMessage: [${IOauth2ListenerCommand.RESTORE_SESSION}]`);
|
|
240
|
-
const response = await __classPrivateFieldGet(this, _STSOAuth2Manager_PostMessage, "f").call(this, { command: IOauth2ListenerCommand.RESTORE_SESSION });
|
|
241
|
-
debug(`STSOAuth2Manager:RestoreSession:response: [${JSON.stringify(response.payload)}]`);
|
|
242
|
-
return response.payload;
|
|
243
|
-
}
|
|
244
|
-
catch (error) {
|
|
245
|
-
console.log(`RestoreSession Error: ${error}`); //red
|
|
246
|
-
return false;
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
this.Authorize = async () => {
|
|
250
|
-
try {
|
|
251
|
-
const response = await __classPrivateFieldGet(this, _STSOAuth2Manager_PostMessage, "f").call(this, { command: IOauth2ListenerCommand.AUTHORIZE });
|
|
252
|
-
__classPrivateFieldGet(this, _STSOAuth2Manager_transactionStore, "f").set(__classPrivateFieldGet(this, _STSOAuth2Manager_STORAGE_AUTHORIZE_OPTIONS_KEY, "f"), response.payload.authorizeOptions);
|
|
253
|
-
const url = response.payload.url;
|
|
254
|
-
window.location.replace(url);
|
|
255
|
-
}
|
|
256
|
-
catch (error) {
|
|
257
|
-
console.log(`Authorize Error: ${error}`); // red
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
this.HandleRedirect = async (queryVars) => {
|
|
261
|
-
try {
|
|
262
|
-
let response = null;
|
|
263
|
-
if (queryVars[OAuth2ParameterType.CODE]) {
|
|
264
|
-
const authorizeOptions = __classPrivateFieldGet(this, _STSOAuth2Manager_transactionStore, "f").get(__classPrivateFieldGet(this, _STSOAuth2Manager_STORAGE_AUTHORIZE_OPTIONS_KEY, "f"));
|
|
265
|
-
__classPrivateFieldGet(this, _STSOAuth2Manager_transactionStore, "f").remove(__classPrivateFieldGet(this, _STSOAuth2Manager_STORAGE_AUTHORIZE_OPTIONS_KEY, "f"));
|
|
266
|
-
response = await __classPrivateFieldGet(this, _STSOAuth2Manager_PostMessage, "f").call(this, { command: IOauth2ListenerCommand.HANDLE_REDIRECT, payload: {
|
|
267
|
-
queryVars: queryVars,
|
|
268
|
-
authorizeOptions
|
|
269
|
-
} });
|
|
205
|
+
debug(`STSOAuth2Manager:#SetupRoute:Restoring session`);
|
|
206
|
+
const sessionRestored = await sts.om.RestoreSession();
|
|
207
|
+
debug(`STSOAuth2Manager:#SetupRoute:Session restored: [${sessionRestored}]`);
|
|
208
|
+
if (sessionRestored !== true) {
|
|
209
|
+
debug(`STSOAuth2Manager:#SetupRoute:Session not restored - need to authorize`);
|
|
210
|
+
sts.om.Authorize();
|
|
211
|
+
return false;
|
|
270
212
|
}
|
|
271
213
|
else {
|
|
272
|
-
|
|
214
|
+
return '/';
|
|
215
|
+
//router.replace({ path: '/' })
|
|
273
216
|
}
|
|
274
|
-
return response.payload;
|
|
275
|
-
}
|
|
276
|
-
catch (error) {
|
|
277
|
-
console.log(`HandleRedirect Error: ${error}`); // red
|
|
278
|
-
return false;
|
|
279
217
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
218
|
+
else {
|
|
219
|
+
// Prevent pages if already logged in
|
|
220
|
+
if (to.path.localeCompare('/consent') === 0) {
|
|
221
|
+
return '/';
|
|
222
|
+
/*
|
|
223
|
+
router.replace({ path: '/' })
|
|
224
|
+
return false;
|
|
225
|
+
*/
|
|
226
|
+
}
|
|
227
|
+
if (to.path.localeCompare('/authorize') === 0) {
|
|
228
|
+
router.replace({ path: '/' });
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
if (to.path.localeCompare('/logout') === 0) {
|
|
232
|
+
router.replace({ path: '/' });
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
return true;
|
|
236
|
+
/*
|
|
237
|
+
if (to.path.localeCompare('/') === 0) {
|
|
238
|
+
// In case press the back button in the browser shows previous query string params, replace them ...
|
|
239
|
+
setTimeout(() => {
|
|
240
|
+
window.history.replaceState(
|
|
241
|
+
{},
|
|
242
|
+
document.title,
|
|
243
|
+
window.location.origin + '/');
|
|
244
|
+
}, 0);
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
*/
|
|
289
248
|
}
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
//@@ this needs to be re-implemented so that access_token never leaves the auth worker
|
|
252
|
+
GetAccessToken = async () => {
|
|
253
|
+
const response = await this.#PostMessage({ command: stsoauth2types_1.IOauth2ListenerCommand.ACCESS_TOKEN });
|
|
254
|
+
return response.payload;
|
|
255
|
+
};
|
|
256
|
+
RestoreSession = async () => {
|
|
257
|
+
try {
|
|
258
|
+
debug(`STSOAuth2Manager:RestoreSession:postMessage: [${stsoauth2types_1.IOauth2ListenerCommand.RESTORE_SESSION}]`);
|
|
259
|
+
const response = await this.#PostMessage({ command: stsoauth2types_1.IOauth2ListenerCommand.RESTORE_SESSION });
|
|
260
|
+
debug(`STSOAuth2Manager:RestoreSession:response: [${JSON.stringify(response.payload)}]`);
|
|
261
|
+
return response.payload;
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
console.log(`RestoreSession Error: ${error}`); //red
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
Authorize = async () => {
|
|
269
|
+
try {
|
|
270
|
+
const response = await this.#PostMessage({ command: stsoauth2types_1.IOauth2ListenerCommand.AUTHORIZE });
|
|
271
|
+
this.#transactionStore.set(this.#STORAGE_AUTHORIZE_OPTIONS_KEY, response.payload.authorizeOptions);
|
|
272
|
+
const url = response.payload.url;
|
|
273
|
+
window.location.replace(url);
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
console.log(`Authorize Error: ${error}`); // red
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
HandleRedirect = async (queryVars) => {
|
|
280
|
+
try {
|
|
281
|
+
let response = null;
|
|
282
|
+
if (queryVars[stsutils_1.OAuth2ParameterType.CODE]) {
|
|
283
|
+
const authorizeOptions = this.#transactionStore.get(this.#STORAGE_AUTHORIZE_OPTIONS_KEY);
|
|
284
|
+
this.#transactionStore.remove(this.#STORAGE_AUTHORIZE_OPTIONS_KEY);
|
|
285
|
+
response = await this.#PostMessage({ command: stsoauth2types_1.IOauth2ListenerCommand.HANDLE_REDIRECT, payload: {
|
|
286
|
+
queryVars: queryVars,
|
|
287
|
+
authorizeOptions
|
|
288
|
+
} });
|
|
295
289
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
return null;
|
|
290
|
+
else {
|
|
291
|
+
response = await this.#PostMessage({ command: stsoauth2types_1.IOauth2ListenerCommand.HANDLE_REDIRECT, payload: queryVars });
|
|
299
292
|
}
|
|
300
|
-
|
|
301
|
-
__classPrivateFieldSet(this, _STSOAuth2Manager_options, options, "f");
|
|
302
|
-
__classPrivateFieldSet(this, _STSOAuth2Manager_storageManager, app.config.globalProperties.$sts.storage, "f");
|
|
303
|
-
__classPrivateFieldSet(this, _STSOAuth2Manager_aic, app.config.globalProperties.$sts.aic.PrimaryPublishInstrumentController, "f");
|
|
304
|
-
__classPrivateFieldSet(this, _STSOAuth2Manager_router, app.config.globalProperties.$router, "f");
|
|
305
|
-
if (!__classPrivateFieldGet(this, _STSOAuth2Manager_options, "f").workerOptions.nodeMode) {
|
|
306
|
-
__classPrivateFieldSet(this, _STSOAuth2Manager_stsOauth2Store, STSOauth2Store(), "f");
|
|
293
|
+
return response.payload;
|
|
307
294
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
__classPrivateFieldGet(this, _STSOAuth2Manager_worker, "f").onmessage = (data) => {
|
|
312
|
-
console.log(`this.#worker.onmessage = [${data}]`); // green
|
|
313
|
-
};
|
|
314
|
-
__classPrivateFieldGet(this, _STSOAuth2Manager_worker, "f").onerror = function (error) {
|
|
315
|
-
console.log(`this.#worker.onerror = [${JSON.stringify(error)}]`); // green
|
|
316
|
-
};
|
|
317
|
-
const { port1: oauth2ManagerPort, // this process port
|
|
318
|
-
port2: oauth2WorkerPort // worker port
|
|
319
|
-
} = new MessageChannel();
|
|
320
|
-
__classPrivateFieldSet(this, _STSOAuth2Manager_oauth2ManagerPort, oauth2ManagerPort, "f");
|
|
321
|
-
const workerMessage = {
|
|
322
|
-
workerPort: oauth2WorkerPort,
|
|
323
|
-
options: __classPrivateFieldGet(this, _STSOAuth2Manager_options, "f").workerOptions
|
|
324
|
-
};
|
|
325
|
-
__classPrivateFieldGet(this, _STSOAuth2Manager_worker, "f").postMessage(workerMessage, [oauth2WorkerPort]);
|
|
326
|
-
__classPrivateFieldGet(this, _STSOAuth2Manager_oauth2ManagerPort, "f").onmessage = (data) => {
|
|
327
|
-
__classPrivateFieldGet(this, _STSOAuth2Manager_ProcessMessageResponse, "f").call(this, data);
|
|
328
|
-
};
|
|
329
|
-
if (!__classPrivateFieldGet(this, _STSOAuth2Manager_options, "f").workerOptions.nodeMode) {
|
|
330
|
-
__classPrivateFieldGet(this, _STSOAuth2Manager_SetupRoute, "f").call(this, app, __classPrivateFieldGet(this, _STSOAuth2Manager_router, "f"));
|
|
295
|
+
catch (error) {
|
|
296
|
+
console.log(`HandleRedirect Error: ${error}`); // red
|
|
297
|
+
return false;
|
|
331
298
|
}
|
|
332
|
-
}
|
|
299
|
+
};
|
|
300
|
+
Logout = async () => {
|
|
301
|
+
try {
|
|
302
|
+
const response = await this.#PostMessage({ command: stsoauth2types_1.IOauth2ListenerCommand.LOGOUT });
|
|
303
|
+
return response.payload;
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
console.log(`Logout Error: ${error}`); // red
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
InvokeExternalAPI = async () => {
|
|
311
|
+
try {
|
|
312
|
+
const response = await this.#PostMessage({ command: stsoauth2types_1.IOauth2ListenerCommand.LOGOUT });
|
|
313
|
+
return response.payload;
|
|
314
|
+
}
|
|
315
|
+
catch (error) {
|
|
316
|
+
console.log(`InvokeExternalAPI Error: ${error}`); // red
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
};
|
|
333
320
|
}
|
|
334
|
-
|
|
321
|
+
exports.STSOAuth2Manager = STSOAuth2Manager;
|
|
335
322
|
//# sourceMappingURL=stsoauth2manager.js.map
|