@axa-fr/react-oidc 5.14.0 → 6.0.0-alpha0

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 (63) hide show
  1. package/dist/OidcProvider.d.ts +1 -0
  2. package/dist/OidcProvider.d.ts.map +1 -1
  3. package/dist/OidcProvider.js +13 -5
  4. package/dist/OidcProvider.js.map +1 -1
  5. package/dist/OidcServiceWorker.js +13 -0
  6. package/dist/ReactOidc.d.ts.map +1 -1
  7. package/dist/ReactOidc.js +29 -7
  8. package/dist/ReactOidc.js.map +1 -1
  9. package/dist/core/default-component/ServiceWorkerInstall.component.d.ts.map +1 -1
  10. package/dist/core/default-component/ServiceWorkerInstall.component.js +21 -9
  11. package/dist/core/default-component/ServiceWorkerInstall.component.js.map +1 -1
  12. package/dist/core/default-component/SilentCallback.component.d.ts.map +1 -1
  13. package/dist/core/default-component/SilentCallback.component.js +23 -15
  14. package/dist/core/default-component/SilentCallback.component.js.map +1 -1
  15. package/dist/core/default-component/SilentSignin.component.d.ts +4 -0
  16. package/dist/core/default-component/SilentSignin.component.d.ts.map +1 -0
  17. package/dist/core/default-component/SilentSignin.component.js +58 -0
  18. package/dist/core/default-component/SilentSignin.component.js.map +1 -0
  19. package/dist/core/routes/OidcRoutes.d.ts +1 -0
  20. package/dist/core/routes/OidcRoutes.d.ts.map +1 -1
  21. package/dist/core/routes/OidcRoutes.js +8 -2
  22. package/dist/core/routes/OidcRoutes.js.map +1 -1
  23. package/dist/vanilla/checkSessionIFrame.d.ts +17 -0
  24. package/dist/vanilla/checkSessionIFrame.d.ts.map +1 -0
  25. package/dist/vanilla/checkSessionIFrame.js +78 -0
  26. package/dist/vanilla/checkSessionIFrame.js.map +1 -0
  27. package/dist/vanilla/initSession.d.ts +3 -1
  28. package/dist/vanilla/initSession.d.ts.map +1 -1
  29. package/dist/vanilla/initSession.js +20 -11
  30. package/dist/vanilla/initSession.js.map +1 -1
  31. package/dist/vanilla/initWorker.d.ts +4 -0
  32. package/dist/vanilla/initWorker.d.ts.map +1 -1
  33. package/dist/vanilla/initWorker.js +31 -3
  34. package/dist/vanilla/initWorker.js.map +1 -1
  35. package/dist/vanilla/oidc.d.ts +24 -5
  36. package/dist/vanilla/oidc.d.ts.map +1 -1
  37. package/dist/vanilla/oidc.js +504 -224
  38. package/dist/vanilla/oidc.js.map +1 -1
  39. package/dist/vanilla/route-utils.d.ts +13 -0
  40. package/dist/vanilla/route-utils.d.ts.map +1 -0
  41. package/dist/vanilla/route-utils.js +65 -0
  42. package/dist/vanilla/route-utils.js.map +1 -0
  43. package/package.json +1 -1
  44. package/src/App.tsx +1 -1
  45. package/src/configurations.ts +8 -4
  46. package/src/oidc/OidcProvider.tsx +11 -0
  47. package/src/oidc/ReactOidc.tsx +32 -8
  48. package/src/oidc/core/default-component/ServiceWorkerInstall.component.tsx +15 -3
  49. package/src/oidc/core/default-component/SilentCallback.component.tsx +10 -15
  50. package/src/oidc/core/default-component/SilentSignin.component.tsx +35 -0
  51. package/src/oidc/core/routes/OidcRoutes.tsx +10 -1
  52. package/src/oidc/vanilla/OidcServiceWorker.js +13 -0
  53. package/src/oidc/vanilla/checkSessionIFrame.ts +82 -0
  54. package/src/oidc/vanilla/initSession.ts +23 -11
  55. package/src/oidc/vanilla/initWorker.ts +19 -2
  56. package/src/oidc/vanilla/oidc.ts +400 -137
  57. package/src/oidc/{core/routes → vanilla}/route-utils.spec.ts +0 -0
  58. package/src/oidc/vanilla/route-utils.ts +76 -0
  59. package/dist/core/routes/route-utils.d.ts +0 -2
  60. package/dist/core/routes/route-utils.d.ts.map +0 -1
  61. package/dist/core/routes/route-utils.js +0 -32
  62. package/dist/core/routes/route-utils.js.map +0 -1
  63. package/src/oidc/core/routes/route-utils.ts +0 -34
