@axa-fr/react-oidc 6.9.6 → 6.10.0

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,5 +1,4 @@
1
- import React from 'react';
2
- import {VanillaOidc} from './vanilla/vanillaOidc'
1
+ import { VanillaOidc } from './vanilla/vanillaOidc';
3
2
 
4
3
  export type Fetch = typeof window.fetch;
5
4
 
@@ -7,12 +6,12 @@ export interface ComponentWithOidcFetchProps {
7
6
  fetch?: Fetch;
8
7
  }
9
8
 
10
- const defaultConfigurationName = "default";
9
+ const defaultConfigurationName = 'default';
11
10
 
12
11
  const fetchWithToken = (fetch: Fetch, getOidcWithConfigurationName: () => VanillaOidc | null) => async (...params: Parameters<Fetch>) => {
13
12
  const [url, options, ...rest] = params;
14
- const optionTmp = options ? { ...options} : { method: "GET" };
15
-
13
+ const optionTmp = options ? { ...options } : { method: 'GET' };
14
+
16
15
  let headers = new Headers();
17
16
  if (optionTmp.headers) {
18
17
  headers = !(optionTmp.headers instanceof Headers)
@@ -20,11 +19,11 @@ const fetchWithToken = (fetch: Fetch, getOidcWithConfigurationName: () => Vanill
20
19
  : optionTmp.headers;
21
20
  }
22
21
  const oidc = getOidcWithConfigurationName();
23
-
22
+
24
23
  // @ts-ignore
25
24
  const getValidToken = await oidc.getValidTokenAsync();
26
25
  const accessToken = getValidToken.tokens.accessToken;
27
-
26
+
28
27
  if (!headers.has('Accept')) {
29
28
  headers.set('Accept', 'application/json');
30
29
  }
@@ -39,16 +38,16 @@ const fetchWithToken = (fetch: Fetch, getOidcWithConfigurationName: () => Vanill
39
38
  };
40
39
 
41
40
  export const withOidcFetch = (fetch: Fetch = null, configurationName = defaultConfigurationName) => (
42
- WrappedComponent
41
+ WrappedComponent,
43
42
  ) => (props: ComponentWithOidcFetchProps) => {
44
- const {fetch:newFetch} = useOidcFetch(fetch || props.fetch, configurationName)
43
+ const { fetch: newFetch } = useOidcFetch(fetch || props.fetch, configurationName);
45
44
  return <WrappedComponent {...props} fetch={newFetch} />;
46
45
  };
47
46
 
48
- export const useOidcFetch =(fetch: Fetch = null, configurationName = defaultConfigurationName) =>{
47
+ export const useOidcFetch = (fetch: Fetch = null, configurationName = defaultConfigurationName) => {
49
48
  const previousFetch = fetch || window.fetch;
50
49
  const getOidc = VanillaOidc.get;
51
50
  const getOidcWithConfigurationName = () => getOidc(configurationName);
52
51
  const newFetch = fetchWithToken(previousFetch, getOidcWithConfigurationName);
53
52
  return { fetch: newFetch };
54
- }
53
+ };
@@ -1,17 +1,18 @@
1
- import React, {ComponentType, FC, PropsWithChildren, useEffect, useState} from 'react';
2
- import {OidcConfiguration} from './vanilla/oidc';
3
- import {VanillaOidc} from './vanilla/vanillaOidc';
1
+ import { ComponentType, FC, PropsWithChildren, useEffect, useState } from 'react';
2
+
3
+ import AuthenticatingError from './core/default-component/AuthenticateError.component';
4
+ import { Authenticating, CallBackSuccess, Loading, SessionLost } from './core/default-component/index';
5
+ import ServiceWorkerNotSupported from './core/default-component/ServiceWorkerNotSupported.component';
4
6
  import OidcRoutes from './core/routes/OidcRoutes';
5
- import {Authenticating, SessionLost, Loading, CallBackSuccess} from './core/default-component/index';
6
- import ServiceWorkerNotSupported from "./core/default-component/ServiceWorkerNotSupported.component";
7
- import AuthenticatingError from "./core/default-component/AuthenticateError.component";
8
- import { CustomHistory } from "./core/routes/withRouter";
7
+ import { CustomHistory } from './core/routes/withRouter';
8
+ import { OidcConfiguration } from './vanilla/oidc';
9
+ import { VanillaOidc } from './vanilla/vanillaOidc';
9
10
 
10
11
  export type oidcContext = {
11
- getOidc: Function;
12
+ (name?: string): VanillaOidc;
12
13
  };
13
14
 
14
- const defaultEventState = {name:"", data:null};
15
+ const defaultEventState = { name: '', data: null };
15
16
 
16
17
  export type OidcProviderProps = {
17
18
  callbackSuccessComponent?: ComponentType<any>;
@@ -23,11 +24,11 @@ export type OidcProviderProps = {
23
24
  configurationName?: string;
24
25
  configuration?: OidcConfiguration;
25
26
  children: any;
26
- onSessionLost?: Function,
27
- onLogoutFromAnotherTab?:Function,
28
- onLogoutFromSameTab?:Function,
29
- withCustomHistory?: () => CustomHistory,
30
- onEvent?:Function
27
+ onSessionLost?: () => void;
28
+ onLogoutFromAnotherTab?: () => void;
29
+ onLogoutFromSameTab?: () => void;
30
+ withCustomHistory?: () => CustomHistory;
31
+ onEvent?: (configuration: string, name: string, data:any) => void;
31
32
  };
32
33
 
33
34
  export type OidcSessionProps = {
@@ -35,162 +36,160 @@ export type OidcSessionProps = {
35
36
  loadingComponent: PropsWithChildren<any>;
36
37
  };
37
38
 
38
-
39
- const OidcSession : FC<PropsWithChildren<OidcSessionProps>> = ({loadingComponent, children, configurationName}) =>{
40
- const [loading, setLoading] = useState(true);
41
- const getOidc = VanillaOidc.get;
39
+ const OidcSession : FC<PropsWithChildren<OidcSessionProps>> = ({ loadingComponent, children, configurationName }) => {
40
+ const [isLoading, setIsLoading] = useState(true);
41
+ const getOidc = VanillaOidc.get;
42
42
  const oidc = getOidc(configurationName);
43
43
  useEffect(() => {
44
44
  let isMounted = true;
45
- if(oidc) {
45
+ if (oidc) {
46
46
  oidc.tryKeepExistingSessionAsync().then(() => {
47
47
  if (isMounted) {
48
- setLoading(false);
48
+ setIsLoading(false);
49
49
  }
50
- })
50
+ });
51
51
  }
52
52
  return () => {
53
53
  isMounted = false;
54
- }
54
+ };
55
+ // eslint-disable-next-line react-hooks/exhaustive-deps
55
56
  }, [configurationName]);
56
57
  const LoadingComponent = loadingComponent;
57
58
  return (
58
59
  <>
59
- {loading ? (
60
+ {isLoading
61
+ ? (
60
62
  <LoadingComponent configurationName={configurationName}/>
61
- ) : (
63
+ )
64
+ : (
62
65
  <>{children}</>
63
66
  )}
64
67
  </>
65
68
  );
66
- }
69
+ };
67
70
 
68
- const Switch = ({isLoading, loadingComponent, children, configurationName}) => {
71
+ const Switch = ({ isLoading, loadingComponent, children, configurationName }) => {
69
72
  const LoadingComponent = loadingComponent;
70
- if(isLoading){
73
+ if (isLoading) {
71
74
  return <LoadingComponent configurationName={configurationName}>{children}</LoadingComponent>;
72
75
  }
73
76
  return <>{children}</>;
74
- }
75
-
77
+ };
76
78
 
77
- export const OidcProvider : FC<PropsWithChildren<OidcProviderProps>> = ({ children,
78
- configuration,
79
- configurationName = "default",
80
- callbackSuccessComponent = CallBackSuccess,
79
+ export const OidcProvider : FC<PropsWithChildren<OidcProviderProps>> = ({
80
+ children,
81
+ configuration,
82
+ configurationName = 'default',
83
+ callbackSuccessComponent = CallBackSuccess,
81
84
  authenticatingComponent = Authenticating,
82
85
  loadingComponent = Loading,
83
86
  serviceWorkerNotSupportedComponent = ServiceWorkerNotSupported,
84
87
  authenticatingErrorComponent = AuthenticatingError,
85
- sessionLostComponent=SessionLost,
86
- onSessionLost=null,
87
- onLogoutFromAnotherTab=null,
88
- onLogoutFromSameTab=null,
89
- withCustomHistory=null,
90
- onEvent=null,
88
+ sessionLostComponent = SessionLost,
89
+ onSessionLost = null,
90
+ onLogoutFromAnotherTab = null,
91
+ onLogoutFromSameTab = null,
92
+ withCustomHistory = null,
93
+ onEvent = null,
91
94
  }) => {
92
- const getOidc =(configurationName="default") => {
95
+ const getOidc = (configurationName = 'default') => {
93
96
  return VanillaOidc.getOrCreate(configuration, configurationName);
94
- }
97
+ };
98
+ // eslint-disable-next-line @typescript-eslint/naming-convention
95
99
  const [loading, setLoading] = useState(true);
96
100
  const [event, setEvent] = useState(defaultEventState);
97
- const [currentConfigurationName, setConfigurationName] = useState("default");
101
+ const [currentConfigurationName, setConfigurationName] = useState('default');
98
102
 
99
103
  useEffect(() => {
100
104
  const oidc = getOidc(configurationName);
101
- const newSubscriptionId = oidc.subscriveEvents((name, data) => {
102
- if(onEvent)
103
- {
105
+ const newSubscriptionId = oidc.subscribeEvents((name, data) => {
106
+ if (onEvent) {
104
107
  onEvent(configurationName, name, data);
105
108
  }
106
109
  });
107
110
  return () => {
108
111
  const previousOidc = getOidc(configurationName);
109
112
  previousOidc.removeEventSubscription(newSubscriptionId);
110
- }
113
+ };
111
114
  }, [configurationName, onEvent]);
112
115
 
113
116
  useEffect(() => {
114
117
  const oidc = getOidc(configurationName);
115
- const newSubscriptionId = oidc.subscriveEvents((name, data) => {
116
- if(name == VanillaOidc.eventNames.refreshTokensAsync_error || name == VanillaOidc.eventNames.syncTokensAsync_error){
117
- if(onSessionLost != null){
118
+ const newSubscriptionId = oidc.subscribeEvents((name, data) => {
119
+ if (name === VanillaOidc.eventNames.refreshTokensAsync_error || name === VanillaOidc.eventNames.syncTokensAsync_error) {
120
+ if (onSessionLost != null) {
118
121
  onSessionLost();
119
122
  return;
120
123
  }
121
- setEvent({name, data});
122
- }
123
- else if(name === VanillaOidc.eventNames.logout_from_another_tab){
124
- if(onLogoutFromAnotherTab != null){
124
+ setEvent({ name, data });
125
+ } else if (name === VanillaOidc.eventNames.logout_from_another_tab) {
126
+ if (onLogoutFromAnotherTab != null) {
125
127
  onLogoutFromAnotherTab();
126
128
  return;
127
129
  }
128
- setEvent({name, data});
129
- }
130
- else if(name === VanillaOidc.eventNames.logout_from_same_tab){
131
- if(onLogoutFromSameTab != null){
130
+ setEvent({ name, data });
131
+ } else if (name === VanillaOidc.eventNames.logout_from_same_tab) {
132
+ if (onLogoutFromSameTab != null) {
132
133
  onLogoutFromSameTab();
133
- return;
134
134
  }
135
- //setEvent({name, data});
136
- }
137
- else if (name == VanillaOidc.eventNames.loginAsync_begin
138
- || name == VanillaOidc.eventNames.loginCallbackAsync_end
139
- || name == VanillaOidc.eventNames.loginAsync_error
140
- || name == VanillaOidc.eventNames.loginCallbackAsync_error
135
+ // setEvent({name, data});
136
+ } else if (name === VanillaOidc.eventNames.loginAsync_begin ||
137
+ name === VanillaOidc.eventNames.loginCallbackAsync_end ||
138
+ name === VanillaOidc.eventNames.loginAsync_error ||
139
+ name === VanillaOidc.eventNames.loginCallbackAsync_error
141
140
  ) {
142
- setEvent({name, data});
143
- } else if (name == VanillaOidc.eventNames.service_worker_not_supported_by_browser && configuration.service_worker_only === true) {
144
- setEvent({name, data});
141
+ setEvent({ name, data });
142
+ } else if (name === VanillaOidc.eventNames.service_worker_not_supported_by_browser && configuration.service_worker_only === true) {
143
+ setEvent({ name, data });
145
144
  }
146
145
  });
147
-
146
+
148
147
  setConfigurationName(configurationName);
149
148
  setLoading(false);
150
149
  return () => {
151
150
  const previousOidc = getOidc(configurationName);
152
151
  previousOidc.removeEventSubscription(newSubscriptionId);
153
152
  setEvent(defaultEventState);
154
- }
153
+ };
154
+ // eslint-disable-next-line react-hooks/exhaustive-deps
155
155
  }, [configuration, configurationName]);
156
156
 
157
-
158
157
  const SessionLostComponent = sessionLostComponent;
159
158
  const AuthenticatingComponent = authenticatingComponent;
160
159
  const LoadingComponent = loadingComponent;
161
160
  const ServiceWorkerNotSupportedComponent = serviceWorkerNotSupportedComponent;
162
161
  const AuthenticatingErrorComponent = authenticatingErrorComponent;
163
162
 
164
- const isLoading = (loading || (currentConfigurationName != configurationName ));
163
+ const isLoading = (loading || (currentConfigurationName !== configurationName));
165
164
  const oidc = getOidc(configurationName);
166
- let eventName = event.name;
167
- switch(eventName){
165
+ const eventName = event.name;
166
+ switch (eventName) {
168
167
  case VanillaOidc.eventNames.service_worker_not_supported_by_browser:
169
- return <Switch loadingComponent={LoadingComponent} isLoading={isLoading} configurationName={configurationName}>
168
+ return (<Switch loadingComponent={LoadingComponent} isLoading={isLoading} configurationName={configurationName}>
170
169
  <ServiceWorkerNotSupportedComponent configurationName={configurationName} />
171
- </Switch>;
170
+ </Switch>);
172
171
  case VanillaOidc.eventNames.loginAsync_begin:
173
- return <Switch loadingComponent={LoadingComponent} isLoading={isLoading} configurationName={configurationName}>
172
+ return (<Switch loadingComponent={LoadingComponent} isLoading={isLoading} configurationName={configurationName}>
174
173
  <AuthenticatingComponent configurationName={configurationName} />
175
- </Switch>;
174
+ </Switch>);
176
175
  case VanillaOidc.eventNames.loginAsync_error:
177
176
  case VanillaOidc.eventNames.loginCallbackAsync_error:
178
- return <Switch loadingComponent={LoadingComponent} isLoading={isLoading} configurationName={configurationName}>
177
+ return (<Switch loadingComponent={LoadingComponent} isLoading={isLoading} configurationName={configurationName}>
179
178
  <AuthenticatingErrorComponent configurationName={configurationName} />
180
- </Switch>;
179
+ </Switch>);
181
180
  case VanillaOidc.eventNames.refreshTokensAsync_error:
182
181
  case VanillaOidc.eventNames.syncTokensAsync_error:
183
182
  case VanillaOidc.eventNames.logout_from_another_tab:
184
- return <Switch loadingComponent={LoadingComponent} isLoading={isLoading} configurationName={configurationName}>
185
- <SessionLostComponent configurationName={configurationName} />
186
- </Switch>;
183
+ return (<Switch loadingComponent={LoadingComponent} isLoading={isLoading} configurationName={configurationName}>
184
+ <SessionLostComponent configurationName={configurationName} />
185
+ </Switch>);
187
186
  default:
188
187
  return (
189
188
  <Switch loadingComponent={LoadingComponent} isLoading={isLoading} configurationName={configurationName}>
190
189
  <OidcRoutes redirect_uri={oidc.configuration.redirect_uri}
191
190
  silent_redirect_uri={oidc.configuration.silent_redirect_uri}
192
191
  silent_login_uri={oidc.configuration.silent_login_uri}
193
- callbackSuccessComponent={callbackSuccessComponent}
192
+ callbackSuccessComponent={callbackSuccessComponent}
194
193
  callbackErrorComponent={authenticatingErrorComponent}
195
194
  authenticatingComponent={authenticatingComponent}
196
195
  configurationName={configurationName}
@@ -1,36 +1,34 @@
1
- import React, {useEffect, PropsWithChildren, FC} from 'react';
1
+ import { FC, PropsWithChildren, useEffect } from 'react';
2
2
 
3
- import {StringMap} from "./vanilla/oidc";
4
- import {VanillaOidc} from "./vanilla/vanillaOidc";
3
+ import { StringMap } from './vanilla/oidc';
4
+ import { VanillaOidc } from './vanilla/vanillaOidc';
5
5
 
6
6
  export type OidcSecureProps = {
7
7
  callbackPath?:string;
8
- extras?:StringMap
8
+ extras?:StringMap;
9
9
  configurationName?: string;
10
10
  };
11
11
 
12
- export const OidcSecure: FC<PropsWithChildren<OidcSecureProps>> = ({children, callbackPath=null, extras=null, configurationName="default"}) => {
13
- const getOidc = VanillaOidc.get;
12
+ export const OidcSecure: FC<PropsWithChildren<OidcSecureProps>> = ({ children, callbackPath = null, extras = null, configurationName = 'default' }) => {
13
+ const getOidc = VanillaOidc.get;
14
14
  const oidc = getOidc(configurationName);
15
15
  useEffect(() => {
16
- if(!oidc.tokens){
16
+ if (!oidc.tokens) {
17
17
  oidc.loginAsync(callbackPath, extras);
18
18
  }
19
- return () => {
20
- }
21
- }, [configurationName, callbackPath, extras])
19
+ }, [configurationName, callbackPath, extras]);
22
20
 
23
- if(!oidc.tokens){
21
+ if (!oidc.tokens) {
24
22
  return null;
25
23
  }
26
- return <>{children}</>
27
- }
24
+ return <>{children}</>;
25
+ };
28
26
 
29
27
  export const withOidcSecure = (
30
- WrappedComponent: FC<PropsWithChildren<OidcSecureProps>>,
31
- callbackPath=null,
32
- extras=null,
33
- configurationName="default"
28
+ WrappedComponent: FC<PropsWithChildren<OidcSecureProps>>,
29
+ callbackPath = null,
30
+ extras = null,
31
+ configurationName = 'default',
34
32
  ) => (props) => {
35
33
  return <OidcSecure callbackPath={callbackPath} extras={extras} configurationName={configurationName}><WrappedComponent {...props} /></OidcSecure>;
36
- };
34
+ };
@@ -1,29 +1,35 @@
1
- import React, {useEffect, useState} from 'react';
2
- import {StringMap} from "./vanilla/oidc";
3
- import {VanillaOidc} from "./vanilla/vanillaOidc";
1
+ import { useEffect, useState } from 'react';
4
2
 
5
- const defaultConfigurationName = "default";
3
+ import { StringMap } from './vanilla/oidc';
4
+ import { VanillaOidc } from './vanilla/vanillaOidc';
6
5
 
7
- const defaultIsAuthenticated = (getOidc, configurationName) =>{
8
- let isAuthenticated:boolean = false;
6
+ const defaultConfigurationName = 'default';
7
+
8
+ type GetOidcFn = {
9
+ (configurationName?: string): any;
10
+ }
11
+
12
+ const defaultIsAuthenticated = (getOidc: GetOidcFn, configurationName: string) => {
13
+ let isAuthenticated = false;
9
14
  const oidc = getOidc(configurationName);
10
- if(oidc){
15
+ if (oidc) {
11
16
  isAuthenticated = getOidc(configurationName).tokens != null;
12
17
  }
13
18
  return isAuthenticated;
14
- }
19
+ };
15
20
 
16
- export const useOidc =(configurationName=defaultConfigurationName) =>{
17
- const getOidc = VanillaOidc.get;
21
+ export const useOidc = (configurationName = defaultConfigurationName) => {
22
+ const getOidc = VanillaOidc.get;
18
23
  const [isAuthenticated, setIsAuthenticated] = useState<boolean>(defaultIsAuthenticated(getOidc, configurationName));
19
24
 
20
25
  useEffect(() => {
21
26
  let isMounted = true;
22
27
  const oidc = getOidc(configurationName);
23
28
  setIsAuthenticated(defaultIsAuthenticated(getOidc, configurationName));
24
- const newSubscriptionId = oidc.subscriveEvents((name, data) => {
25
- if(name === VanillaOidc.eventNames.logout_from_another_tab || name === VanillaOidc.eventNames.logout_from_same_tab || name === VanillaOidc.eventNames.token_aquired){
26
- if(isMounted) {
29
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
30
+ const newSubscriptionId = oidc.subscribeEvents((name: string, data: any) => {
31
+ if (name === VanillaOidc.eventNames.logout_from_another_tab || name === VanillaOidc.eventNames.logout_from_same_tab || name === VanillaOidc.eventNames.token_aquired) {
32
+ if (isMounted) {
27
33
  setIsAuthenticated(defaultIsAuthenticated(getOidc, configurationName));
28
34
  }
29
35
  }
@@ -32,107 +38,111 @@ export const useOidc =(configurationName=defaultConfigurationName) =>{
32
38
  isMounted = false;
33
39
  oidc.removeEventSubscription(newSubscriptionId);
34
40
  };
41
+ // eslint-disable-next-line react-hooks/exhaustive-deps
35
42
  }, [configurationName]);
36
43
 
37
- const login = (callbackPath:string | undefined = undefined, extras:StringMap=null, silentLoginOnly = false) => {
44
+ const login = (callbackPath:string | undefined = undefined, extras:StringMap = null, silentLoginOnly = false) => {
38
45
  return getOidc(configurationName).loginAsync(callbackPath, extras, false, undefined, silentLoginOnly);
39
46
  };
40
- const logout = (callbackPath: string | null | undefined = undefined, extras:StringMap=null) => {
47
+ const logout = (callbackPath: string | null | undefined = undefined, extras:StringMap = null) => {
41
48
  return getOidc(configurationName).logoutAsync(callbackPath, extras);
42
49
  };
43
- const renewTokens = (extras:StringMap=null) => {
50
+ const renewTokens = (extras:StringMap = null) => {
44
51
  return getOidc(configurationName).renewTokensAsync(extras);
45
52
  };
46
53
  return { login, logout, renewTokens, isAuthenticated };
47
- }
54
+ };
48
55
 
49
- const accessTokenInitialState = {accessToken:null, accessTokenPayload:null};
56
+ const accessTokenInitialState = { accessToken: null, accessTokenPayload: null };
50
57
 
51
- const initTokens = (configurationName) => {
52
- const getOidc = VanillaOidc.get;
58
+ const initTokens = (configurationName: string) => {
59
+ const getOidc = VanillaOidc.get;
53
60
  const oidc = getOidc(configurationName);
54
- if(oidc.tokens) {
61
+ if (oidc.tokens) {
55
62
  const tokens = oidc.tokens;
56
- return {accessToken :tokens.accessToken, accessTokenPayload: tokens.accessTokenPayload }
63
+ return { accessToken: tokens.accessToken, accessTokenPayload: tokens.accessTokenPayload };
57
64
  }
58
65
  return accessTokenInitialState;
59
- }
66
+ };
60
67
 
61
68
  export type OidcAccessToken = {
62
- accessToken?: any,
63
- accessTokenPayload?: any
69
+ accessToken?: any;
70
+ accessTokenPayload?: any;
64
71
  }
65
72
 
66
- export const useOidcAccessToken =(configurationName=defaultConfigurationName) =>{
67
- const getOidc = VanillaOidc.get;
73
+ export const useOidcAccessToken = (configurationName = defaultConfigurationName) => {
74
+ const getOidc = VanillaOidc.get;
68
75
  const [state, setAccessToken] = useState<OidcAccessToken>(initTokens(configurationName));
69
76
 
70
77
  useEffect(() => {
71
78
  let isMounted = true;
72
79
  const oidc = getOidc(configurationName);
73
- if(oidc.tokens) {
80
+ if (oidc.tokens) {
74
81
  const tokens = oidc.tokens;
75
- setAccessToken({accessToken :tokens.accessToken, accessTokenPayload: tokens.accessTokenPayload });
82
+ setAccessToken({ accessToken: tokens.accessToken, accessTokenPayload: tokens.accessTokenPayload });
76
83
  }
77
- const newSubscriptionId = oidc.subscriveEvents((name, data) => {
78
- if(name == VanillaOidc.eventNames.token_renewed
79
- || name == VanillaOidc.eventNames.token_aquired
80
- || name === VanillaOidc.eventNames.logout_from_another_tab
81
- || name === VanillaOidc.eventNames.logout_from_same_tab
82
- || name == VanillaOidc.eventNames.refreshTokensAsync_error
83
- || name == VanillaOidc.eventNames.syncTokensAsync_error){
84
- if(isMounted) {
84
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
85
+ const newSubscriptionId = oidc.subscribeEvents((name: string, data: any) => {
86
+ if (name === VanillaOidc.eventNames.token_renewed ||
87
+ name === VanillaOidc.eventNames.token_aquired ||
88
+ name === VanillaOidc.eventNames.logout_from_another_tab ||
89
+ name === VanillaOidc.eventNames.logout_from_same_tab ||
90
+ name === VanillaOidc.eventNames.refreshTokensAsync_error ||
91
+ name === VanillaOidc.eventNames.syncTokensAsync_error) {
92
+ if (isMounted) {
85
93
  const tokens = oidc.tokens;
86
- setAccessToken(tokens != null ? {accessToken :tokens.accessToken, accessTokenPayload: tokens.accessTokenPayload } : accessTokenInitialState);
94
+ setAccessToken(tokens != null ? { accessToken: tokens.accessToken, accessTokenPayload: tokens.accessTokenPayload } : accessTokenInitialState);
87
95
  }
88
96
  }
89
97
  });
90
- return () => {
98
+ return () => {
91
99
  isMounted = false;
92
100
  oidc.removeEventSubscription(newSubscriptionId);
93
101
  };
102
+ // eslint-disable-next-line react-hooks/exhaustive-deps
94
103
  }, [configurationName]);
95
104
  return state;
96
- }
105
+ };
97
106
 
98
- const idTokenInitialState = {idToken:null, idTokenPayload:null};
107
+ const idTokenInitialState = { idToken: null, idTokenPayload: null };
99
108
 
100
- const initIdToken= (configurationName) =>{
101
- const getOidc = VanillaOidc.get;
109
+ const initIdToken = (configurationName: string) => {
110
+ const getOidc = VanillaOidc.get;
102
111
  const oidc = getOidc(configurationName);
103
- if(oidc.tokens) {
112
+ if (oidc.tokens) {
104
113
  const tokens = oidc.tokens;
105
- return { idToken: tokens.idToken, idTokenPayload:tokens.idTokenPayload };
114
+ return { idToken: tokens.idToken, idTokenPayload: tokens.idTokenPayload };
106
115
  }
107
- return idTokenInitialState
108
- }
116
+ return idTokenInitialState;
117
+ };
109
118
 
110
119
  export type OidcIdToken = {
111
- idToken?: any,
112
- idTokenPayload?: any
120
+ idToken?: any;
121
+ idTokenPayload?: any;
113
122
  }
114
123
 
115
- export const useOidcIdToken =(configurationName= defaultConfigurationName) =>{
116
- const getOidc = VanillaOidc.get;
124
+ export const useOidcIdToken = (configurationName = defaultConfigurationName) => {
125
+ const getOidc = VanillaOidc.get;
117
126
  const [state, setIDToken] = useState<OidcIdToken>(initIdToken(configurationName));
118
127
 
119
128
  useEffect(() => {
120
129
  let isMounted = true;
121
130
  const oidc = getOidc(configurationName);
122
- if(oidc.tokens) {
131
+ if (oidc.tokens) {
123
132
  const tokens = oidc.tokens;
124
- setIDToken({idToken: tokens.idToken, idTokenPayload:tokens.idTokenPayload});
133
+ setIDToken({ idToken: tokens.idToken, idTokenPayload: tokens.idTokenPayload });
125
134
  }
126
- const newSubscriptionId = oidc.subscriveEvents((name, data) => {
127
- if(name == VanillaOidc.eventNames.token_renewed
128
- || name == VanillaOidc.eventNames.token_aquired
129
- || name === VanillaOidc.eventNames.logout_from_another_tab
130
- || name === VanillaOidc.eventNames.logout_from_same_tab
131
- || name == VanillaOidc.eventNames.refreshTokensAsync_error
132
- || name == VanillaOidc.eventNames.syncTokensAsync_error){
133
- if(isMounted) {
135
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
136
+ const newSubscriptionId = oidc.subscribeEvents((name: string, data: any) => {
137
+ if (name === VanillaOidc.eventNames.token_renewed ||
138
+ name === VanillaOidc.eventNames.token_aquired ||
139
+ name === VanillaOidc.eventNames.logout_from_another_tab ||
140
+ name === VanillaOidc.eventNames.logout_from_same_tab ||
141
+ name === VanillaOidc.eventNames.refreshTokensAsync_error ||
142
+ name === VanillaOidc.eventNames.syncTokensAsync_error) {
143
+ if (isMounted) {
134
144
  const tokens = oidc.tokens;
135
- setIDToken(tokens != null ? {idToken: tokens.idToken, idTokenPayload:tokens.idTokenPayload} : idTokenInitialState);
145
+ setIDToken(tokens != null ? { idToken: tokens.idToken, idTokenPayload: tokens.idTokenPayload } : idTokenInitialState);
136
146
  }
137
147
  }
138
148
  });
@@ -140,6 +150,7 @@ export const useOidcIdToken =(configurationName= defaultConfigurationName) =>{
140
150
  isMounted = false;
141
151
  oidc.removeEventSubscription(newSubscriptionId);
142
152
  };
153
+ // eslint-disable-next-line react-hooks/exhaustive-deps
143
154
  }, [configurationName]);
144
155
  return state;
145
- }
156
+ };