@nsshunt/stsoauth2plugin 0.1.44 → 0.1.45

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/package-vite.json DELETED
@@ -1,58 +0,0 @@
1
- {
2
- "name": "@nsshunt/stsoauth2plugin",
3
- "files": [
4
- "dist",
5
- "types"
6
- ],
7
- "version": "0.1.38",
8
- "description": "STS OAuth2 VUE Plugin",
9
- "module": "./dist/stsoauth2plugin.es.js",
10
- "types": "./types/index.d.ts",
11
- "exports": {
12
- ".": {
13
- "import": "./dist/stsoauth2plugin.es.js"
14
- }
15
- },
16
- "scripts": {
17
- "lint": "eslint . --ext js,jsx,ts,tsx --fix",
18
- "test": "jest --detectOpenHandles --no-cache",
19
- "testwatch": "jest --watchAll --detectOpenHandles --no-cache",
20
- "build2": "tsc",
21
- "build": "tsc && vite build"
22
- },
23
- "repository": {
24
- "type": "git",
25
- "url": "git+https://github.com/nsshunt/stsoauth2plugin.git"
26
- },
27
- "author": "STS",
28
- "license": "MIT",
29
- "bugs": {
30
- "url": "https://github.com/nsshunt/stsoauth2plugin/issues"
31
- },
32
- "devDependencies": {
33
- "@babel/preset-env": "^7.18.2",
34
- "@babel/preset-typescript": "^7.17.12",
35
- "@tsconfig/node18": "^1.0.0",
36
- "@types/debug": "^4.1.7",
37
- "@types/jest": "^28.1.1",
38
- "@typescript-eslint/eslint-plugin": "^5.28.0",
39
- "@typescript-eslint/parser": "^5.28.0",
40
- "eslint": "^8.16.0",
41
- "jest": "^28.0.2",
42
- "prettier": "^2.7.1",
43
- "supertest": "^6.2.2",
44
- "ts-loader": "^9.3.0",
45
- "typescript": "^4.7.3"
46
- },
47
- "homepage": "https://github.com/nsshunt/stsoauth2plugin#readme",
48
- "dependencies": {
49
- "@nsshunt/stsinstrumentation": "^6.11.1",
50
- "@nsshunt/stsutils": "^1.15.1",
51
- "axios": "^0.27.2",
52
- "debug": "^4.3.4",
53
- "es-cookie": "^1.3.2",
54
- "http-status-codes": "^2.2.0",
55
- "jwt-decode": "^3.1.2",
56
- "vite": "^2.9.12"
57
- }
58
- }
@@ -1,32 +0,0 @@
1
- export class CryptoUtils {
2
- DigestMessage = async function (message) {
3
- const encoder = new TextEncoder();
4
- const data = encoder.encode(message);
5
- const hashBuffer = await crypto.subtle.digest('SHA-256', data);
6
- const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
7
- //let b64 = window.btoa(String.fromCharCode(...hashArray));
8
- const b64 = btoa(String.fromCharCode(...hashArray));// Use below if a HEX string is required
9
- // const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); // convert bytes to hex string
10
- return b64;
11
- }
12
-
13
- CreateRandomString = (size = 43) => {
14
- //const randomValues = Array.from(window.crypto.getRandomValues(new Uint8Array(size)))
15
- const randomValues = Array.from(crypto.getRandomValues(new Uint8Array(size)))
16
- //let b64 = window.btoa(String.fromCharCode(...randomValues));
17
- const b64 = btoa(String.fromCharCode(...randomValues));
18
- return b64;
19
- //return randomValues.toString('base64');
20
- }
21
-
22
- CreateRandomStringEx = () => {
23
- const charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~.';
24
- let random = '';
25
- //const randomValues = Array.from(window.crypto.getRandomValues(new Uint8Array(43)));
26
- const randomValues = Array.from(crypto.getRandomValues(new Uint8Array(43)));
27
- randomValues.forEach(v => (random += charset[v % charset.length]));
28
- return random;
29
- }
30
- }
31
-
32
- export default CryptoUtils
@@ -1,48 +0,0 @@
1
- // https://github.com/auth0/auth0-spa-js/blob/1de6427f81a8c5b005e9b6d10b9efb1e73542528/static/index.html
2
- // https://stackoverflow.com/questions/12446317/change-url-without-redirecting-using-javascript
3
- class QueryParams {
4
- DecodeQueryParams = (params) => {
5
- const retObj = { };
6
- const arr = Object.keys(params)
7
- .filter(k => typeof params[k] !== 'undefined')
8
- .map(k => {
9
- retObj[decodeURIComponent(k)] = decodeURIComponent(params[k]);
10
- });
11
- return retObj;
12
- }
13
-
14
- CreateQueryParams = (params) => {
15
- return Object.keys(params)
16
- .filter(k => typeof params[k] !== 'undefined')
17
- .map(k => {
18
- if (Array.isArray(params[k])) {
19
- return encodeURIComponent(k) + '=' + encodeURIComponent(params[k].join(' '))
20
- } else {
21
- return encodeURIComponent(k) + '=' + encodeURIComponent(params[k])
22
- }
23
- })
24
- .join('&');
25
- }
26
-
27
- _GetQueryParams = (param) => {
28
- let retVal = { };
29
- const uri = param.split("?");
30
- if (uri.length == 2) {
31
- const vars = uri[1].split("&");
32
- const getVars = {};
33
- let tmp = "";
34
- vars.forEach(function (v) {
35
- tmp = v.split("=");
36
- if (tmp.length == 2) getVars[tmp[0]] = tmp[1];
37
- });
38
- retVal = this.DecodeQueryParams(getVars);
39
- }
40
- return retVal;
41
- }
42
-
43
- GetQueryParams = () => {
44
- return this._GetQueryParams(window.location.href);
45
- }
46
- }
47
-
48
- export default QueryParams;
package/src/index.test.ts DELETED
@@ -1,10 +0,0 @@
1
-
2
- describe("Test Latency Controller", () =>
3
- {
4
- test('Testing Module', async () =>
5
- {
6
- expect.assertions(1);
7
- expect(1).toEqual(1);
8
- });
9
- });
10
-
package/src/index.ts DELETED
@@ -1,13 +0,0 @@
1
- import { STSOAuth2Manager } from './stsoauth2manager'
2
- import { ISTSOAuth2ManagerOptions } from './stsoauth2types'
3
-
4
- export * from './stsoauth2types'
5
- export * from './stsoauth2manager'
6
- export * from './stsoauth2worker'
7
-
8
- export const STSOAuth2ManagerPlugin = {
9
- install: (app, options: ISTSOAuth2ManagerOptions) => {
10
- const om = new STSOAuth2Manager(app, options);
11
- app.config.globalProperties.$sts.om = om;
12
- }
13
- }
package/src/stsStorage.ts DELETED
@@ -1,158 +0,0 @@
1
- import Debug from "debug";
2
- const debug = Debug(`proc:${process.pid}:storage.ts`);
3
-
4
- import * as Cookies from 'es-cookie';
5
- import { JSONObject } from "@nsshunt/stsutils";
6
-
7
- export interface IStsStorage<T> {
8
- get(key: string): T
9
- set(key: string, value: T, options?: JSONObject): void
10
- remove(key: string): void
11
- }
12
-
13
- export enum ClientStorageType {
14
- LOCAL_STORAGE = 'LocalStorage', //@@ todo
15
- SESSION_STORAGE = 'SessionStorage',
16
- COOKIE_STORAGE = 'CookieStorage',
17
- MEMORY_STORAGE = 'MemoryStorage' //@@ todo
18
- }
19
-
20
- class CookieStorage<T> implements IStsStorage<T>
21
- {
22
- get = (key: string): T => {
23
- const raw = Cookies.get(key);
24
- if (raw) {
25
- return JSON.parse(raw);
26
- } else {
27
- return null;
28
- }
29
- }
30
-
31
- set = (key: string, value: T, options: JSONObject = { }) => {
32
- let cookieAttributes: Cookies.CookieAttributes = { };
33
- if ('https:' === window.location.protocol) {
34
- cookieAttributes = {
35
- secure: true,
36
- sameSite: 'none'
37
- };
38
- }
39
-
40
- if (options && options.daysUntilExpire) {
41
- cookieAttributes.expires = options.daysUntilExpire;
42
- } else {
43
- cookieAttributes.expires = 1;
44
- }
45
- debug(`CookieStorage.set: key: ${key}, value: [${value}]`);
46
- Cookies.set(key, JSON.stringify(value), cookieAttributes);
47
- }
48
-
49
- remove = (key: string): void => {
50
- Cookies.remove(key);
51
- }
52
- }
53
-
54
- class SessionStorage<T> implements IStsStorage<T>
55
- {
56
- get = (key: string): T => {
57
- const value: string = sessionStorage.getItem(key);
58
- if (typeof value === 'undefined') {
59
- return null;
60
- }
61
- if (value === null) {
62
- return null;
63
- }
64
- return JSON.parse(value);
65
- }
66
-
67
- set = (key: string, value: T): void => {
68
- debug(`SessionStorage.set: key: ${key}, value: [${value}]`);
69
- sessionStorage.setItem(key, JSON.stringify(value));
70
- }
71
-
72
- remove = (key: string): void => {
73
- sessionStorage.removeItem(key);
74
- }
75
- }
76
-
77
- class LocalStorage<T> implements IStsStorage<T>
78
- {
79
- get = (key: string): T => {
80
- const value: string = localStorage.getItem(key);
81
- if (typeof value === 'undefined') {
82
- return null;
83
- }
84
- if (value === null) {
85
- return null;
86
- }
87
- return JSON.parse(value);
88
- }
89
-
90
- set = (key: string, value: T): void => {
91
- debug(`LocalStorage.set: key: ${key}, value: [${value}]`);
92
- localStorage.setItem(key, JSON.stringify(value));
93
- }
94
-
95
- remove = (key: string): void => {
96
- localStorage.removeItem(key);
97
- }
98
- }
99
-
100
- class MemoryStorage<T> implements IStsStorage<T>
101
- {
102
- #store: Record<string, T> = { };
103
-
104
- get = (key: string): T => {
105
- const value: T = this.#store[key];
106
- if (typeof value === 'undefined') {
107
- return null;
108
- }
109
- if (value === null) {
110
- return null;
111
- }
112
- return value;
113
- }
114
-
115
- set = (key: string, value: T): void => {
116
- debug(`MemoryStorage.set: key: ${key}, value: [${value}]`);
117
- this.#store[key] = value;
118
- }
119
-
120
- remove = (key: string): void => {
121
- delete this.#store[key];
122
- }
123
- }
124
-
125
- export class ClientStorageOptions {
126
- clientStorageType: ClientStorageType = ClientStorageType.MEMORY_STORAGE;
127
- storageOptions?: JSONObject
128
- }
129
-
130
- export class ClientStorageFactory<T>
131
- {
132
- #storage = null;
133
-
134
- constructor(options: ClientStorageOptions) {
135
- switch (options.clientStorageType) {
136
- case ClientStorageType.SESSION_STORAGE :
137
- this.#storage = new SessionStorage<T>();
138
- break;
139
- case ClientStorageType.LOCAL_STORAGE :
140
- this.#storage = new LocalStorage<T>();
141
- break;
142
- case ClientStorageType.COOKIE_STORAGE :
143
- this.#storage = new CookieStorage<T>();
144
- break;
145
- case ClientStorageType.MEMORY_STORAGE :
146
- this.#storage = new MemoryStorage<T>();
147
- break;
148
- default:
149
- throw new Error(`Unknown [${options.clientStorageType}] storage type.`);
150
- }
151
- return;
152
- }
153
-
154
- GetStorage(): IStsStorage<T>
155
- {
156
- return this.#storage;
157
- }
158
- }
@@ -1,377 +0,0 @@
1
- import Debug from "debug";
2
- const debug = Debug(`proc:${process.pid}:stsoauth2manager.ts`);
3
-
4
- import { JSONObject, OAuth2ParameterType } from '@nsshunt/stsutils';
5
-
6
- import CryptoUtils from './Utils/CryptoUtils'
7
- import QueryParams from './Utils/QueryParams';
8
-
9
- import { IAuthorizeOptions, IAuthorizeResponse, IAuthorizeErrorResponse, AuthenticateEvent,
10
- ISTSOAuth2ManagerOptions, IOauth2ListenerMessage, IOauth2ListenerMessageResponse,
11
- IOauth2ListenerCommand, ISTSOAuth2WorkerMessage } from './stsoauth2types'
12
-
13
- import { IStsStorage, ClientStorageType, ClientStorageFactory } from './stsStorage'
14
-
15
- import { Gauge, InstrumentBaseTelemetry } from '@nsshunt/stsinstrumentation'
16
-
17
- //import createPersistedState from "vuex-persistedstate"; // https://www.npmjs.com/package/vuex-persistedstate
18
- import jwt_decode from "jwt-decode";
19
- //import { transformWithEsbuild } from "vite";
20
-
21
- // STS Client SDK for SPAs
22
- export class STSOAuth2Manager {
23
- #storageManager = null;
24
- #router: any = null;
25
- #store = null;
26
- #cUtils = new CryptoUtils();
27
- #qParams = new QueryParams();
28
- #STORAGE_AUTHORIZE_OPTIONS_KEY = 'authorize_options.stsmda.com.au';
29
- #STORAGE_SESSION_KEY = 'session.stsmda.com.au';
30
- #aic = null;
31
- #options: ISTSOAuth2ManagerOptions = null;
32
- #messages: Record<number, IOauth2ListenerMessage> = { };
33
- #oauth2ManagerPort: MessagePort;
34
- #messageId = 0;
35
- #messageHandlers: Record<number, any> = { }; // keyed by messageId
36
- #messageTimeout = 1000;
37
- #worker: Worker = null;
38
- #transactionStore: IStsStorage<IAuthorizeOptions> = null; // Transient transaction data used to establish a session via OAuth2 authorize handshake
39
-
40
- constructor(app, options: ISTSOAuth2ManagerOptions) {
41
- this.#options = options;
42
- this.#storageManager = app.config.globalProperties.$sts.storage;
43
- this.#store = app.config.globalProperties.$store;
44
- this.#aic = app.config.globalProperties.$sts.aic.PrimaryPublishInstrumentController;
45
- this.#router = app.config.globalProperties.$router;
46
-
47
- // Use session storage for the transient nature of the OAuth2 authorize handshake. Once completed, the storage will be removed.
48
- this.#transactionStore = new ClientStorageFactory<IAuthorizeOptions>({clientStorageType: ClientStorageType.SESSION_STORAGE}).GetStorage();
49
-
50
- /*
51
- if (this.#options.workerFactory) {
52
- this.#worker = this.#options.workerFactory();
53
- } else {
54
- this.#worker = new Worker(new URL('./stsoauth2worker.ts', import.meta.url), {
55
- type: 'module'
56
- });
57
- }
58
- */
59
-
60
- this.#worker = this.#options.workerFactory();
61
-
62
- this.#worker.onmessage = (data: MessageEvent) => {
63
- console.log(`this.#worker.onmessage = [${data}]`); // green
64
- };
65
-
66
- this.#worker.onerror = function(error) {
67
- console.log(`this.#worker.onerror = [${JSON.stringify(error)}]`); // green
68
- };
69
-
70
- const {
71
- port1: oauth2ManagerPort, // process message port
72
- port2: oauth2WorkerPort // collector message port
73
- } = new MessageChannel();
74
- this.#oauth2ManagerPort = oauth2ManagerPort;
75
-
76
- const workerMessage: ISTSOAuth2WorkerMessage = {
77
- workerPort: oauth2WorkerPort,
78
- options: this.#options.workerOptions
79
- }
80
-
81
- this.#worker.postMessage(workerMessage, [ oauth2WorkerPort ]);
82
-
83
- this.#oauth2ManagerPort.onmessage = (data: MessageEvent) => {
84
- this.#ProcessMessageResponse(data);
85
- }
86
-
87
- this.#SetupStoreNamespace();
88
- this.#SetupRoute(app, this.#router);
89
- }
90
-
91
- #ProcessMessageResponse = (data: MessageEvent) => {
92
- const messageResponse: IOauth2ListenerMessageResponse = data.data as IOauth2ListenerMessageResponse;
93
- if (messageResponse.messageId === -1) {
94
- // unsolicted message
95
- switch (messageResponse.command) {
96
- case IOauth2ListenerCommand.AUTHENTICATE_EVENT :
97
- this.#HandleAuthenticateEvent(messageResponse.payload as string);
98
- break;
99
- case IOauth2ListenerCommand.ERROR :
100
- this.#HandleErrorEvent(messageResponse.payload as JSONObject);
101
- break;
102
- case IOauth2ListenerCommand.LOG :
103
- this.#HandleLogEvent(messageResponse.payload as string);
104
- break;
105
- case IOauth2ListenerCommand.UPDATE_INSTRUMENT :
106
- this.#HandleUpdateInstrumentEvent(messageResponse.payload.instrumentName, messageResponse.payload.telemetry);
107
- break;
108
- default :
109
- throw new Error(`ProcessMessageResponse command [${messageResponse.command}] not valid.`);
110
- }
111
- } else {
112
- const callBack = this.#messageHandlers[messageResponse.messageId];
113
- if (callBack) {
114
- callBack(messageResponse);
115
- } else {
116
- throw new Error(`Message: [${messageResponse.messageId}] does not exists in callBacks.`);
117
- }
118
- }
119
- }
120
-
121
- #PostMessage = (message: IOauth2ListenerMessage): Promise<IOauth2ListenerMessageResponse> => {
122
- message.messageId = this.#messageId++;
123
-
124
- return new Promise<IOauth2ListenerMessageResponse>((resolve, reject) => {
125
- // Setup message timeout
126
- const timeout: NodeJS.Timeout = setTimeout(() => {
127
- delete this.#messageHandlers[message.messageId];
128
- reject(`Message: [${message.messageId}] timeout error after: [${this.#messageTimeout}] ms.`);
129
- }, this.#messageTimeout);
130
-
131
- // Setup message callback based on messageId
132
- this.#messageHandlers[message.messageId] = (response: IOauth2ListenerMessageResponse) => {
133
- clearTimeout(timeout);
134
- delete this.#messageHandlers[message.messageId];
135
- resolve(response);
136
- }
137
-
138
- // Send the message
139
- this.#oauth2ManagerPort.postMessage(message);
140
- });
141
- }
142
-
143
- #HandleLogEvent = (message: string): void => {
144
- if (this.#aic) {
145
- this.#aic.LogEx(message);
146
- }
147
- debug(message);
148
- }
149
-
150
- // UpdateInstrument = (instrumentName: Gauge, telemetry: InstrumentBaseTelemetry): void => {
151
- #HandleUpdateInstrumentEvent = (instrumentName: Gauge, telemetry: InstrumentBaseTelemetry): void => {
152
- if (this.#aic) {
153
- this.#aic.UpdateInstrument(instrumentName, telemetry);
154
- }
155
- }
156
-
157
- // Will come from message channel
158
- #HandleErrorEvent = (error: JSONObject): void => {
159
- this.#store.commit('AuthorizeError', {
160
- message: error
161
- });
162
- // plugin to do this ...
163
- setTimeout(() => {
164
- this.#router.replace('/error'); //@@ was push
165
- }, 0);
166
- }
167
-
168
- #HandleAuthenticateEvent: AuthenticateEvent = (id_token: string): void => {
169
- if (this.#options.authenticateEvent) {
170
- this.#options.authenticateEvent(id_token);
171
- }
172
- this.#store.commit('stsOAuth2SDK/SessionData', id_token);
173
- }
174
-
175
- #SetupRoute = (app, router) => {
176
- router.beforeEach(async (to, from) => {
177
- const store = app.config.globalProperties.$store;
178
- const sts = app.config.globalProperties.$sts;
179
-
180
- debug(`beforeEach: from: [${from.path}], to: [${to.path}]`); // gray
181
- if (store.getters['stsOAuth2SDK/LoggedIn'] === false) {
182
- console.log(`Not logged in`);
183
- // Not logged in
184
- if (to.path.localeCompare('/authorize') === 0) {
185
- console.log(`to = /authorize`);
186
- return true;
187
- } else if (to.path.localeCompare('/consent') === 0) {
188
- // Need to check if we are in the correct state, if not - drop back to the start of the process
189
- if (typeof store.getters.Session.sessionId !== 'undefined') {
190
- return true;
191
- }
192
- }
193
- if (to.path.localeCompare('/logout') === 0) {
194
- return true;
195
- }
196
- if (to.path.localeCompare('/error') === 0) {
197
- return true;
198
- }
199
- if (to.path.localeCompare('/logout') === 0) {
200
- return true;
201
- }
202
-
203
- const str = to.query;
204
- // Check if this route is from a redirect from the authorization server
205
- if (str[OAuth2ParameterType.CODE] || str[OAuth2ParameterType.ERROR]) {
206
-
207
- console.log(`#SetupRout:str = [${str}]`);
208
-
209
- const retVal: boolean = await sts.om.HandleRedirect(str);
210
- if (retVal) {
211
- // Success
212
- setTimeout(() => {
213
- window.history.replaceState(
214
- {},
215
- document.title,
216
- window.location.origin + '/');
217
- }, 0);
218
- return true;
219
- } else {
220
- // Error
221
- //@@ need the error data here - or use the vuex store ?
222
- this.#router.replace('/error'); //@@ was push
223
-
224
- //@@ should replaceState be used as in above?
225
- return false;
226
- }
227
- }
228
-
229
- const sessionRestored = await sts.om.RestoreSession();
230
- console.log(`#SetupRoute:sessionRestored [${sessionRestored}]`);
231
-
232
- if (sessionRestored !== true) {
233
- console.log('Session not restored - Need to Authorize');
234
- sts.om.Authorize();
235
- return false;
236
- } else {
237
- return '/';
238
- //router.replace({ path: '/' })
239
- }
240
- } else {
241
- // Prevent pages if already logged in
242
- if (to.path.localeCompare('/consent') === 0) {
243
- return '/';
244
- /*
245
- router.replace({ path: '/' })
246
- return false;
247
- */
248
- }
249
- if (to.path.localeCompare('/authorize') === 0) {
250
- router.replace({ path: '/' })
251
- return false;
252
- }
253
- if (to.path.localeCompare('/logout') === 0) {
254
- router.replace({ path: '/' })
255
- return false;
256
- }
257
- return true;
258
-
259
- /*
260
- if (to.path.localeCompare('/') === 0) {
261
- // In case press the back button in the browser shows previous query string params, replace them ...
262
- setTimeout(() => {
263
- window.history.replaceState(
264
- {},
265
- document.title,
266
- window.location.origin + '/');
267
- }, 0);
268
- return true;
269
- }
270
- */
271
- }
272
- })
273
- }
274
-
275
- // Replace with pinia
276
- // https://pinia.vuejs.org/
277
- // https://seb-l.github.io/pinia-plugin-persist/
278
- #SetupStoreNamespace = () => {
279
- this.#store.registerModule('stsOAuth2SDK', {
280
- namespaced: true,
281
-
282
- state () {
283
- return {
284
- // STS Client SDK options. These are parameters initiated by the client SPA and used for the end-to-end transaction processing.
285
- //authorizeOptions: { },
286
-
287
- sessionData: { },
288
- }
289
- },
290
-
291
- getters: {
292
- SessionData (state) {
293
- return state.sessionData;
294
- },
295
- LoggedIn (state) {
296
- if (typeof state.sessionData === 'undefined') {
297
- return false;
298
- }
299
- if (state.sessionData === null) {
300
- return false;
301
- }
302
- return true;
303
- },
304
- UserDetails (state) {
305
- //if (state.sessionData && state.sessionData.id_token) {
306
- if (state.sessionData) {
307
- const id_token = state.sessionData;
308
- const decodedIdToken = jwt_decode(id_token);
309
- return decodedIdToken;
310
- } else {
311
- return null;
312
- }
313
- }
314
- },
315
-
316
- mutations: {
317
- SessionData (state, sessionData) {
318
- state.sessionData = sessionData;
319
- console.log(`commit [sessionData]: ${JSON.stringify(sessionData)}`)
320
- },
321
- }
322
- }, { preserveState: true });
323
- }
324
-
325
- RestoreSession = async(): Promise<boolean> => {
326
- try {
327
- const response: IOauth2ListenerMessageResponse = await this.#PostMessage({ command: IOauth2ListenerCommand.RESTORE_SESSION });
328
- return response.payload;
329
- } catch (error) {
330
- console.log(`RestoreSession Error: ${error}`); //red
331
- return false;
332
- }
333
- }
334
-
335
- Authorize = async (): Promise<void> => {
336
- try {
337
- const response: IOauth2ListenerMessageResponse = await this.#PostMessage({ command: IOauth2ListenerCommand.AUTHORIZE });
338
- this.#transactionStore.set(this.#STORAGE_AUTHORIZE_OPTIONS_KEY, response.payload.authorizeOptions);
339
- const url = response.payload.url;
340
- window.location.replace(url);
341
- } catch (error) {
342
- console.log(`Authorize Error: ${error}`); // red
343
- }
344
- }
345
-
346
- HandleRedirect = async (queryVars: JSONObject): Promise<boolean> => {
347
- try {
348
- let response: IOauth2ListenerMessageResponse = null;
349
- if (queryVars[OAuth2ParameterType.CODE]) {
350
-
351
- const authorizeOptions: IAuthorizeOptions = this.#transactionStore.get(this.#STORAGE_AUTHORIZE_OPTIONS_KEY) as IAuthorizeOptions;
352
- this.#transactionStore.remove(this.#STORAGE_AUTHORIZE_OPTIONS_KEY);
353
-
354
- response = await this.#PostMessage({ command: IOauth2ListenerCommand.HANDLE_REDIRECT, payload: {
355
- queryVars: queryVars as IAuthorizeResponse,
356
- authorizeOptions
357
- }});
358
- } else {
359
- response = await this.#PostMessage({ command: IOauth2ListenerCommand.HANDLE_REDIRECT, payload: queryVars as IAuthorizeErrorResponse });
360
- }
361
- return response.payload;
362
- } catch (error) {
363
- console.log(`HandleRedirect Error: ${error}`); // red
364
- return false;
365
- }
366
- }
367
-
368
- Logout = async (): Promise<boolean> => {
369
- try {
370
- const response: IOauth2ListenerMessageResponse = await this.#PostMessage({ command: IOauth2ListenerCommand.LOGOUT });
371
- return response.payload;
372
- } catch (error) {
373
- console.log(`Logout Error: ${error}`); // red
374
- return false;
375
- }
376
- }
377
- }