@@ -0,0 +1,82 @@
1
+ const DefaultInterval = 2000;
2
+
3
+ const Log = console;
4
+
5
+ export class CheckSessionIFrame {
6
+ private _client_id: any;
7
+ private _callback: any;
8
+ private _url: any;
9
+ private _interval: number;
10
+ private _stopOnError: boolean;
11
+ private _frame_origin: string;
12
+ private _frame: HTMLIFrameElement;
13
+ private _boundMessageEvent: any;
14
+ private _timer: number;
15
+ constructor(callback, client_id, url, interval=DefaultInterval, stopOnError = true) {
16
+ this._callback = callback;
17
+ this._client_id = client_id;
18
+ this._url = url;
19
+ this._interval = interval || DefaultInterval;
20
+ this._stopOnError = stopOnError;
21
+ const idx = url.indexOf("/", url.indexOf("//") + 2);
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";
27
+ // @ts-ignore
28
+ this._frame.width = 0;
29
+ // @ts-ignore
30
+ this._frame.height = 0;
31
+
32
+ this._frame.src = url;
33
+ }
34
+ load() {
35
+ return new Promise<void>((resolve) => {
36
+ this._frame.onload = () => {
37
+ resolve();
38
+ }
39
+ window.document.body.appendChild(this._frame);
40
+ this._boundMessageEvent = this._message.bind(this);
41
+ window.addEventListener("message", this._boundMessageEvent, false);
42
+ });
43
+ }
44
+ _message(e) {
45
+ if (e.origin === this._frame_origin &&
46
+ e.source === this._frame.contentWindow
47
+ ) {
48
+ if (e.data === "error") {
49
+ console.error("CheckSessionIFrame: error message from check session op iframe");
50
+ if (this._stopOnError) {
51
+ this.stop();
52
+ }
53
+ }
54
+ else if (e.data === "changed") {
55
+ Log.debug(e)
56
+ Log.debug("CheckSessionIFrame: changed message from check session op iframe");
57
+ this.stop();
58
+ this._callback();
59
+ }
60
+ else {
61
+ Log.debug("CheckSessionIFrame: " + e.data + " message from check session op iframe");
62
+ }
63
+ }
64
+ }
65
+ start(session_state) {
66
+ Log.debug("CheckSessionIFrame.start :" + session_state);
67
+ this.stop();
68
+ let send = () => {
69
+ this._frame.contentWindow.postMessage(this._client_id + " " + session_state, this._frame_origin);
70
+ };
71
+ send();
72
+ this._timer = window.setInterval(send, this._interval);
73
+ }
74
+
75
+ stop() {
76
+ if (this._timer) {
77
+ Log.debug("CheckSessionIFrame.stop");
78
+ window.clearInterval(this._timer);
79
+ this._timer = null;
80
+ }
81
+ }
82
+ }
@@ -1,36 +1,48 @@
1
- export const initSession = (configurationName, storage=sessionStorage) => {
1
+ export const initSession = (configurationName, redirectUri, storage=sessionStorage) => {
2
2
 
3
3
  const saveItemsAsync =(items) =>{
4
- storage[`oidc_items.${configurationName}`] = JSON.stringify(items);
4
+ storage[`oidc_items.${configurationName}:${redirectUri}`] = JSON.stringify(items);
5
5
  return Promise.resolve();
6
6
  }
7
7
 
8
8
  const loadItemsAsync=() =>{
9
- return Promise.resolve(JSON.parse(storage[`oidc_items.${configurationName}`]));
9
+ return Promise.resolve(JSON.parse(storage[`oidc_items.${configurationName}:${redirectUri}`]));
10
10
  }
11
11
 
12
12
  const clearAsync=() =>{
13
- storage[`oidc.${configurationName}`] = JSON.stringify({tokens:null});
13
+ storage[`oidc.${configurationName}:${redirectUri}`] = JSON.stringify({tokens:null});
14
14
  return Promise.resolve();
15
15
  }
16
16
 
17
17
  const initAsync=async () => {
18
- if(!storage[`oidc.${configurationName}`]){
19
- storage[`oidc.${configurationName}`] = JSON.stringify({tokens:null});
18
+ if(!storage[`oidc.${configurationName}:${redirectUri}`]){
19
+ storage[`oidc.${configurationName}:${redirectUri}`] = JSON.stringify({tokens:null});
20
+ return {tokens:null};
20
21
  }
21
- return Promise.resolve({ tokens : JSON.parse(storage[`oidc.${configurationName}`]).tokens });
22
+ return Promise.resolve({ tokens : JSON.parse(storage[`oidc.${configurationName}:${redirectUri}`]).tokens });
22
23
  }
23
24
 
24
25
  const setTokens = (tokens) => {
25
- storage[`oidc.${configurationName}`] = JSON.stringify({tokens});
26
+ //console.log("setTokens");
27
+ //console.log(tokens);
28
+ storage[`oidc.${configurationName}:${redirectUri}`] = JSON.stringify({tokens});
29
+ }
30
+
31
+ const setSessionState = (sessionState) => {
32
+ storage[`oidc.session_state.${configurationName}:${redirectUri}`] = sessionState;
33
+ }
34
+
35
+ const getSessionState= () =>{
36
+ return storage[`oidc.session_state.${configurationName}:${redirectUri}`];
26
37
  }
27
38
 
28
39
  const getTokens = () => {
29
- if(!storage[`oidc.${configurationName}`]){
40
+
41
+ if(!storage[`oidc.${configurationName}:${redirectUri}`]){
30
42
  return null;
31
43
  }
32
- return JSON.stringify({ tokens : JSON.parse(storage[`oidc.${configurationName}`]).tokens });
44
+ return JSON.stringify({ tokens : JSON.parse(storage[`oidc.${configurationName}:${redirectUri}`]).tokens });
33
45
  }
34
46
 
35
- return { saveItemsAsync, loadItemsAsync, clearAsync, initAsync, setTokens, getTokens };
47
+ return { saveItemsAsync, loadItemsAsync, clearAsync, initAsync, setTokens, getTokens, setSessionState, getSessionState };
36
48
  }
@@ -102,6 +102,10 @@ export const initWorkerAsync = async(serviceWorkerRelativeUrl, configurationName
102
102
  const loadItemsAsync=() =>{
103
103
  return sendMessageAsync(registration)({type: "loadItems", data: null, configurationName});
104
104
  }
105
+
106
+ const unregisterAsync = async () => {
107
+ await registration.unregister()
108
+ }
105
109
 
106
110
  const getAccessTokenPayloadAsync=async () => {
107
111
  const result = await sendMessageAsync(registration)({
@@ -123,7 +127,7 @@ export const initWorkerAsync = async(serviceWorkerRelativeUrl, configurationName
123
127
  configurationName
124
128
  });
125
129
  // @ts-ignore
126
- return { tokens : result.tokens};
130
+ return { tokens : result.tokens, isLogin: result.isLogin};
127
131
  }
128
132
 
129
133
  const startKeepAliveServiceWorker = () => {
@@ -133,6 +137,16 @@ export const initWorkerAsync = async(serviceWorkerRelativeUrl, configurationName
133
137
  }
134
138
  }
135
139
 
140
+ const setSessionStateAsync = (sessionState) => {
141
+ return sendMessageAsync(registration)({type: "setSessionState", data: {sessionState}, configurationName});
142
+ }
143
+
144
+ const getSessionStateAsync= async () => {
145
+ const result = await sendMessageAsync(registration)({type: "getSessionState", data: null, configurationName});
146
+ // @ts-ignore
147
+ return result.sessionState;
148
+ }
149
+
136
150
  return {
137
151
  saveItemsAsync,
138
152
  loadItemsAsync,
@@ -140,6 +154,9 @@ export const initWorkerAsync = async(serviceWorkerRelativeUrl, configurationName
140
154
  initAsync,
141
155
  getAccessTokenPayloadAsync,
142
156
  startKeepAliveServiceWorker,
143
- isServiceWorkerProxyActiveAsync
157
+ isServiceWorkerProxyActiveAsync,
158
+ setSessionStateAsync,
159
+ getSessionStateAsync,
160
+ unregisterAsync,
144
161
  };
145
162
  }