@axa-fr/react-oidc 6.6.7 → 6.6.9-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.
- package/dist/FetchToken.d.ts.map +1 -1
- package/dist/FetchToken.js +4 -9
- package/dist/FetchToken.js.map +1 -1
- package/dist/OidcProvider.d.ts.map +1 -1
- package/dist/OidcProvider.js +19 -19
- package/dist/OidcProvider.js.map +1 -1
- package/dist/OidcSecure.d.ts +1 -2
- package/dist/OidcSecure.d.ts.map +1 -1
- package/dist/OidcSecure.js +4 -7
- package/dist/OidcSecure.js.map +1 -1
- package/dist/OidcServiceWorker.js +40 -11
- package/dist/ReactOidc.d.ts +3 -3
- package/dist/ReactOidc.d.ts.map +1 -1
- package/dist/ReactOidc.js +19 -17
- package/dist/ReactOidc.js.map +1 -1
- package/dist/User.d.ts.map +1 -1
- package/dist/User.js +2 -5
- package/dist/User.js.map +1 -1
- package/dist/core/default-component/Callback.component.js +3 -3
- package/dist/core/default-component/Callback.component.js.map +1 -1
- package/dist/core/default-component/SilentCallback.component.js +3 -6
- package/dist/core/default-component/SilentCallback.component.js.map +1 -1
- package/dist/core/default-component/SilentLogin.component.js +2 -5
- package/dist/core/default-component/SilentLogin.component.js.map +1 -1
- package/dist/vanilla/index.d.ts +1 -1
- package/dist/vanilla/index.d.ts.map +1 -1
- package/dist/vanilla/index.js +3 -3
- package/dist/vanilla/index.js.map +1 -1
- package/dist/vanilla/initWorker.d.ts +1 -1
- package/dist/vanilla/initWorker.d.ts.map +1 -1
- package/dist/vanilla/initWorker.js +4 -0
- package/dist/vanilla/initWorker.js.map +1 -1
- package/dist/vanilla/noHashQueryStringUtils.d.ts.map +1 -1
- package/dist/vanilla/noHashQueryStringUtils.js +1 -2
- package/dist/vanilla/noHashQueryStringUtils.js.map +1 -1
- package/dist/vanilla/oidc.d.ts +16 -12
- package/dist/vanilla/oidc.d.ts.map +1 -1
- package/dist/vanilla/oidc.js +83 -38
- package/dist/vanilla/oidc.js.map +1 -1
- package/dist/vanilla/parseTokens.d.ts +11 -2
- package/dist/vanilla/parseTokens.d.ts.map +1 -1
- package/dist/vanilla/parseTokens.js +2 -2
- package/dist/vanilla/parseTokens.js.map +1 -1
- package/dist/vanilla/timer.js +3 -3
- package/dist/vanilla/timer.js.map +1 -1
- package/dist/vanilla/vanillaOidc.d.ts +56 -0
- package/dist/vanilla/vanillaOidc.d.ts.map +1 -0
- package/dist/vanilla/vanillaOidc.js +84 -0
- package/dist/vanilla/vanillaOidc.js.map +1 -0
- package/package.json +1 -1
- package/src/Home.tsx +0 -1
- package/src/configurations.ts +3 -3
- package/src/oidc/FetchToken.tsx +6 -11
- package/src/oidc/OidcProvider.tsx +21 -20
- package/src/oidc/OidcSecure.tsx +5 -6
- package/src/oidc/ReactOidc.tsx +20 -14
- package/src/oidc/User.ts +2 -4
- package/src/oidc/core/default-component/Callback.component.tsx +3 -3
- package/src/oidc/core/default-component/SilentCallback.component.tsx +3 -3
- package/src/oidc/core/default-component/SilentLogin.component.tsx +2 -2
- package/src/oidc/vanilla/OidcServiceWorker.js +40 -11
- package/src/oidc/vanilla/index.ts +1 -1
- package/src/oidc/vanilla/initWorker.ts +5 -0
- package/src/oidc/vanilla/noHashQueryStringUtils.ts +1 -2
- package/src/oidc/vanilla/oidc.ts +108 -65
- package/src/oidc/vanilla/parseTokens.ts +13 -4
- package/src/oidc/vanilla/timer.ts +3 -3
- package/src/oidc/vanilla/vanillaOidc.ts +74 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React, {ComponentType, FC, PropsWithChildren, useEffect, useState} from 'react';
|
|
2
|
-
import
|
|
2
|
+
import {OidcConfiguration} from './vanilla/oidc';
|
|
3
|
+
import {VanillaOidc} from './vanilla/vanillaOidc';
|
|
3
4
|
import OidcRoutes from './core/routes/OidcRoutes';
|
|
4
|
-
import {Authenticating,
|
|
5
|
+
import {Authenticating, SessionLost, Loading, CallBackSuccess} from './core/default-component/index';
|
|
5
6
|
import ServiceWorkerNotSupported from "./core/default-component/ServiceWorkerNotSupported.component";
|
|
6
7
|
import AuthenticatingError from "./core/default-component/AuthenticateError.component";
|
|
7
8
|
import { CustomHistory } from "./core/routes/withRouter";
|
|
@@ -37,7 +38,7 @@ export type OidcSessionProps = {
|
|
|
37
38
|
|
|
38
39
|
const OidcSession : FC<PropsWithChildren<OidcSessionProps>> = ({loadingComponent, children, configurationName}) =>{
|
|
39
40
|
const [loading, setLoading] = useState(true);
|
|
40
|
-
const getOidc =
|
|
41
|
+
const getOidc = VanillaOidc.get;
|
|
41
42
|
const oidc = getOidc(configurationName);
|
|
42
43
|
useEffect(() => {
|
|
43
44
|
let isMounted = true;
|
|
@@ -51,7 +52,7 @@ const OidcSession : FC<PropsWithChildren<OidcSessionProps>> = ({loadingComponent
|
|
|
51
52
|
return () => {
|
|
52
53
|
isMounted = false;
|
|
53
54
|
}
|
|
54
|
-
}, [
|
|
55
|
+
}, [configurationName]);
|
|
55
56
|
const LoadingComponent = loadingComponent;
|
|
56
57
|
return (
|
|
57
58
|
<>
|
|
@@ -89,7 +90,7 @@ export const OidcProvider : FC<PropsWithChildren<OidcProviderProps>> = ({ child
|
|
|
89
90
|
onEvent=null,
|
|
90
91
|
}) => {
|
|
91
92
|
const getOidc =(configurationName="default") => {
|
|
92
|
-
return
|
|
93
|
+
return VanillaOidc.getOrCreate(configuration, configurationName);
|
|
93
94
|
}
|
|
94
95
|
const [loading, setLoading] = useState(true);
|
|
95
96
|
const [event, setEvent] = useState(defaultEventState);
|
|
@@ -112,34 +113,34 @@ export const OidcProvider : FC<PropsWithChildren<OidcProviderProps>> = ({ child
|
|
|
112
113
|
useEffect(() => {
|
|
113
114
|
const oidc = getOidc(configurationName);
|
|
114
115
|
const newSubscriptionId = oidc.subscriveEvents((name, data) => {
|
|
115
|
-
if(name ==
|
|
116
|
+
if(name == VanillaOidc.eventNames.refreshTokensAsync_error || name == VanillaOidc.eventNames.syncTokensAsync_error){
|
|
116
117
|
if(onSessionLost != null){
|
|
117
118
|
onSessionLost();
|
|
118
119
|
return;
|
|
119
120
|
}
|
|
120
121
|
setEvent({name, data});
|
|
121
122
|
}
|
|
122
|
-
else if(name ===
|
|
123
|
+
else if(name === VanillaOidc.eventNames.logout_from_another_tab){
|
|
123
124
|
if(onLogoutFromAnotherTab != null){
|
|
124
125
|
onLogoutFromAnotherTab();
|
|
125
126
|
return;
|
|
126
127
|
}
|
|
127
128
|
setEvent({name, data});
|
|
128
129
|
}
|
|
129
|
-
else if(name ===
|
|
130
|
+
else if(name === VanillaOidc.eventNames.logout_from_same_tab){
|
|
130
131
|
if(onLogoutFromSameTab != null){
|
|
131
132
|
onLogoutFromSameTab();
|
|
132
133
|
return;
|
|
133
134
|
}
|
|
134
135
|
//setEvent({name, data});
|
|
135
136
|
}
|
|
136
|
-
else if (name ==
|
|
137
|
-
|| name ==
|
|
138
|
-
|| name ==
|
|
139
|
-
|| name ==
|
|
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
|
|
140
141
|
) {
|
|
141
142
|
setEvent({name, data});
|
|
142
|
-
} else if (name ==
|
|
143
|
+
} else if (name == VanillaOidc.eventNames.service_worker_not_supported_by_browser && configuration.service_worker_only === true) {
|
|
143
144
|
setEvent({name, data});
|
|
144
145
|
}
|
|
145
146
|
});
|
|
@@ -164,22 +165,22 @@ export const OidcProvider : FC<PropsWithChildren<OidcProviderProps>> = ({ child
|
|
|
164
165
|
const oidc = getOidc(configurationName);
|
|
165
166
|
let eventName = event.name;
|
|
166
167
|
switch(eventName){
|
|
167
|
-
case
|
|
168
|
+
case VanillaOidc.eventNames.service_worker_not_supported_by_browser:
|
|
168
169
|
return <Switch loadingComponent={LoadingComponent} isLoading={isLoading} configurationName={configurationName}>
|
|
169
170
|
<ServiceWorkerNotSupportedComponent configurationName={configurationName} />
|
|
170
171
|
</Switch>;
|
|
171
|
-
case
|
|
172
|
+
case VanillaOidc.eventNames.loginAsync_begin:
|
|
172
173
|
return <Switch loadingComponent={LoadingComponent} isLoading={isLoading} configurationName={configurationName}>
|
|
173
174
|
<AuthenticatingComponent configurationName={configurationName} />
|
|
174
175
|
</Switch>;
|
|
175
|
-
case
|
|
176
|
-
case
|
|
176
|
+
case VanillaOidc.eventNames.loginAsync_error:
|
|
177
|
+
case VanillaOidc.eventNames.loginCallbackAsync_error:
|
|
177
178
|
return <Switch loadingComponent={LoadingComponent} isLoading={isLoading} configurationName={configurationName}>
|
|
178
179
|
<AuthenticatingErrorComponent configurationName={configurationName} />
|
|
179
180
|
</Switch>;
|
|
180
|
-
case
|
|
181
|
-
case
|
|
182
|
-
case
|
|
181
|
+
case VanillaOidc.eventNames.refreshTokensAsync_error:
|
|
182
|
+
case VanillaOidc.eventNames.syncTokensAsync_error:
|
|
183
|
+
case VanillaOidc.eventNames.logout_from_another_tab:
|
|
183
184
|
return <Switch loadingComponent={LoadingComponent} isLoading={isLoading} configurationName={configurationName}>
|
|
184
185
|
<SessionLostComponent configurationName={configurationName} />
|
|
185
186
|
</Switch>;
|
package/src/oidc/OidcSecure.tsx
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import React, {useEffect, PropsWithChildren, FC} from 'react';
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import {StringMap} from "./vanilla/oidc";
|
|
4
|
+
import {VanillaOidc} from "./vanilla/vanillaOidc";
|
|
4
5
|
|
|
5
6
|
export type OidcSecureProps = {
|
|
6
7
|
callbackPath?:string;
|
|
7
8
|
extras?:StringMap
|
|
8
9
|
configurationName?: string;
|
|
9
|
-
state?: string|undefined;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export const OidcSecure: FC<PropsWithChildren<OidcSecureProps>> = ({children, callbackPath=null, extras=null, configurationName="default"}) => {
|
|
13
|
-
const getOidc =
|
|
13
|
+
const getOidc = VanillaOidc.get;
|
|
14
14
|
const oidc = getOidc(configurationName);
|
|
15
15
|
useEffect(() => {
|
|
16
16
|
if(!oidc.tokens){
|
|
@@ -30,8 +30,7 @@ export const withOidcSecure = (
|
|
|
30
30
|
WrappedComponent: FC<PropsWithChildren<OidcSecureProps>>,
|
|
31
31
|
callbackPath=null,
|
|
32
32
|
extras=null,
|
|
33
|
-
configurationName="default"
|
|
34
|
-
state: string|undefined=undefined
|
|
33
|
+
configurationName="default"
|
|
35
34
|
) => (props) => {
|
|
36
|
-
return <OidcSecure
|
|
35
|
+
return <OidcSecure callbackPath={callbackPath} extras={extras} configurationName={configurationName}><WrappedComponent {...props} /></OidcSecure>;
|
|
37
36
|
};
|
package/src/oidc/ReactOidc.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, {useEffect, useState} from 'react';
|
|
2
|
-
import
|
|
2
|
+
import {StringMap} from "./vanilla/oidc";
|
|
3
|
+
import {VanillaOidc} from "./vanilla/vanillaOidc";
|
|
3
4
|
|
|
4
5
|
const defaultConfigurationName = "default";
|
|
5
6
|
|
|
@@ -13,7 +14,7 @@ const defaultIsAuthenticated = (getOidc, configurationName) =>{
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export const useOidc =(configurationName=defaultConfigurationName) =>{
|
|
16
|
-
const getOidc =
|
|
17
|
+
const getOidc = VanillaOidc.get;
|
|
17
18
|
const [isAuthenticated, setIsAuthenticated] = useState<boolean>(defaultIsAuthenticated(getOidc, configurationName));
|
|
18
19
|
|
|
19
20
|
useEffect(() => {
|
|
@@ -21,7 +22,7 @@ export const useOidc =(configurationName=defaultConfigurationName) =>{
|
|
|
21
22
|
const oidc = getOidc(configurationName);
|
|
22
23
|
setIsAuthenticated(defaultIsAuthenticated(getOidc, configurationName));
|
|
23
24
|
const newSubscriptionId = oidc.subscriveEvents((name, data) => {
|
|
24
|
-
if(name ===
|
|
25
|
+
if(name === VanillaOidc.eventNames.logout_from_another_tab || name === VanillaOidc.eventNames.logout_from_same_tab || name === VanillaOidc.eventNames.token_aquired){
|
|
25
26
|
if(isMounted) {
|
|
26
27
|
setIsAuthenticated(defaultIsAuthenticated(getOidc, configurationName));
|
|
27
28
|
}
|
|
@@ -48,7 +49,7 @@ export const useOidc =(configurationName=defaultConfigurationName) =>{
|
|
|
48
49
|
const accessTokenInitialState = {accessToken:null, accessTokenPayload:null};
|
|
49
50
|
|
|
50
51
|
const initTokens = (configurationName) => {
|
|
51
|
-
const getOidc =
|
|
52
|
+
const getOidc = VanillaOidc.get;
|
|
52
53
|
const oidc = getOidc(configurationName);
|
|
53
54
|
if(oidc.tokens) {
|
|
54
55
|
const tokens = oidc.tokens;
|
|
@@ -63,7 +64,7 @@ export type OidcAccessToken = {
|
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
export const useOidcAccessToken =(configurationName=defaultConfigurationName) =>{
|
|
66
|
-
const getOidc =
|
|
67
|
+
const getOidc = VanillaOidc.get;
|
|
67
68
|
const [state, setAccessToken] = useState<OidcAccessToken>(initTokens(configurationName));
|
|
68
69
|
|
|
69
70
|
useEffect(() => {
|
|
@@ -74,10 +75,12 @@ export const useOidcAccessToken =(configurationName=defaultConfigurationName) =>
|
|
|
74
75
|
setAccessToken({accessToken :tokens.accessToken, accessTokenPayload: tokens.accessTokenPayload });
|
|
75
76
|
}
|
|
76
77
|
const newSubscriptionId = oidc.subscriveEvents((name, data) => {
|
|
77
|
-
if(name ==
|
|
78
|
-
|| name ==
|
|
79
|
-
|| name ===
|
|
80
|
-
|| name ===
|
|
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){
|
|
81
84
|
if(isMounted) {
|
|
82
85
|
const tokens = oidc.tokens;
|
|
83
86
|
setAccessToken(tokens != null ? {accessToken :tokens.accessToken, accessTokenPayload: tokens.accessTokenPayload } : accessTokenInitialState);
|
|
@@ -95,7 +98,7 @@ export const useOidcAccessToken =(configurationName=defaultConfigurationName) =>
|
|
|
95
98
|
const idTokenInitialState = {idToken:null, idTokenPayload:null};
|
|
96
99
|
|
|
97
100
|
const initIdToken= (configurationName) =>{
|
|
98
|
-
const getOidc =
|
|
101
|
+
const getOidc = VanillaOidc.get;
|
|
99
102
|
const oidc = getOidc(configurationName);
|
|
100
103
|
if(oidc.tokens) {
|
|
101
104
|
const tokens = oidc.tokens;
|
|
@@ -110,7 +113,7 @@ export type OidcIdToken = {
|
|
|
110
113
|
}
|
|
111
114
|
|
|
112
115
|
export const useOidcIdToken =(configurationName= defaultConfigurationName) =>{
|
|
113
|
-
const getOidc =
|
|
116
|
+
const getOidc = VanillaOidc.get;
|
|
114
117
|
const [state, setIDToken] = useState<OidcIdToken>(initIdToken(configurationName));
|
|
115
118
|
|
|
116
119
|
useEffect(() => {
|
|
@@ -121,9 +124,12 @@ export const useOidcIdToken =(configurationName= defaultConfigurationName) =>{
|
|
|
121
124
|
setIDToken({idToken: tokens.idToken, idTokenPayload:tokens.idTokenPayload});
|
|
122
125
|
}
|
|
123
126
|
const newSubscriptionId = oidc.subscriveEvents((name, data) => {
|
|
124
|
-
if(name ==
|
|
125
|
-
|| name ==
|
|
126
|
-
|| name ===
|
|
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){
|
|
127
133
|
if(isMounted) {
|
|
128
134
|
const tokens = oidc.tokens;
|
|
129
135
|
setIDToken(tokens != null ? {idToken: tokens.idToken, idTokenPayload:tokens.idTokenPayload} : idTokenInitialState);
|
package/src/oidc/User.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useState} from "react";
|
|
2
|
-
import
|
|
2
|
+
import {VanillaOidc} from "./vanilla/vanillaOidc";
|
|
3
3
|
|
|
4
4
|
export enum OidcUserStatus {
|
|
5
5
|
Unauthenticated= 'Unauthenticated',
|
|
@@ -16,10 +16,9 @@ export type OidcUser = {
|
|
|
16
16
|
export const useOidcUser = (configurationName="default") => {
|
|
17
17
|
const [oidcUser, setOidcUser] = useState<OidcUser>({user: null, status: OidcUserStatus.Unauthenticated});
|
|
18
18
|
|
|
19
|
-
const oidc =
|
|
19
|
+
const oidc = VanillaOidc.get(configurationName);
|
|
20
20
|
useEffect(() => {
|
|
21
21
|
let isMounted = true;
|
|
22
|
-
|
|
23
22
|
if(oidc && oidc.tokens) {
|
|
24
23
|
setOidcUser({...oidcUser, status: OidcUserStatus.Loading});
|
|
25
24
|
oidc.userInfoAsync()
|
|
@@ -30,7 +29,6 @@ export const useOidcUser = (configurationName="default") => {
|
|
|
30
29
|
})
|
|
31
30
|
.catch(() => setOidcUser({...oidcUser, status: OidcUserStatus.LoadingError}));
|
|
32
31
|
}
|
|
33
|
-
|
|
34
32
|
return () => { isMounted = false };
|
|
35
33
|
}, []);
|
|
36
34
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, {useEffect, useState, ComponentType} from 'react';
|
|
2
2
|
import AuthenticatingError from "./AuthenticateError.component";
|
|
3
|
-
import
|
|
3
|
+
import {VanillaOidc} from "../../vanilla/vanillaOidc";
|
|
4
4
|
import {getCustomHistory} from "../routes/withRouter";
|
|
5
5
|
|
|
6
6
|
export const CallBackSuccess: ComponentType<any> = () => (<div className="oidc-callback">
|
|
@@ -16,9 +16,9 @@ const CallbackManager: ComponentType<any> = ({callBackError, callBackSuccess, co
|
|
|
16
16
|
useEffect(() => {
|
|
17
17
|
let isMounted = true;
|
|
18
18
|
const playCallbackAsync = async () => {
|
|
19
|
-
const getOidc =
|
|
19
|
+
const getOidc = VanillaOidc.get;
|
|
20
20
|
try {
|
|
21
|
-
const {callbackPath} = await getOidc(configurationName).
|
|
21
|
+
const {callbackPath} = await getOidc(configurationName).loginCallbackAsync();
|
|
22
22
|
const history = (withCustomHistory)? withCustomHistory(): getCustomHistory();
|
|
23
23
|
history.replaceState(callbackPath || "/")
|
|
24
24
|
} catch (error) {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import React, {useEffect, ComponentType} from 'react';
|
|
2
|
-
import
|
|
2
|
+
import {VanillaOidc} from "../../vanilla/vanillaOidc"
|
|
3
3
|
|
|
4
4
|
const CallbackManager: ComponentType<any> = ({configurationName }) => {
|
|
5
5
|
|
|
6
6
|
useEffect(() => {
|
|
7
7
|
let isMounted = true;
|
|
8
8
|
const playCallbackAsync = async () => {
|
|
9
|
-
const getOidc =
|
|
9
|
+
const getOidc = VanillaOidc.get;
|
|
10
10
|
const oidc = getOidc(configurationName);
|
|
11
|
-
oidc.
|
|
11
|
+
oidc.silentLoginCallbackAsync();
|
|
12
12
|
};
|
|
13
13
|
playCallbackAsync();
|
|
14
14
|
return () => {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React, {useEffect, ComponentType} from 'react';
|
|
2
|
-
import
|
|
2
|
+
import {VanillaOidc} from "../../vanilla/vanillaOidc";
|
|
3
3
|
import {getParseQueryStringFromLocation} from "../../vanilla/route-utils";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
const SilentLogin: ComponentType<any> = (({configurationName }) => {
|
|
7
7
|
const queryParams = getParseQueryStringFromLocation(window.location.href);
|
|
8
8
|
|
|
9
|
-
const getOidc =
|
|
9
|
+
const getOidc = VanillaOidc.get;
|
|
10
10
|
const oidc = getOidc(configurationName);
|
|
11
11
|
|
|
12
12
|
let extras = null;
|
|
@@ -13,6 +13,13 @@ const handleInstall = (event) => {
|
|
|
13
13
|
const handleActivate = (event) => {
|
|
14
14
|
console.log('[OidcServiceWorker] service worker activated ' + id);
|
|
15
15
|
event.waitUntil(self.clients.claim());
|
|
16
|
+
/*self.registration.unregister()
|
|
17
|
+
.then(function() {
|
|
18
|
+
return self.clients.matchAll();
|
|
19
|
+
})
|
|
20
|
+
.then(function(clients) {
|
|
21
|
+
clients.forEach(client => client.navigate(client.url))
|
|
22
|
+
});*/
|
|
16
23
|
};
|
|
17
24
|
|
|
18
25
|
let currentLoginCallbackConfigurationName = null;
|
|
@@ -131,21 +138,21 @@ function hideTokens(currentDatabaseElement) {
|
|
|
131
138
|
const accessTokenExpiresAt = (accessTokenPayload && accessTokenPayload.exp)? accessTokenPayload.exp : tokens.issued_at + tokens.expires_in;
|
|
132
139
|
const expiresAt = idTokenExpiresAt < accessTokenExpiresAt ? idTokenExpiresAt : accessTokenExpiresAt;
|
|
133
140
|
secureTokens.expiresAt = expiresAt;
|
|
134
|
-
|
|
141
|
+
|
|
135
142
|
tokens.expiresAt = expiresAt;
|
|
136
143
|
|
|
137
144
|
if(!isTokensOidcValid(tokens, currentDatabaseElement.nonce.nonce, currentDatabaseElement.oidcServerConfiguration)){
|
|
138
145
|
throw Error("Tokens are not OpenID valid");
|
|
139
146
|
}
|
|
140
|
-
|
|
147
|
+
|
|
141
148
|
// When refresh_token is not rotated we reuse ald refresh_token
|
|
142
149
|
if(currentDatabaseElement.tokens != null && "refresh_token" in currentDatabaseElement.tokens && !("refresh_token" in tokens)){
|
|
143
150
|
const refreshToken = currentDatabaseElement.tokens.refresh_token;
|
|
144
151
|
currentDatabaseElement.tokens = {...tokens, refresh_token : refreshToken};
|
|
145
152
|
} else{
|
|
146
|
-
currentDatabaseElement.tokens = tokens;
|
|
153
|
+
currentDatabaseElement.tokens = tokens;
|
|
147
154
|
}
|
|
148
|
-
|
|
155
|
+
|
|
149
156
|
currentDatabaseElement.status = "LOGGED_IN";
|
|
150
157
|
const body = JSON.stringify(secureTokens);
|
|
151
158
|
return new Response(body, response);
|
|
@@ -156,8 +163,12 @@ function hideTokens(currentDatabaseElement) {
|
|
|
156
163
|
const getCurrentDatabasesTokenEndpoint = (database, url) => {
|
|
157
164
|
const databases = [];
|
|
158
165
|
for (const [key, value] of Object.entries(database)) {
|
|
159
|
-
if(value
|
|
160
|
-
|
|
166
|
+
if(value ){
|
|
167
|
+
if(value.oidcServerConfiguration !=null && url.startsWith(value.oidcServerConfiguration.tokenEndpoint)){
|
|
168
|
+
databases.push(value);
|
|
169
|
+
} else if(value.oidcServerConfiguration !=null && value.oidcServerConfiguration.revocationEndpoint && url.startsWith(value.oidcServerConfiguration.revocationEndpoint)) {
|
|
170
|
+
databases.push(value);
|
|
171
|
+
}
|
|
161
172
|
}
|
|
162
173
|
}
|
|
163
174
|
return databases;
|
|
@@ -178,6 +189,9 @@ const getCurrentDatabaseDomain = (database, url) => {
|
|
|
178
189
|
if(oidcServerConfiguration.tokenEndpoint && url === oidcServerConfiguration.tokenEndpoint){
|
|
179
190
|
continue;
|
|
180
191
|
}
|
|
192
|
+
if(oidcServerConfiguration.revocationEndpoint && url === oidcServerConfiguration.revocationEndpoint){
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
181
195
|
|
|
182
196
|
const domainsToSendTokens = oidcServerConfiguration.userInfoEndpoint ? [
|
|
183
197
|
oidcServerConfiguration.userInfoEndpoint, ...trustedDomains[key]
|
|
@@ -239,7 +253,7 @@ const keepAliveAsync = async (event) => {
|
|
|
239
253
|
|
|
240
254
|
const handleFetch = async (event) => {
|
|
241
255
|
const originalRequest = event.request;
|
|
242
|
-
|
|
256
|
+
const url =originalRequest.url;
|
|
243
257
|
if(originalRequest.url.includes(keepAliveJsonFilename) ){
|
|
244
258
|
event.respondWith(keepAliveAsync(event));
|
|
245
259
|
return;
|
|
@@ -263,6 +277,7 @@ const handleFetch = async (event) => {
|
|
|
263
277
|
if(event.request.method !== "POST"){
|
|
264
278
|
return;
|
|
265
279
|
}
|
|
280
|
+
|
|
266
281
|
let currentDatabase = null;
|
|
267
282
|
const currentDatabases = getCurrentDatabasesTokenEndpoint(database, originalRequest.url);
|
|
268
283
|
const numberDatabase = currentDatabases.length;
|
|
@@ -270,7 +285,7 @@ const handleFetch = async (event) => {
|
|
|
270
285
|
const maPromesse = new Promise((resolve, reject) => {
|
|
271
286
|
const clonedRequest = originalRequest.clone();
|
|
272
287
|
const response = clonedRequest.text().then(actualBody => {
|
|
273
|
-
if(actualBody.includes(REFRESH_TOKEN)) {
|
|
288
|
+
if(actualBody.includes(REFRESH_TOKEN) || actualBody.includes(ACCESS_TOKEN)) {
|
|
274
289
|
let newBody = actualBody;
|
|
275
290
|
for(let i= 0;i<numberDatabase;i++){
|
|
276
291
|
const currentDb = currentDatabases[i];
|
|
@@ -282,10 +297,15 @@ const handleFetch = async (event) => {
|
|
|
282
297
|
currentDatabase = currentDb;
|
|
283
298
|
break;
|
|
284
299
|
}
|
|
300
|
+
const keyAccessToken = ACCESS_TOKEN + '_'+ currentDb.configurationName;
|
|
301
|
+
if(actualBody.includes(keyAccessToken)) {
|
|
302
|
+
newBody = newBody.replace(keyAccessToken, encodeURIComponent(currentDb.tokens.access_token));
|
|
303
|
+
currentDatabase = currentDb;
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
285
306
|
}
|
|
286
307
|
}
|
|
287
|
-
|
|
288
|
-
return fetch(originalRequest, {
|
|
308
|
+
let fetchPromise = fetch(originalRequest, {
|
|
289
309
|
body: newBody,
|
|
290
310
|
method: clonedRequest.method,
|
|
291
311
|
headers: {
|
|
@@ -297,7 +317,14 @@ const handleFetch = async (event) => {
|
|
|
297
317
|
referrer: clonedRequest.referrer,
|
|
298
318
|
credentials: clonedRequest.credentials,
|
|
299
319
|
integrity: clonedRequest.integrity
|
|
300
|
-
})
|
|
320
|
+
});
|
|
321
|
+
if(currentDatabase.oidcServerConfiguration !=null && currentDatabase.oidcServerConfiguration.revocationEndpoint && url.startsWith(currentDatabase.oidcServerConfiguration.revocationEndpoint)){
|
|
322
|
+
return fetchPromise.then(async response => {
|
|
323
|
+
const text = await response.text();
|
|
324
|
+
return new Response(text, response);
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
return fetchPromise.then(hideTokens(currentDatabase));
|
|
301
328
|
} else if(actualBody.includes("code_verifier=") && currentLoginCallbackConfigurationName){
|
|
302
329
|
currentDatabase = database[currentLoginCallbackConfigurationName];
|
|
303
330
|
currentLoginCallbackConfigurationName=null;
|
|
@@ -371,6 +398,7 @@ addEventListener('message', event => {
|
|
|
371
398
|
trustedDomains[configurationName] = [];
|
|
372
399
|
}
|
|
373
400
|
}
|
|
401
|
+
|
|
374
402
|
switch (data.type){
|
|
375
403
|
case "loadItems":
|
|
376
404
|
port.postMessage(database[configurationName].items);
|
|
@@ -386,6 +414,7 @@ addEventListener('message', event => {
|
|
|
386
414
|
const domains = trustedDomains[configurationName];
|
|
387
415
|
if (!domains.find(f => f === acceptAnyDomainToken)) {
|
|
388
416
|
checkDomain(domains, oidcServerConfiguration.tokenEndpoint);
|
|
417
|
+
checkDomain(domains, oidcServerConfiguration.revocationEndpoint);
|
|
389
418
|
checkDomain(domains, oidcServerConfiguration.userInfoEndpoint);
|
|
390
419
|
checkDomain(domains, oidcServerConfiguration.issuer);
|
|
391
420
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { VanillaOidc } from './vanillaOidc';
|
|
@@ -45,6 +45,11 @@ const keepAlive = () => {
|
|
|
45
45
|
} catch (error){console.log(error)}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/*window.addEventListener('error', (event) => {
|
|
49
|
+
var textContent = `${event.type}: ${event.message}\n`;
|
|
50
|
+
console.log(textContent)
|
|
51
|
+
});*/
|
|
52
|
+
|
|
48
53
|
const isServiceWorkerProxyActiveAsync = () => {
|
|
49
54
|
try {
|
|
50
55
|
return fetch('/OidcKeepAliveServiceWorker.json', {
|
|
@@ -2,8 +2,7 @@ import {BasicQueryStringUtils} from '@openid/appauth';
|
|
|
2
2
|
|
|
3
3
|
export class NoHashQueryStringUtils extends BasicQueryStringUtils {
|
|
4
4
|
parse(input, useHash) {
|
|
5
|
-
|
|
6
|
-
return output;
|
|
5
|
+
return super.parse(input, false /* never use hash */);
|
|
7
6
|
}
|
|
8
7
|
}
|
|
9
8
|
|