@axa-fr/react-oidc 6.20.0 → 6.21.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.
- package/README.md +1 -1
- package/dist/OidcProvider.d.ts +2 -0
- package/dist/OidcProvider.d.ts.map +1 -1
- package/dist/OidcProvider.js +2 -2
- package/dist/OidcProvider.js.map +1 -1
- package/dist/service_worker/OidcServiceWorker.js +1 -1
- package/dist/service_worker/OidcServiceWorker.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/vanilla/oidc.d.ts +4 -2
- package/dist/vanilla/oidc.d.ts.map +1 -1
- package/dist/vanilla/oidc.js +10 -9
- package/dist/vanilla/oidc.js.map +1 -1
- package/dist/vanilla/requests.d.ts +2 -1
- package/dist/vanilla/requests.d.ts.map +1 -1
- package/dist/vanilla/requests.js +1 -1
- package/dist/vanilla/requests.js.map +1 -1
- package/dist/vanilla/vanillaOidc.d.ts +2 -1
- package/dist/vanilla/vanillaOidc.d.ts.map +1 -1
- package/dist/vanilla/vanillaOidc.js +3 -3
- package/dist/vanilla/vanillaOidc.js.map +1 -1
- package/package.json +1 -1
- package/service_worker/OidcServiceWorker.ts +0 -2
- package/service_worker/dist/OidcServiceWorker.js +1 -1
- package/service_worker/dist/OidcServiceWorker.js.map +1 -1
- package/src/oidc/OidcProvider.tsx +4 -1
- package/src/oidc/vanilla/oidc.ts +12 -9
- package/src/oidc/vanilla/requests.ts +2 -1
- package/src/oidc/vanilla/vanillaOidc.ts +4 -3
|
@@ -5,6 +5,7 @@ import { Authenticating, CallBackSuccess, Loading, SessionLost } from './core/de
|
|
|
5
5
|
import ServiceWorkerNotSupported from './core/default-component/ServiceWorkerNotSupported.component.js';
|
|
6
6
|
import OidcRoutes from './core/routes/OidcRoutes.js';
|
|
7
7
|
import { CustomHistory } from './core/routes/withRouter.js';
|
|
8
|
+
import { Fetch } from './FetchToken';
|
|
8
9
|
import { OidcConfiguration } from './vanilla/types.js';
|
|
9
10
|
import { VanillaOidc } from './vanilla/vanillaOidc.js';
|
|
10
11
|
|
|
@@ -29,6 +30,7 @@ export type OidcProviderProps = {
|
|
|
29
30
|
onLogoutFromSameTab?: () => void;
|
|
30
31
|
withCustomHistory?: () => CustomHistory;
|
|
31
32
|
onEvent?: (configuration: string, name: string, data:any) => void;
|
|
33
|
+
fetch : Fetch;
|
|
32
34
|
};
|
|
33
35
|
|
|
34
36
|
export type OidcSessionProps = {
|
|
@@ -91,9 +93,10 @@ export const OidcProvider : FC<PropsWithChildren<OidcProviderProps>> = ({
|
|
|
91
93
|
onLogoutFromSameTab = null,
|
|
92
94
|
withCustomHistory = null,
|
|
93
95
|
onEvent = null,
|
|
96
|
+
fetch = window.fetch,
|
|
94
97
|
}) => {
|
|
95
98
|
const getOidc = (configurationName = 'default') => {
|
|
96
|
-
return VanillaOidc.getOrCreate(configuration, configurationName);
|
|
99
|
+
return VanillaOidc.getOrCreate(fetch)(configuration, configurationName);
|
|
97
100
|
};
|
|
98
101
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
99
102
|
const [loading, setLoading] = useState(true);
|
package/src/oidc/vanilla/oidc.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
|
|
2
|
+
import { Fetch } from '../FetchToken';
|
|
2
3
|
import { startCheckSessionAsync as defaultStartCheckSessionAsync } from './checkSession.js';
|
|
3
4
|
import { CheckSessionIFrame } from './checkSessionIFrame.js';
|
|
4
5
|
import { eventNames } from './events.js';
|
|
@@ -46,11 +47,11 @@ export class OidcAuthorizationServiceConfiguration {
|
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
const oidcDatabase = {};
|
|
49
|
-
const oidcFactory = (configuration: OidcConfiguration, name = 'default') => {
|
|
50
|
+
const oidcFactory = (configuration: OidcConfiguration, name = 'default', fetch: Fetch = window.fetch) => {
|
|
50
51
|
if (oidcDatabase[name]) {
|
|
51
52
|
return oidcDatabase[name];
|
|
52
53
|
}
|
|
53
|
-
oidcDatabase[name] = new Oidc(configuration, name);
|
|
54
|
+
oidcDatabase[name] = new Oidc(configuration, name, fetch);
|
|
54
55
|
return oidcDatabase[name];
|
|
55
56
|
};
|
|
56
57
|
export type LoginCallback = {
|
|
@@ -80,7 +81,8 @@ export class Oidc {
|
|
|
80
81
|
private timeoutId: NodeJS.Timeout;
|
|
81
82
|
public configurationName: string;
|
|
82
83
|
private checkSessionIFrame: CheckSessionIFrame;
|
|
83
|
-
|
|
84
|
+
private fetch: Fetch;
|
|
85
|
+
constructor(configuration:OidcConfiguration, configurationName = 'default', fetch: Fetch = window.fetch) {
|
|
84
86
|
let silent_login_uri = configuration.silent_login_uri;
|
|
85
87
|
if (configuration.silent_redirect_uri && !configuration.silent_login_uri) {
|
|
86
88
|
silent_login_uri = `${configuration.silent_redirect_uri.replace('-callback', '').replace('callback', '')}-login`;
|
|
@@ -103,6 +105,7 @@ export class Oidc {
|
|
|
103
105
|
silent_login_timeout: configuration.silent_login_timeout ?? 12000,
|
|
104
106
|
token_renew_mode: configuration.token_renew_mode ?? TokenRenewMode.access_token_or_id_token_invalid,
|
|
105
107
|
};
|
|
108
|
+
this.fetch = fetch;
|
|
106
109
|
this.configurationName = configurationName;
|
|
107
110
|
this.tokens = null;
|
|
108
111
|
this.userInfo = null;
|
|
@@ -138,9 +141,9 @@ export class Oidc {
|
|
|
138
141
|
});
|
|
139
142
|
}
|
|
140
143
|
|
|
141
|
-
static getOrCreate(configuration, name = 'default') {
|
|
142
|
-
return oidcFactory(configuration, name);
|
|
143
|
-
}
|
|
144
|
+
static getOrCreate = (fetch: Fetch = window.fetch) => (configuration, name = 'default') => {
|
|
145
|
+
return oidcFactory(configuration, name, fetch);
|
|
146
|
+
};
|
|
144
147
|
|
|
145
148
|
static get(name = 'default') {
|
|
146
149
|
const isInsideBrowser = (typeof process === 'undefined');
|
|
@@ -197,7 +200,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
197
200
|
|
|
198
201
|
const serviceWorker = await initWorkerAsync(this.configuration.service_worker_relative_url, this.configurationName);
|
|
199
202
|
const storage = serviceWorker ? window.localStorage : null;
|
|
200
|
-
return await fetchFromIssuer(fetch)(authority, this.configuration.authority_time_cache_wellknowurl_in_second ?? 60 * 60, storage, this.configuration.authority_timeout_wellknowurl_in_millisecond);
|
|
203
|
+
return await fetchFromIssuer(this.fetch)(authority, this.configuration.authority_time_cache_wellknowurl_in_second ?? 60 * 60, storage, this.configuration.authority_timeout_wellknowurl_in_millisecond);
|
|
201
204
|
};
|
|
202
205
|
this.initPromise = localFuncAsync();
|
|
203
206
|
return this.initPromise.then((result) => {
|
|
@@ -451,7 +454,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
451
454
|
};
|
|
452
455
|
const oidcServerConfiguration = await this.initAsync(authority, configuration.authority_configuration);
|
|
453
456
|
const timeoutMs = document.hidden ? 10000 : 30000 * 10;
|
|
454
|
-
const tokenResponse = await performTokenRequestAsync(oidcServerConfiguration.tokenEndpoint, details, finalExtras, tokens, configuration.token_renew_mode, timeoutMs);
|
|
457
|
+
const tokenResponse = await performTokenRequestAsync(this.fetch)(oidcServerConfiguration.tokenEndpoint, details, finalExtras, tokens, configuration.token_renew_mode, timeoutMs);
|
|
455
458
|
if (tokenResponse.success) {
|
|
456
459
|
const { isValid, reason } = isTokensOidcValid(tokenResponse.data, nonce.nonce, oidcServerConfiguration);
|
|
457
460
|
if (!isValid) {
|
|
@@ -597,7 +600,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
597
600
|
if (this.logoutPromise) {
|
|
598
601
|
return this.logoutPromise;
|
|
599
602
|
}
|
|
600
|
-
this.logoutPromise = logoutAsync(this, oidcDatabase, fetch, window, console)(callbackPathOrUrl, extras);
|
|
603
|
+
this.logoutPromise = logoutAsync(this, oidcDatabase, this.fetch, window, console)(callbackPathOrUrl, extras);
|
|
601
604
|
return this.logoutPromise.then(result => {
|
|
602
605
|
this.logoutPromise = null;
|
|
603
606
|
return result;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Fetch } from '../FetchToken';
|
|
1
2
|
import { getFromCache, setCache } from './cache.js';
|
|
2
3
|
import { deriveChallengeAsync, generateRandom } from './crypto.js';
|
|
3
4
|
import { OidcAuthorizationServiceConfiguration } from './oidc.js';
|
|
@@ -83,7 +84,7 @@ export const performRevocationRequestAsync = (fetch) => async (url, token, token
|
|
|
83
84
|
};
|
|
84
85
|
};
|
|
85
86
|
|
|
86
|
-
export const performTokenRequestAsync = async (url, details, extras, oldTokens, tokenRenewMode: string, timeoutMs = 10000) => {
|
|
87
|
+
export const performTokenRequestAsync = (fetch:Fetch) => async (url, details, extras, oldTokens, tokenRenewMode: string, timeoutMs = 10000) => {
|
|
87
88
|
for (const [key, value] of Object.entries(extras)) {
|
|
88
89
|
if (details[key] === undefined) {
|
|
89
90
|
details[key] = value;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Fetch } from '../FetchToken';
|
|
1
2
|
import { LoginCallback, Oidc } from './oidc.js';
|
|
2
3
|
import { getValidTokenAsync, Tokens, ValidToken } from './parseTokens.js';
|
|
3
4
|
import { OidcConfiguration, StringMap } from './types.js';
|
|
@@ -24,9 +25,9 @@ export class VanillaOidc {
|
|
|
24
25
|
this._oidc.publishEvent(eventName, data);
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
static getOrCreate(configuration:OidcConfiguration, name = 'default'):VanillaOidc {
|
|
28
|
-
return new VanillaOidc(Oidc.getOrCreate(configuration, name));
|
|
29
|
-
}
|
|
28
|
+
static getOrCreate = (fetch: Fetch = window.fetch) => (configuration:OidcConfiguration, name = 'default'): VanillaOidc => {
|
|
29
|
+
return new VanillaOidc(Oidc.getOrCreate(fetch)(configuration, name));
|
|
30
|
+
};
|
|
30
31
|
|
|
31
32
|
static get(name = 'default'):VanillaOidc {
|
|
32
33
|
return new VanillaOidc(Oidc.get(name));
|