@axa-fr/react-oidc 6.9.7 → 6.10.1

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 (146) hide show
  1. package/README.md +102 -102
  2. package/dist/FetchToken.d.ts.map +1 -1
  3. package/dist/FetchToken.js +2 -2
  4. package/dist/FetchToken.js.map +1 -1
  5. package/dist/OidcProvider.d.ts +7 -6
  6. package/dist/OidcProvider.d.ts.map +1 -1
  7. package/dist/OidcProvider.js +30 -26
  8. package/dist/OidcProvider.js.map +1 -1
  9. package/dist/OidcSecure.d.ts +2 -2
  10. package/dist/OidcSecure.d.ts.map +1 -1
  11. package/dist/OidcSecure.js +2 -4
  12. package/dist/OidcSecure.js.map +1 -1
  13. package/dist/OidcServiceWorker.js +150 -144
  14. package/dist/OidcTrustedDomains.js +9 -10
  15. package/dist/ReactOidc.d.ts +1 -1
  16. package/dist/ReactOidc.d.ts.map +1 -1
  17. package/dist/ReactOidc.js +22 -16
  18. package/dist/ReactOidc.js.map +1 -1
  19. package/dist/User.d.ts.map +1 -1
  20. package/dist/User.js +1 -1
  21. package/dist/User.js.map +1 -1
  22. package/dist/core/default-component/AuthenticateError.component.d.ts +1 -1
  23. package/dist/core/default-component/AuthenticateError.component.d.ts.map +1 -1
  24. package/dist/core/default-component/Authenticating.component.d.ts +1 -1
  25. package/dist/core/default-component/Authenticating.component.d.ts.map +1 -1
  26. package/dist/core/default-component/Callback.component.d.ts.map +1 -1
  27. package/dist/core/default-component/Callback.component.js +5 -5
  28. package/dist/core/default-component/Callback.component.js.map +1 -1
  29. package/dist/core/default-component/Loading.component.d.ts +1 -1
  30. package/dist/core/default-component/Loading.component.d.ts.map +1 -1
  31. package/dist/core/default-component/ServiceWorkerNotSupported.component.d.ts +1 -1
  32. package/dist/core/default-component/ServiceWorkerNotSupported.component.d.ts.map +1 -1
  33. package/dist/core/default-component/SessionLost.component.d.ts.map +1 -1
  34. package/dist/core/default-component/SilentCallback.component.d.ts.map +1 -1
  35. package/dist/core/default-component/SilentCallback.component.js +1 -0
  36. package/dist/core/default-component/SilentCallback.component.js.map +1 -1
  37. package/dist/core/default-component/SilentLogin.component.d.ts.map +1 -1
  38. package/dist/core/default-component/SilentLogin.component.js +5 -7
  39. package/dist/core/default-component/SilentLogin.component.js.map +1 -1
  40. package/dist/core/default-component/index.d.ts +2 -2
  41. package/dist/core/default-component/index.d.ts.map +1 -1
  42. package/dist/core/default-component/index.js +5 -5
  43. package/dist/core/default-component/index.js.map +1 -1
  44. package/dist/core/routes/OidcRoutes.d.ts +1 -1
  45. package/dist/core/routes/OidcRoutes.d.ts.map +1 -1
  46. package/dist/core/routes/OidcRoutes.js +1 -1
  47. package/dist/core/routes/OidcRoutes.js.map +1 -1
  48. package/dist/core/routes/withRouter.d.ts.map +1 -1
  49. package/dist/core/routes/withRouter.js.map +1 -1
  50. package/dist/index.d.ts +7 -6
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +10 -10
  53. package/dist/index.js.map +1 -1
  54. package/dist/vanilla/checkSessionIFrame.d.ts.map +1 -1
  55. package/dist/vanilla/checkSessionIFrame.js +15 -15
  56. package/dist/vanilla/checkSessionIFrame.js.map +1 -1
  57. package/dist/vanilla/initSession.d.ts.map +1 -1
  58. package/dist/vanilla/initSession.js +1 -1
  59. package/dist/vanilla/initSession.js.map +1 -1
  60. package/dist/vanilla/initWorker.d.ts +1 -1
  61. package/dist/vanilla/initWorker.d.ts.map +1 -1
  62. package/dist/vanilla/initWorker.js +22 -20
  63. package/dist/vanilla/initWorker.js.map +1 -1
  64. package/dist/vanilla/memoryStorageBackend.d.ts +5 -4
  65. package/dist/vanilla/memoryStorageBackend.d.ts.map +1 -1
  66. package/dist/vanilla/memoryStorageBackend.js.map +1 -1
  67. package/dist/vanilla/noHashQueryStringUtils.d.ts +3 -3
  68. package/dist/vanilla/noHashQueryStringUtils.d.ts.map +1 -1
  69. package/dist/vanilla/noHashQueryStringUtils.js +4 -4
  70. package/dist/vanilla/noHashQueryStringUtils.js.map +1 -1
  71. package/dist/vanilla/oidc.d.ts +6 -6
  72. package/dist/vanilla/oidc.d.ts.map +1 -1
  73. package/dist/vanilla/oidc.js +215 -216
  74. package/dist/vanilla/oidc.js.map +1 -1
  75. package/dist/vanilla/parseTokens.d.ts +2 -2
  76. package/dist/vanilla/parseTokens.d.ts.map +1 -1
  77. package/dist/vanilla/parseTokens.js +8 -8
  78. package/dist/vanilla/parseTokens.js.map +1 -1
  79. package/dist/vanilla/route-utils.d.ts.map +1 -1
  80. package/dist/vanilla/route-utils.js +10 -7
  81. package/dist/vanilla/route-utils.js.map +1 -1
  82. package/dist/vanilla/timer.d.ts.map +1 -1
  83. package/dist/vanilla/timer.js +8 -8
  84. package/dist/vanilla/timer.js.map +1 -1
  85. package/dist/vanilla/vanillaOidc.d.ts +6 -4
  86. package/dist/vanilla/vanillaOidc.d.ts.map +1 -1
  87. package/dist/vanilla/vanillaOidc.js +4 -5
  88. package/dist/vanilla/vanillaOidc.js.map +1 -1
  89. package/package.json +15 -6
  90. package/src/oidc/FetchToken.tsx +10 -11
  91. package/src/oidc/OidcProvider.tsx +82 -83
  92. package/src/oidc/OidcSecure.tsx +16 -18
  93. package/src/oidc/ReactOidc.tsx +74 -63
  94. package/src/oidc/User.ts +14 -13
  95. package/src/oidc/core/default-component/AuthenticateError.component.tsx +1 -1
  96. package/src/oidc/core/default-component/Authenticating.component.tsx +1 -1
  97. package/src/oidc/core/default-component/Callback.component.tsx +18 -18
  98. package/src/oidc/core/default-component/Loading.component.tsx +1 -1
  99. package/src/oidc/core/default-component/ServiceWorkerNotSupported.component.tsx +1 -1
  100. package/src/oidc/core/default-component/SessionLost.component.tsx +1 -1
  101. package/src/oidc/core/default-component/SilentCallback.component.tsx +7 -6
  102. package/src/oidc/core/default-component/SilentLogin.component.tsx +16 -18
  103. package/src/oidc/core/default-component/index.ts +2 -2
  104. package/src/oidc/core/routes/OidcRoutes.tsx +16 -15
  105. package/src/oidc/core/routes/withRouter.tsx +2 -4
  106. package/src/oidc/index.ts +7 -6
  107. package/src/oidc/vanilla/OidcServiceWorker.js +150 -144
  108. package/src/oidc/vanilla/OidcTrustedDomains.js +9 -10
  109. package/src/oidc/vanilla/checkSessionIFrame.ts +24 -23
  110. package/src/oidc/vanilla/index.ts +2 -1
  111. package/src/oidc/vanilla/initSession.ts +36 -37
  112. package/src/oidc/vanilla/initWorker.ts +82 -83
  113. package/src/oidc/vanilla/memoryStorageBackend.ts +13 -6
  114. package/src/oidc/vanilla/noHashQueryStringUtils.ts +13 -13
  115. package/src/oidc/vanilla/oidc.ts +460 -467
  116. package/src/oidc/vanilla/parseTokens.ts +73 -79
  117. package/src/oidc/vanilla/route-utils.ts +18 -18
  118. package/src/oidc/vanilla/timer.ts +14 -16
  119. package/src/oidc/vanilla/vanillaOidc.ts +35 -19
  120. package/src/override/AuthenticateError.component.tsx +4 -3
  121. package/src/override/Authenticating.component.tsx +4 -3
  122. package/src/override/Callback.component.tsx +4 -3
  123. package/src/override/Loading.component.tsx +4 -6
  124. package/src/override/ServiceWorkerNotSupported.component.tsx +5 -5
  125. package/src/override/SessionLost.component.tsx +8 -7
  126. package/src/override/style.ts +12 -10
  127. package/dist/core/routes/index.d.ts +0 -3
  128. package/dist/core/routes/index.d.ts.map +0 -1
  129. package/dist/core/routes/index.js +0 -9
  130. package/dist/core/routes/index.js.map +0 -1
  131. package/dist/vanilla/index.d.ts +0 -2
  132. package/dist/vanilla/index.d.ts.map +0 -1
  133. package/dist/vanilla/index.js +0 -6
  134. package/dist/vanilla/index.js.map +0 -1
  135. package/src/App.css +0 -38
  136. package/src/App.specold.tsx +0 -46
  137. package/src/App.tsx +0 -103
  138. package/src/FetchUser.tsx +0 -53
  139. package/src/Home.tsx +0 -23
  140. package/src/MultiAuth.tsx +0 -129
  141. package/src/Profile.tsx +0 -81
  142. package/src/configurations.ts +0 -73
  143. package/src/index.css +0 -13
  144. package/src/index.tsx +0 -9
  145. package/src/logo.svg +0 -7
  146. package/src/setupTests.js +0 -5
