@asgardeo/auth-spa 0.2.15 → 0.2.19

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.
Files changed (31) hide show
  1. package/dist/asgardeo-spa.production.esm.js +13 -13
  2. package/dist/asgardeo-spa.production.esm.js.map +1 -1
  3. package/dist/asgardeo-spa.production.js +13 -13
  4. package/dist/asgardeo-spa.production.js.map +1 -1
  5. package/dist/asgardeo-spa.production.min.js +1 -1
  6. package/dist/asgardeo-spa.production.min.js.map +1 -1
  7. package/dist/polyfilled/asgardeo-spa.production.esm.js +35 -35
  8. package/dist/polyfilled/asgardeo-spa.production.esm.js.map +1 -1
  9. package/dist/polyfilled/asgardeo-spa.production.js +35 -35
  10. package/dist/polyfilled/asgardeo-spa.production.js.map +1 -1
  11. package/dist/polyfilled/asgardeo-spa.production.min.js +1 -1
  12. package/dist/polyfilled/asgardeo-spa.production.min.js.map +1 -1
  13. package/dist/src/clients/main-thread-client.d.ts.map +1 -1
  14. package/dist/src/clients/main-thread-client.js +24 -17
  15. package/dist/src/clients/main-thread-client.js.map +1 -1
  16. package/dist/src/clients/web-worker-client.d.ts.map +1 -1
  17. package/dist/src/clients/web-worker-client.js +5 -1
  18. package/dist/src/clients/web-worker-client.js.map +1 -1
  19. package/dist/src/models/request-custom-grant.d.ts +25 -0
  20. package/dist/src/models/request-custom-grant.d.ts.map +1 -0
  21. package/dist/src/models/request-custom-grant.js +19 -0
  22. package/dist/src/models/request-custom-grant.js.map +1 -0
  23. package/dist/src/worker/worker-core.d.ts.map +1 -1
  24. package/dist/src/worker/worker-core.js +11 -13
  25. package/dist/src/worker/worker-core.js.map +1 -1
  26. package/dist/tsconfig.tsbuildinfo +1 -1
  27. package/package.json +2 -2
  28. package/src/clients/main-thread-client.ts +28 -19
  29. package/src/clients/web-worker-client.ts +8 -2
  30. package/src/models/request-custom-grant.ts +26 -0
  31. package/src/worker/worker-core.ts +12 -15
@@ -53,6 +53,7 @@ import {
53
53
  MainThreadClientInterface,
54
54
  Message
55
55
  } from "../models";
56
+ import { SPACustomGrantConfig } from "../models/request-custom-grant";
56
57
  import { LocalStore, MemoryStore, SessionStore } from "../stores";
57
58
  import { SPAUtils } from "../utils";
58
59
 
@@ -86,6 +87,8 @@ export const MainThreadClient = async (
86
87
  (sessionState: string) => _dataLayer.setSessionDataParameter(SESSION_STATE, sessionState ?? "")
87
88
  );
88
89
 
90
+ let _getSignOutURLFromSessionStorage: boolean = false;
91
+
89
92
  const _httpClient: HttpClientInstance = HttpClient.getInstance();
90
93
  let _isHttpHandlerEnabled: boolean = true;
91
94
  let _httpErrorCallback: (error: HttpError) => void | Promise<void>;
@@ -455,10 +458,13 @@ export const MainThreadClient = async (
455
458
  };
456
459
 
