oidc-spa 6.15.0 → 7.0.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 +12 -13
- package/core/Oidc.d.ts +24 -12
- package/core/createOidc.d.ts +15 -30
- package/core/createOidc.js +137 -136
- package/core/createOidc.js.map +1 -1
- package/core/handleOidcCallback.js +11 -30
- package/core/handleOidcCallback.js.map +1 -1
- package/core/loginOrGoToAuthServer.d.ts +1 -2
- package/core/loginOrGoToAuthServer.js +239 -180
- package/core/loginOrGoToAuthServer.js.map +1 -1
- package/core/loginSilent.d.ts +1 -1
- package/core/loginSilent.js +4 -4
- package/core/loginSilent.js.map +1 -1
- package/core/logoutPropagationToOtherTabs.d.ts +1 -5
- package/core/logoutPropagationToOtherTabs.js +3 -10
- package/core/logoutPropagationToOtherTabs.js.map +1 -1
- package/core/oidcClientTsUserToTokens.d.ts +1 -2
- package/core/oidcClientTsUserToTokens.js +93 -58
- package/core/oidcClientTsUserToTokens.js.map +1 -1
- package/mock/oidc.d.ts +1 -1
- package/mock/oidc.js +29 -19
- package/mock/oidc.js.map +1 -1
- package/package.json +1 -5
- package/react/react.d.ts +1 -7
- package/react/react.js +8 -59
- package/react/react.js.map +1 -1
- package/src/core/Oidc.ts +27 -14
- package/src/core/createOidc.ts +124 -129
- package/src/core/handleOidcCallback.ts +12 -56
- package/src/core/loginOrGoToAuthServer.ts +26 -12
- package/src/core/loginSilent.ts +4 -4
- package/src/core/logoutPropagationToOtherTabs.ts +6 -24
- package/src/core/oidcClientTsUserToTokens.ts +129 -82
- package/src/mock/oidc.ts +16 -6
- package/src/react/react.tsx +11 -72
- package/src/tools/readExpirationTimeInJwt.ts +4 -5
- package/tools/readExpirationTimeInJwt.js +4 -4
- package/tools/readExpirationTimeInJwt.js.map +1 -1
- package/vendor/frontend/oidc-client-ts-and-jwt-decode.js +1 -1
- package/core/debug966975.d.ts +0 -7
- package/core/debug966975.js +0 -88
- package/core/debug966975.js.map +0 -1
- package/src/core/debug966975.ts +0 -85
package/src/react/react.tsx
CHANGED
|
@@ -3,8 +3,6 @@ import {
|
|
|
3
3
|
useState,
|
|
4
4
|
createContext,
|
|
5
5
|
useContext,
|
|
6
|
-
useReducer,
|
|
7
|
-
useRef,
|
|
8
6
|
type ReactNode,
|
|
9
7
|
type ComponentType,
|
|
10
8
|
type FC,
|
|
@@ -33,10 +31,7 @@ export namespace OidcReact {
|
|
|
33
31
|
}) => Promise<never>;
|
|
34
32
|
initializationError: OidcInitializationError | undefined;
|
|
35
33
|
|
|
36
|
-
/** @deprecated: Use `const { decodedIdToken, tokens} = useOidc();` */
|
|
37
|
-
oidcTokens?: never;
|
|
38
34
|
decodedIdToken?: never;
|
|
39
|
-
tokens?: never;
|
|
40
35
|
logout?: never;
|
|
41
36
|
subscribeToAutoLogoutCountdown?: never;
|
|
42
37
|
goToAuthServer?: never;
|
|
@@ -46,10 +41,7 @@ export namespace OidcReact {
|
|
|
46
41
|
|
|
47
42
|
export type LoggedIn<DecodedIdToken extends Record<string, unknown>> = Common & {
|
|
48
43
|
isUserLoggedIn: true;
|
|
49
|
-
/** @deprecated: Use `const { decodedIdToken, tokens} = useOidc();` */
|
|
50
|
-
oidcTokens: Oidc.Tokens<DecodedIdToken>;
|
|
51
44
|
decodedIdToken: DecodedIdToken;
|
|
52
|
-
tokens: Oidc.Tokens<DecodedIdToken> | undefined;
|
|
53
45
|
logout: Oidc.LoggedIn["logout"];
|
|
54
46
|
renewTokens: Oidc.LoggedIn["renewTokens"];
|
|
55
47
|
subscribeToAutoLogoutCountdown: (
|
|
@@ -259,62 +251,22 @@ export function createOidcReactApi_dependencyInjection<
|
|
|
259
251
|
}
|
|
260
252
|
}
|
|
261
253
|
|
|
262
|
-
const [,
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
if (!oidc.isUserLoggedIn) {
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
const { unsubscribe } = oidc.subscribeToTokensChange(forceUpdate);
|
|
270
|
-
|
|
271
|
-
return unsubscribe;
|
|
272
|
-
}, [oidc]);
|
|
273
|
-
|
|
274
|
-
const tokensState_ref = useRef<{
|
|
275
|
-
isConsumerReadingTokens: boolean;
|
|
276
|
-
tokens: Oidc.Tokens<DecodedIdToken> | undefined;
|
|
277
|
-
}>({
|
|
278
|
-
isConsumerReadingTokens: false,
|
|
279
|
-
tokens: undefined
|
|
280
|
-
});
|
|
254
|
+
const [, reRenderIfDecodedIdTokenChanged] = useState(
|
|
255
|
+
!oidc.isUserLoggedIn ? undefined : oidc.getDecodedIdToken()
|
|
256
|
+
);
|
|
281
257
|
|
|
282
258
|
useEffect(() => {
|
|
283
259
|
if (!oidc.isUserLoggedIn) {
|
|
284
260
|
return;
|
|
285
261
|
}
|
|
286
262
|
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
const tokenState = tokensState_ref.current;
|
|
293
|
-
|
|
294
|
-
tokenState.tokens = tokens;
|
|
295
|
-
|
|
296
|
-
if (tokenState.isConsumerReadingTokens) {
|
|
297
|
-
forceUpdate();
|
|
298
|
-
}
|
|
299
|
-
};
|
|
263
|
+
const { unsubscribe } = oidc.subscribeToTokensChange(() =>
|
|
264
|
+
reRenderIfDecodedIdTokenChanged(oidc.getDecodedIdToken())
|
|
265
|
+
);
|
|
300
266
|
|
|
301
|
-
|
|
267
|
+
reRenderIfDecodedIdTokenChanged(oidc.getDecodedIdToken());
|
|
302
268
|
|
|
303
|
-
|
|
304
|
-
if (!isActive) {
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
307
|
-
updateTokens(tokens);
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
const { unsubscribe } = oidc.subscribeToTokensChange(tokens => {
|
|
311
|
-
updateTokens(tokens);
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
return () => {
|
|
315
|
-
isActive = false;
|
|
316
|
-
unsubscribe();
|
|
317
|
-
};
|
|
269
|
+
return unsubscribe;
|
|
318
270
|
}, []);
|
|
319
271
|
|
|
320
272
|
const common: OidcReact.Common = {
|
|
@@ -334,13 +286,7 @@ export function createOidcReactApi_dependencyInjection<
|
|
|
334
286
|
const oidcReact: OidcReact.LoggedIn<DecodedIdToken> = {
|
|
335
287
|
...common,
|
|
336
288
|
isUserLoggedIn: true,
|
|
337
|
-
oidcTokens: oidc.getTokens(),
|
|
338
289
|
decodedIdToken: oidc.getDecodedIdToken(),
|
|
339
|
-
get tokens() {
|
|
340
|
-
const tokensState = tokensState_ref.current;
|
|
341
|
-
tokensState.isConsumerReadingTokens = true;
|
|
342
|
-
return tokensState.tokens;
|
|
343
|
-
},
|
|
344
290
|
logout: oidc.logout,
|
|
345
291
|
renewTokens: oidc.renewTokens,
|
|
346
292
|
subscribeToAutoLogoutCountdown: oidc.subscribeToAutoLogoutCountdown,
|
|
@@ -422,17 +368,10 @@ export function createOidcReactApi_dependencyInjection<
|
|
|
422
368
|
return oidc;
|
|
423
369
|
});
|
|
424
370
|
|
|
425
|
-
|
|
371
|
+
function getOidc(): Promise<Oidc<DecodedIdToken>> {
|
|
426
372
|
dReadyToCreate.resolve();
|
|
427
373
|
|
|
428
|
-
|
|
429
|
-
const oidc = await prOidc;
|
|
430
|
-
|
|
431
|
-
if (oidc.isUserLoggedIn) {
|
|
432
|
-
await oidc.getTokens_next();
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
return oidc;
|
|
374
|
+
return prOidc;
|
|
436
375
|
}
|
|
437
376
|
|
|
438
377
|
const oidcReact: OidcReactApi<DecodedIdToken, false> = {
|
|
@@ -449,7 +388,7 @@ export function createOidcReactApi_dependencyInjection<
|
|
|
449
388
|
|
|
450
389
|
/** @see: https://docs.oidc-spa.dev/v/v6/usage#react-api */
|
|
451
390
|
export function createReactOidc<
|
|
452
|
-
DecodedIdToken extends Record<string, unknown> =
|
|
391
|
+
DecodedIdToken extends Record<string, unknown> = Oidc.Tokens.DecodedIdToken_base,
|
|
453
392
|
AutoLogin extends boolean = false
|
|
454
393
|
>(params: ValueOrAsyncGetter<ParamsOfCreateOidc<DecodedIdToken, AutoLogin>>) {
|
|
455
394
|
return createOidcReactApi_dependencyInjection(params, createOidc);
|
|
@@ -3,15 +3,14 @@ import { assert } from "../vendor/frontend/tsafe";
|
|
|
3
3
|
|
|
4
4
|
// Return undefined if token provided wasn't a JWT or if it hasn't an exp claim number
|
|
5
5
|
export function readExpirationTimeInJwt(token: string): number | undefined {
|
|
6
|
-
let
|
|
6
|
+
let exp: number;
|
|
7
7
|
|
|
8
8
|
try {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
assert(typeof expirationTime === "number" && !isNaN(expirationTime));
|
|
9
|
+
exp = decodeJwt<{ exp: number }>(token).exp;
|
|
10
|
+
assert(typeof exp === "number");
|
|
12
11
|
} catch {
|
|
13
12
|
return undefined;
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
return
|
|
15
|
+
return exp * 1000;
|
|
17
16
|
}
|
|
@@ -5,14 +5,14 @@ var decodeJwt_1 = require("./decodeJwt");
|
|
|
5
5
|
var tsafe_1 = require("../vendor/frontend/tsafe");
|
|
6
6
|
// Return undefined if token provided wasn't a JWT or if it hasn't an exp claim number
|
|
7
7
|
function readExpirationTimeInJwt(token) {
|
|
8
|
-
var
|
|
8
|
+
var exp;
|
|
9
9
|
try {
|
|
10
|
-
|
|
11
|
-
(0, tsafe_1.assert)(typeof
|
|
10
|
+
exp = (0, decodeJwt_1.decodeJwt)(token).exp;
|
|
11
|
+
(0, tsafe_1.assert)(typeof exp === "number");
|
|
12
12
|
}
|
|
13
13
|
catch (_a) {
|
|
14
14
|
return undefined;
|
|
15
15
|
}
|
|
16
|
-
return
|
|
16
|
+
return exp * 1000;
|
|
17
17
|
}
|
|
18
18
|
//# sourceMappingURL=readExpirationTimeInJwt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readExpirationTimeInJwt.js","sourceRoot":"","sources":["../src/tools/readExpirationTimeInJwt.ts"],"names":[],"mappings":";;AAIA,
|
|
1
|
+
{"version":3,"file":"readExpirationTimeInJwt.js","sourceRoot":"","sources":["../src/tools/readExpirationTimeInJwt.ts"],"names":[],"mappings":";;AAIA,0DAWC;AAfD,yCAAwC;AACxC,kDAAkD;AAElD,sFAAsF;AACtF,SAAgB,uBAAuB,CAAC,KAAa;IACjD,IAAI,GAAW,CAAC;IAEhB,IAAI,CAAC;QACD,GAAG,GAAG,IAAA,qBAAS,EAAkB,KAAK,CAAC,CAAC,GAAG,CAAC;QAC5C,IAAA,cAAM,EAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC;IACpC,CAAC;IAAC,WAAM,CAAC;QACL,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,OAAO,GAAG,GAAG,IAAI,CAAC;AACtB,CAAC"}
|