@@ -1,4 +1,4 @@
1
- const DefaultInterval = 2000;
1
+ const DefaultInterval = 2000;
2
2
 
3
3
  const Log = console;
4
4
 
@@ -12,18 +12,18 @@ export class CheckSessionIFrame {
12
12
  private readonly _frame: HTMLIFrameElement;
13
13
  private _boundMessageEvent: any;
14
14
  private _timer: number;
15
- constructor(callback, client_id, url, interval=DefaultInterval, stopOnError = true) {
15
+ constructor(callback, client_id, url, interval = DefaultInterval, stopOnError = true) {
16
16
  this._callback = callback;
17
17
  this._client_id = client_id;
18
18
  this._url = url;
19
19
  this._interval = interval || DefaultInterval;
20
20
  this._stopOnError = stopOnError;
21
- const idx = url.indexOf("/", url.indexOf("//") + 2);
21
+ const idx = url.indexOf('/', url.indexOf('//') + 2);
22
22
  this._frame_origin = url.substr(0, idx);
23
- this._frame = window.document.createElement("iframe");
24
- this._frame.style.visibility = "hidden";
25
- this._frame.style.position = "absolute";
26
- this._frame.style.display = "none";
23
+ this._frame = window.document.createElement('iframe');
24
+ this._frame.style.visibility = 'hidden';
25
+ this._frame.style.position = 'absolute';
26
+ this._frame.style.display = 'none';
27
27
  // @ts-ignore
28
28
  this._frame.width = 0;
29
29
  // @ts-ignore
@@ -31,42 +31,43 @@ export class CheckSessionIFrame {
31
31
 
32
32
  this._frame.src = url;
33
33
  }
34
+
34
35
  load() {
35
36
  return new Promise<void>((resolve) => {
36
37
  this._frame.onload = () => {
37
38
  resolve();
38
- }
39
+ };
39
40
  window.document.body.appendChild(this._frame);
40
41
  this._boundMessageEvent = this._message.bind(this);
41
- window.addEventListener("message", this._boundMessageEvent, false);
42
+ window.addEventListener('message', this._boundMessageEvent, false);
42
43
  });
43
44
  }
45
+
44
46
  _message(e) {
45
47
  if (e.origin === this._frame_origin &&
46
48
  e.source === this._frame.contentWindow
47
49
  ) {
48
- if (e.data === "error") {
49
- Log.error("CheckSessionIFrame: error message from check session op iframe");
50
+ if (e.data === 'error') {
51
+ Log.error('CheckSessionIFrame: error message from check session op iframe');
50
52
  if (this._stopOnError) {
51
53
  this.stop();
52
54
  }
53
- }
54
- else if (e.data === "changed") {
55
- Log.debug(e)
56
- Log.debug("CheckSessionIFrame: changed message from check session op iframe");
55
+ } else if (e.data === 'changed') {
56
+ Log.debug(e);
57
+ Log.debug('CheckSessionIFrame: changed message from check session op iframe');
57
58
  this.stop();
58
59
  this._callback();
59
- }
60
- else {
61
- Log.debug("CheckSessionIFrame: " + e.data + " message from check session op iframe");
60
+ } else {
61
+ Log.debug('CheckSessionIFrame: ' + e.data + ' message from check session op iframe');
62
62
  }
63
63
  }
64
64
  }
65
+
65
66
  start(session_state) {
66
- Log.debug("CheckSessionIFrame.start :" + session_state);
67
+ Log.debug('CheckSessionIFrame.start :' + session_state);
67
68
  this.stop();
68
- let send = () => {
69
- this._frame.contentWindow.postMessage(this._client_id + " " + session_state, this._frame_origin);
69
+ const send = () => {
70
+ this._frame.contentWindow.postMessage(this._client_id + ' ' + session_state, this._frame_origin);
70
71
  };
71
72
  send();
72
73
  this._timer = window.setInterval(send, this._interval);
@@ -74,9 +75,9 @@ export class CheckSessionIFrame {
74
75
 
75
76
  stop() {
76
77
  if (this._timer) {
77
- Log.debug("CheckSessionIFrame.stop");
78
+ Log.debug('CheckSessionIFrame.stop');
78
79
  window.clearInterval(this._timer);
79
80
  this._timer = null;
80
81
  }
81
82
  }
82
- }
83
+ }
@@ -1 +1,2 @@
1
- export { VanillaOidc } from './vanillaOidc';
1
+ export { OidcConfiguration } from './oidc';
2
+ export { VanillaOidc } from './vanillaOidc';
@@ -1,67 +1,66 @@
1
- export const initSession = (configurationName, redirectUri, storage=sessionStorage) => {
2
-
3
- const saveItemsAsync =(items) =>{
1
+ export const initSession = (configurationName, redirectUri, storage = sessionStorage) => {
2
+ const saveItemsAsync = (items) => {
4
3
  storage[`oidc_items.${configurationName}:${redirectUri}`] = JSON.stringify(items);
5
4
  return Promise.resolve();
6
- }
5
+ };
7
6
 
8
- const loadItemsAsync=() =>{
7
+ const loadItemsAsync = () => {
9
8
  return Promise.resolve(JSON.parse(storage[`oidc_items.${configurationName}:${redirectUri}`]));
10
- }
9
+ };
11
10
 
12
- const clearAsync=(status) =>{
13
- storage[`oidc.${configurationName}:${redirectUri}`] = JSON.stringify({tokens:null, status});
11
+ const clearAsync = (status) => {
12
+ storage[`oidc.${configurationName}:${redirectUri}`] = JSON.stringify({ tokens: null, status });
14
13
  return Promise.resolve();
15
- }
14
+ };
16
15
 
17
- const initAsync=async () => {
18
- if(!storage[`oidc.${configurationName}:${redirectUri}`]){
19
- storage[`oidc.${configurationName}:${redirectUri}`] = JSON.stringify({tokens:null, status:null});
20
- return {tokens:null, status:null};
16
+ const initAsync = async () => {
17
+ if (!storage[`oidc.${configurationName}:${redirectUri}`]) {
18
+ storage[`oidc.${configurationName}:${redirectUri}`] = JSON.stringify({ tokens: null, status: null });
19
+ return { tokens: null, status: null };
21
20
  }
22
21
  const data = JSON.parse(storage[`oidc.${configurationName}:${redirectUri}`]);
23
- return Promise.resolve({ tokens : data.tokens, status: data.status });
24
- }
22
+ return Promise.resolve({ tokens: data.tokens, status: data.status });
23
+ };
25
24
 
26
25
  const setTokens = (tokens) => {
27
- storage[`oidc.${configurationName}:${redirectUri}`] = JSON.stringify({tokens});
28
- }
26
+ storage[`oidc.${configurationName}:${redirectUri}`] = JSON.stringify({ tokens });
27
+ };
29
28
 
30
29
  const setSessionState = (sessionState) => {
31
30
  storage[`oidc.session_state.${configurationName}:${redirectUri}`] = sessionState;
32
- }
33
-
34
- const getSessionState= () =>{
31
+ };
32
+
33
+ const getSessionState = () => {
35
34
  return storage[`oidc.session_state.${configurationName}:${redirectUri}`];
36
- }
35
+ };
37
36
 
38
37
  const setNonceAsync = (nonce) => {
39
38
  localStorage[`oidc.nonce.${configurationName}:${redirectUri}`] = nonce.nonce;
40
- }
39
+ };
41
40
 
42
- const getNonceAsync= async () => {
41
+ const getNonceAsync = async () => {
43
42
  // @ts-ignore
44
- const result = {nonce: localStorage[`oidc.nonce.${configurationName}:${redirectUri}`]};
43
+ const result = { nonce: localStorage[`oidc.nonce.${configurationName}:${redirectUri}`] };
45
44
  return result;
46
- }
45
+ };
47
46
 
48
47
  const getTokens = () => {
49
- if(!storage[`oidc.${configurationName}:${redirectUri}`]){
48
+ if (!storage[`oidc.${configurationName}:${redirectUri}`]) {
50
49
  return null;
51
50
  }
52
- return JSON.stringify({ tokens : JSON.parse(storage[`oidc.${configurationName}:${redirectUri}`]).tokens });
53
- }
51
+ return JSON.stringify({ tokens: JSON.parse(storage[`oidc.${configurationName}:${redirectUri}`]).tokens });
52
+ };
54
53
 
55
54
  return {
56
- saveItemsAsync,
57
- loadItemsAsync,
58
- clearAsync,
59
- initAsync,
60
- setTokens,
61
- getTokens,
62
- setSessionState,
55
+ saveItemsAsync,
56
+ loadItemsAsync,
57
+ clearAsync,
58
+ initAsync,
59
+ setTokens,
60
+ getTokens,
61
+ setSessionState,
63
62
  getSessionState,
64
63
  setNonceAsync,
65
- getNonceAsync
64
+ getNonceAsync,
66
65
  };
67
- }
66
+ };
@@ -1,64 +1,65 @@
1
- import timer from "./timer"
2
- import {parseOriginalTokens} from "./parseTokens";
3
- import {OidcConfiguration} from "./oidc";
1
+ import { OidcConfiguration } from './oidc';
2
+ import { parseOriginalTokens } from './parseTokens';
3
+ import timer from './timer';
4
4
 
5
5
  function get_browser() {
6
- let ua = navigator.userAgent, tem,
7
- M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
8
- if(/trident/i.test(M[1])){
9
- tem=/\brv[ :]+(\d+)/g.exec(ua) || [];
10
- return {name:'ie',version:(tem[1]||'')};
11
- }
12
- if(M[1]==='Chrome'){
13
- tem=ua.match(/\bOPR|Edge\/(\d+)/);
14
-
15
- if(tem!=null) {
6
+ const ua = navigator.userAgent; let tem;
7
+ let M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
8
+ if (/trident/i.test(M[1])) {
9
+ tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
10
+ return { name: 'ie', version: (tem[1] || '') };
11
+ }
12
+ if (M[1] === 'Chrome') {
13
+ tem = ua.match(/\bOPR|Edge\/(\d+)/);
14
+
15
+ if (tem != null) {
16
16
  let version = tem[1];
17
- if(!version){
18
- const splits = ua.split(tem[0]+"/");
19
- if(splits.length>1){
17
+ if (!version) {
18
+ const splits = ua.split(tem[0] + '/');
19
+ if (splits.length > 1) {
20
20
  version = splits[1];
21
21
  }
22
22
  }
23
-
24
- return {name:'opera', version};
23
+
24
+ return { name: 'opera', version };
25
25
  }
26
26
  }
27
- M=M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?'];
28
- if((tem=ua.match(/version\/(\d+)/i))!=null) {M.splice(1,1,tem[1]);}
27
+ M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?'];
28
+ if ((tem = ua.match(/version\/(\d+)/i)) != null) { M.splice(1, 1, tem[1]); }
29
29
  return {
30
30
  name: M[0].toLowerCase(),
31
- version: M[1]
31
+ version: M[1],
32
32
  };
33
33
  }
34
34
 
35
35
  let keepAliveServiceWorkerTimeoutId = null;
36
36
 
37
37
  export const sleepAsync = (milliseconds) => {
38
- return new Promise(resolve => timer.setTimeout(resolve, milliseconds))
39
- }
38
+ return new Promise(resolve => timer.setTimeout(resolve, milliseconds));
39
+ };
40
40
 
41
41
  const keepAlive = () => {
42
42
  try {
43
43
  const promise = fetch('/OidcKeepAliveServiceWorker.json');
44
- promise.catch(error => {console.log(error)});
44
+ promise.catch(error => { console.log(error); });
45
45
  sleepAsync(230 * 1000).then(keepAlive);
46
- } catch (error){console.log(error)}
47
- }
46
+ } catch (error) { console.log(error); }
47
+ };
48
48
 
49
49
  const isServiceWorkerProxyActiveAsync = () => {
50
50
  try {
51
51
  return fetch('/OidcKeepAliveServiceWorker.json', {
52
52
  headers: {
53
- 'oidc-vanilla': "true"
54
- }})
53
+ 'oidc-vanilla': 'true',
54
+ },
55
+ })
55
56
  .then((response) => {
56
57
  return response.statusText === 'oidc-service-worker';
57
- }).catch(error => {console.log(error)});
58
- } catch (error){console.log(error)}
58
+ }).catch(error => { console.log(error); });
59
+ } catch (error) { console.log(error); }
59
60
  };