457
460
  const signOut = async (): Promise<boolean> => {
458
- if (await _authenticationClient.isAuthenticated()) {
461
+ if (await _authenticationClient.isAuthenticated() && !_getSignOutURLFromSessionStorage) {
459
462
  location.href = await _authenticationClient.signOut();
460
463
  } else {
461
464
  location.href = SPAUtils.getSignOutURL();
465
+ await _dataLayer.removeOIDCProviderMetaData();
466
+ await _dataLayer.removeTemporaryData();
467
+ await _dataLayer.removeSessionData();
462
468
  }
463
469
 
464
470
  _spaHelper.clearRefreshTokenTimeout();
@@ -468,7 +474,7 @@ export const MainThreadClient = async (
468
474
  return true;
469
475
  };
470
476
 
471
- const requestCustomGrant = async (config: CustomGrantConfig): Promise<BasicUserInfo | HttpResponse> => {
477
+ const requestCustomGrant = async (config: SPACustomGrantConfig): Promise<BasicUserInfo | HttpResponse> => {
472
478
  let useDefaultEndpoint = true;
473
479
  let matches = false;
474
480
  const clientConfig = await _dataLayer.getConfigData();
@@ -493,6 +499,10 @@ export const MainThreadClient = async (
493
499
  return _authenticationClient
494
500
  .requestCustomGrant(config)
495
501
  .then(async (response: HttpResponse | TokenResponse) => {
502
+ if (config.preventSignOutURLUpdate) {
503
+ _getSignOutURLFromSessionStorage = true;
504
+ }
505
+
496
506
  if (config.returnsSession) {
497
507
  _spaHelper.refreshAccessTokenAutomatically();
498
508
 
@@ -519,22 +529,19 @@ export const MainThreadClient = async (
519
529
  }
520
530
  };
521
531
 
522
- const refreshAccessToken = (): Promise<BasicUserInfo> => {
523
- return _authenticationClient
524
- .refreshAccessToken()
525
- .then(() => {
526
- getCustomGrantConfigData().then((customGrantConfig) => {
527
- if(customGrantConfig) {
528
- requestCustomGrant(customGrantConfig)
529
- }
530
- })
531
- _spaHelper.refreshAccessTokenAutomatically();
532
+ const refreshAccessToken = async (): Promise<BasicUserInfo> => {
533
+ try {
534
+ await _authenticationClient.refreshAccessToken();
535
+ const customGrantConfig = await getCustomGrantConfigData();
536
+ if (customGrantConfig) {
537
+ await requestCustomGrant(customGrantConfig);
538
+ }
539
+ _spaHelper.refreshAccessTokenAutomatically();
532
540
 
533
- return _authenticationClient.getBasicUserInfo();
534
- })
535
- .catch((error) => {
536
- return Promise.reject(error);
537
- });
541
+ return _authenticationClient.getBasicUserInfo();
542
+ } catch (error) {
543
+ return Promise.reject(error);
544
+ }
538
545
  };
539
546
 
540
547
  const revokeAccessToken = (): Promise<boolean> => {
@@ -564,9 +571,11 @@ export const MainThreadClient = async (
564
571
  return _authenticationClient
565
572
  .requestAccessToken(resolvedAuthorizationCode, resolvedSessionState)
566
573
  .then(async () => {
567
- if (config.storage === Storage.BrowserMemory) {
574
+ // Disable this temporarily
575
+ /* if (config.storage === Storage.BrowserMemory) {
568
576
  SPAUtils.setSignOutURL(await _authenticationClient.getSignOutURL());
569
- }
577
+ } */
578
+ SPAUtils.setSignOutURL(await _authenticationClient.getSignOutURL());
570
579
 
571
580
  _spaHelper.clearRefreshTokenTimeout();
572
581
  _spaHelper.refreshAccessTokenAutomatically();
@@ -76,6 +76,7 @@ import {
76
76
  WebWorkerClientConfig,
77
77
  WebWorkerClientInterface
78
78
  } from "../models";
79
+ import { SPACustomGrantConfig } from "../models/request-custom-grant";
79
80
  import { SPAUtils } from "../utils";
80
81
 
81
82
  export const WebWorkerClient = (config: AuthClientConfig<WebWorkerClientConfig>): WebWorkerClientInterface => {
@@ -88,6 +89,7 @@ export const WebWorkerClient = (config: AuthClientConfig<WebWorkerClientConfig>)
88
89
  */
89
90
  const _requestTimeout: number = config?.requestTimeout ?? 60000;
90
91
  let _isHttpHandlerEnabled: boolean = true;
92
+ let _getSignOutURLFromSessionStorage: boolean = false;
91
93
 
92
94
  const _sessionManagementHelper = SessionManagementHelper(
93
95
  async () => {
@@ -154,7 +156,7 @@ export const WebWorkerClient = (config: AuthClientConfig<WebWorkerClientConfig>)
154
156
  * @returns {Promise<HttpResponse|boolean>} A promise that resolves with a boolean value or the request
155
157
  * response if the the `returnResponse` attribute in the `requestParams` object is set to `true`.
156
158
  */
157
- const requestCustomGrant = (requestParams: CustomGrantConfig): Promise<HttpResponse | BasicUserInfo> => {
159
+ const requestCustomGrant = (requestParams: SPACustomGrantConfig): Promise<HttpResponse | BasicUserInfo> => {
158
160
  const message: Message<CustomGrantConfig> = {
159
161
  data: requestParams,
160
162
  type: REQUEST_CUSTOM_GRANT
@@ -162,6 +164,10 @@ export const WebWorkerClient = (config: AuthClientConfig<WebWorkerClientConfig>)
162
164
 
163
165
  return communicate<CustomGrantConfig, HttpResponse | BasicUserInfo>(message)
164
166
  .then((response) => {
167
+ if (requestParams.preventSignOutURLUpdate) {
168
+ _getSignOutURLFromSessionStorage = true;
169
+ }
170
+
165
171
  return Promise.resolve(response);
166
172
  })
167
173
  .catch((error) => {
@@ -596,7 +602,7 @@ export const WebWorkerClient = (config: AuthClientConfig<WebWorkerClientConfig>)
596
602
  const signOut = (): Promise<boolean> => {
597
603
  return isAuthenticated()
598
604
  .then(async (response: boolean) => {
599
- if (response) {
605
+ if (response && !_getSignOutURLFromSessionStorage) {
600
606
  const message: Message<null> = {
601
607
  type: SIGN_OUT
602
608
  };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com) All Rights Reserved.
3
+ *
4
+ * WSO2 Inc. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+
19
+ import { CustomGrantConfig } from "@asgardeo/auth-js";
20
+
21
+ /**
22
+ * SPA Custom Request Grant config model
23
+ */
24
+ export interface SPACustomGrantConfig extends CustomGrantConfig {
25
+ preventSignOutURLUpdate?: boolean;
26
+ }
@@ -356,22 +356,19 @@ export const WebWorkerCore = async (
356
356
  }
357
357
  };
358
358
 
359
- const refreshAccessToken = (): Promise<BasicUserInfo> => {
360
- return _authenticationClient
361
- .refreshAccessToken()
362
- .then(() => {
363
- getCustomGrantConfigData().then((customGrantConfig) => {
364
- if(customGrantConfig) {
365
- requestCustomGrant(customGrantConfig)
366
- }
367
- });
368
- _spaHelper.refreshAccessTokenAutomatically();
359
+ const refreshAccessToken = async (): Promise<BasicUserInfo> => {
360
+ try {
361
+ await _authenticationClient.refreshAccessToken();
362
+ const customGrantConfig = await getCustomGrantConfigData();
363
+ if (customGrantConfig) {
364
+ await requestCustomGrant(customGrantConfig);
365
+ }
366
+ _spaHelper.refreshAccessTokenAutomatically();
369
367
 
370
- return _authenticationClient.getBasicUserInfo();
371
- })
372
- .catch((error) => {
373
- return Promise.reject(error);
374
- });
368
+ return _authenticationClient.getBasicUserInfo();
369
+ } catch (error) {
370
+ return Promise.reject(error);
371
+ }
375
372
  };
376
373
 
377
374
  const revokeAccessToken = (): Promise<boolean> => {