60
61
 
61
- const sendMessageAsync = (registration) => (data) =>{
62
+ const sendMessageAsync = (registration) => (data) => {
62
63
  return new Promise(function(resolve, reject) {
63
64
  const messageChannel = new MessageChannel();
64
65
  messageChannel.port1.onmessage = function (event) {
@@ -70,95 +71,93 @@ const sendMessageAsync = (registration) => (data) =>{
70
71
  };
71
72
  registration.active.postMessage(data, [messageChannel.port2]);
72
73
  });
73
- }
74
+ };
74
75
 
75
76
  export const initWorkerAsync = async(serviceWorkerRelativeUrl, configurationName) => {
76
-
77
- if(typeof window === "undefined" || typeof navigator === "undefined" || !navigator.serviceWorker||!serviceWorkerRelativeUrl){
77
+ if (typeof window === 'undefined' || typeof navigator === 'undefined' || !navigator.serviceWorker || !serviceWorkerRelativeUrl) {
78
78
  return null;
79
79
  }
80
- const {name, version} = get_browser();
81
- if(name == "chrome" && parseInt(version)<90){
80
+ const { name, version } = get_browser();
81
+ if (name === 'chrome' && parseInt(version) < 90) {
82
82
  return null;
83
83
  }
84
- if(name == "opera"){
85
- if(!version) {
84
+ if (name === 'opera') {
85
+ if (!version) {
86
86
  return null;
87
87
  }
88
- if(parseInt(version.split(".")[0])< 80) {
88
+ if (parseInt(version.split('.')[0]) < 80) {
89
89
  return null;
90
90
  }
91
91
  }
92
- if(name == "ie"){
92
+ if (name === 'ie') {
93
93
  return null;
94
94
  }
95
95
 
96
96
  const registration = await navigator.serviceWorker.register(serviceWorkerRelativeUrl);
97
97
 
98
98
  try {
99
- await navigator.serviceWorker.ready
100
- }
101
- catch(err) {
99
+ await navigator.serviceWorker.ready;
100
+ } catch (err) {
102
101
  return null;
103
102
  }
104
-
105
- const saveItemsAsync =(items) =>{
106
- return sendMessageAsync(registration)({type: "saveItems", data: items, configurationName});
107
- }
108
-
109
- const loadItemsAsync=() =>{
110
- return sendMessageAsync(registration)({type: "loadItems", data: null, configurationName});
111
- }
112
-
103
+
104
+ const saveItemsAsync = (items) => {
105
+ return sendMessageAsync(registration)({ type: 'saveItems', data: items, configurationName });
106
+ };
107
+
108
+ const loadItemsAsync = () => {
109
+ return sendMessageAsync(registration)({ type: 'loadItems', data: null, configurationName });
110
+ };
111
+
113
112
  const unregisterAsync = async () => {
114
113
  return await registration.unregister();
115
- }
116
-
117
- const clearAsync=(status) =>{
118
- return sendMessageAsync(registration)({type: "clear", data: {status}, configurationName});
119
- }
120
- const initAsync= async (oidcServerConfiguration, where, oidcConfiguration:OidcConfiguration) => {
114
+ };
115
+
116
+ const clearAsync = (status) => {
117
+ return sendMessageAsync(registration)({ type: 'clear', data: { status }, configurationName });
118
+ };
119
+ const initAsync = async (oidcServerConfiguration, where, oidcConfiguration:OidcConfiguration) => {
121
120
  const result = await sendMessageAsync(registration)({
122
- type: "init",
123
- data: {oidcServerConfiguration, where, oidcConfiguration},
124
- configurationName
121
+ type: 'init',
122
+ data: { oidcServerConfiguration, where, oidcConfiguration },
123
+ configurationName,
125
124
  });
126
125
  // @ts-ignore
127
- return { tokens : parseOriginalTokens(result.tokens, null, oidcConfiguration.token_renew_mode), status: result.status};
128
- }
129
-
126
+ return { tokens: parseOriginalTokens(result.tokens, null, oidcConfiguration.token_renew_mode), status: result.status };
127
+ };
128
+
130
129
  const startKeepAliveServiceWorker = () => {
131
130
  if (keepAliveServiceWorkerTimeoutId == null) {
132
- keepAliveServiceWorkerTimeoutId = "not_null";
131
+ keepAliveServiceWorkerTimeoutId = 'not_null';
133
132
  keepAlive();
134
133
  }
135
- }
134
+ };
136
135
 
137
136
  const setSessionStateAsync = (sessionState) => {
138
- return sendMessageAsync(registration)({type: "setSessionState", data: {sessionState}, configurationName});
139
- }
137
+ return sendMessageAsync(registration)({ type: 'setSessionState', data: { sessionState }, configurationName });
138
+ };
140
139
 
141
- const getSessionStateAsync= async () => {
142
- const result = await sendMessageAsync(registration)({type: "getSessionState", data: null, configurationName});
140
+ const getSessionStateAsync = async () => {
141
+ const result = await sendMessageAsync(registration)({ type: 'getSessionState', data: null, configurationName });
143
142
  // @ts-ignore
144
143
  return result.sessionState;
145
- }
144
+ };
146
145
 
147
146
  const setNonceAsync = (nonce) => {
148
- return sendMessageAsync(registration)({type: "setNonce", data: {nonce}, configurationName});
149
- }
147
+ return sendMessageAsync(registration)({ type: 'setNonce', data: { nonce }, configurationName });
148
+ };
150
149
  const NONCE_TOKEN = 'NONCE_SECURED_BY_OIDC_SERVICE_WORKER';
151
- const getNonceAsync= async () => {
150
+ const getNonceAsync = async () => {
152
151
  // @ts-ignore
153
- const keyNonce = NONCE_TOKEN + '_'+ configurationName;
154
- return {nonce:keyNonce};
155
- }
152
+ const keyNonce = NONCE_TOKEN + '_' + configurationName;
153
+ return { nonce: keyNonce };
154
+ };
156
155
 
157
- return {
158
- saveItemsAsync,
159
- loadItemsAsync,
160
- clearAsync,
161
- initAsync,
156
+ return {
157
+ saveItemsAsync,
158
+ loadItemsAsync,
159
+ clearAsync,
160
+ initAsync,
162
161
  startKeepAliveServiceWorker,
163
162
  isServiceWorkerProxyActiveAsync,
164
163
  setSessionStateAsync,
@@ -167,4 +166,4 @@ export const initWorkerAsync = async(serviceWorkerRelativeUrl, configurationName
167
166
  getNonceAsync,
168
167
  unregisterAsync,
169
168
  };
170
- }
169
+ };
@@ -1,6 +1,13 @@
1
- export class MemoryStorageBackend {
1
+
2
+ interface SaveItemsFn {
3
+ (items:any):Promise<any>;
4
+ }
5
+
6
+ export type ItemName = string | number;
7
+
8
+ export class MemoryStorageBackend {
2
9
  public items: any;
3
- private saveItemsAsync: Function;
10
+ private saveItemsAsync: SaveItemsFn;
4
11
 
5
12
  constructor(saveItemsAsync, items = {}) {
6
13
  this.items = items;
@@ -12,11 +19,11 @@
12
19
  this.setItem.bind(this);
13
20
  }
14
21
 
15
- getItem(name) {
22
+ getItem(name: ItemName) {
16
23
  return Promise.resolve(this.items[name]);
17
24
  }
18
25
 
19
- removeItem(name) {
26
+ removeItem(name: ItemName) {
20
27
  delete this.items[name];
21
28
  return this.saveItemsAsync(this.items);
22
29
  }
@@ -26,8 +33,8 @@
26
33
  return this.saveItemsAsync(this.items);
27
34
  }
28
35
 
29
- setItem(name, value) {
36
+ setItem(name: ItemName, value: any) {
30
37
  this.items[name] = value;
31
38
  return this.saveItemsAsync(this.items);
32
39
  }
33
- }
40
+ }
@@ -1,32 +1,32 @@
1
- import {BasicQueryStringUtils} from '@openid/appauth';
1
+ import { BasicQueryStringUtils, LocationLike } from '@openid/appauth';
2
2
 
3
3
  export class NoHashQueryStringUtils extends BasicQueryStringUtils {
4
- parse(input, useHash) {
4
+ parse(input: LocationLike, _useHash: boolean) {
5
5
  return super.parse(input, false /* never use hash */);
6
6
  }
7
7
  }
8
8
 
9
- const keys = ["code", "session_state", "state"]
9
+ const keys = ['code', 'session_state', 'state'];
10
10
 
11
11
  export class HashQueryStringUtils extends BasicQueryStringUtils {
12
- parse(input, useHash) {
13
- const output = super.parse(input, true /* use hash */);
14
-
12
+ parse(input: LocationLike, _useHash: boolean) {
13
+ const output = super.parse(input, true /* use hash */);
14
+
15
15
  // Fix AppAuthJs behavior
16
16
  let propertyToDelelete = null;
17
- Object.entries(output).map(([key, value]) => {
17
+ Object.entries(output).forEach(([key, value]) => {
18
18
  keys.forEach(k => {
19
- if(key.endsWith(`?${k}`)){
20
- output[k]= value;
19
+ if (key.endsWith(`?${k}`)) {
20
+ output[k] = value;
21
21
  propertyToDelelete = key;
22
22
  }
23
- })
23
+ });
24
24
  });
25
-
26
- if(propertyToDelelete){
25
+
26
+ if (propertyToDelelete) {
27
27
  delete output[propertyToDelelete];
28
28
  }
29
-
29
+
30
30
  return output;
31
31
  }
32
32
  }