oidc-spa 8.2.8 → 8.2.10
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 +104 -81
- package/core/createOidc.js +48 -30
- package/core/createOidc.js.map +1 -1
- package/core/diagnostic.d.ts +0 -1
- package/core/diagnostic.js +1 -4
- package/core/diagnostic.js.map +1 -1
- package/core/persistedAuthState.js +6 -1
- package/core/persistedAuthState.js.map +1 -1
- package/esm/angular.d.ts +1 -1
- package/esm/angular.js +7 -7
- package/esm/angular.js.map +1 -1
- package/esm/core/createOidc.js +49 -31
- package/esm/core/createOidc.js.map +1 -1
- package/esm/core/diagnostic.d.ts +0 -1
- package/esm/core/diagnostic.js +1 -4
- package/esm/core/diagnostic.js.map +1 -1
- package/esm/core/persistedAuthState.js +6 -1
- package/esm/core/persistedAuthState.js.map +1 -1
- package/esm/react-spa/createOidcSpaApi.js +2 -2
- package/esm/react-spa/createOidcSpaApi.js.map +1 -1
- package/esm/react-spa/types.d.ts +1 -1
- package/esm/tanstack-start/react/createOidcSpaApi.js +2 -2
- package/esm/tanstack-start/react/createOidcSpaApi.js.map +1 -1
- package/esm/tanstack-start/react/types.d.ts +8 -7
- package/esm/tools/MaybeAsync.d.ts +1 -0
- package/esm/tools/MaybeAsync.js +2 -0
- package/esm/tools/MaybeAsync.js.map +1 -0
- package/package.json +1 -1
- package/react-spa/createOidcSpaApi.js +2 -2
- package/react-spa/createOidcSpaApi.js.map +1 -1
- package/react-spa/types.d.ts +1 -1
- package/src/angular.ts +7 -8
- package/src/core/createOidc.ts +62 -35
- package/src/core/diagnostic.ts +1 -6
- package/src/core/persistedAuthState.ts +10 -3
- package/src/react-spa/createOidcSpaApi.tsx +2 -2
- package/src/react-spa/types.tsx +1 -1
- package/src/tanstack-start/react/createOidcSpaApi.tsx +12 -5
- package/src/tanstack-start/react/types.tsx +20 -7
- package/src/tools/MaybeAsync.ts +1 -0
- package/tools/MaybeAsync.d.ts +1 -0
- package/tools/MaybeAsync.js +3 -0
- package/tools/MaybeAsync.js.map +1 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { typeGuard } from "../tools/tsafe/typeGuard";
|
|
2
2
|
import { id } from "../tools/tsafe/id";
|
|
3
|
+
import { INFINITY_TIME } from "../tools/INFINITY_TIME";
|
|
3
4
|
|
|
4
5
|
function getKey(params: { configId: string }) {
|
|
5
6
|
const { configId } = params;
|
|
@@ -82,10 +83,16 @@ export function persistAuthState(params: {
|
|
|
82
83
|
return Date.now() + idleSessionLifetimeInSeconds * 1000;
|
|
83
84
|
})();
|
|
84
85
|
|
|
85
|
-
|
|
86
|
-
untilTime_real ??
|
|
87
|
-
unitTime_userOverwrite ??
|
|
86
|
+
const untilTime = Math.min(
|
|
87
|
+
untilTime_real ?? INFINITY_TIME,
|
|
88
|
+
unitTime_userOverwrite ?? INFINITY_TIME
|
|
88
89
|
);
|
|
90
|
+
|
|
91
|
+
if (untilTime === INFINITY_TIME) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return untilTime;
|
|
89
96
|
})()
|
|
90
97
|
});
|
|
91
98
|
case "explicitly logged out":
|
|
@@ -46,7 +46,7 @@ export function createOidcSpaApi<
|
|
|
46
46
|
}
|
|
47
47
|
assert<Equals<typeof paramsOfBootstrap.implementation, "real">>;
|
|
48
48
|
|
|
49
|
-
const {
|
|
49
|
+
const { warnUserSecondsBeforeAutoLogout = 45 } = paramsOfBootstrap;
|
|
50
50
|
|
|
51
51
|
if (
|
|
52
52
|
oidcCoreOrInitializationError === undefined ||
|
|
@@ -69,7 +69,7 @@ export function createOidcSpaApi<
|
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
if (secondsLeft >
|
|
72
|
+
if (secondsLeft > warnUserSecondsBeforeAutoLogout) {
|
|
73
73
|
return {
|
|
74
74
|
shouldDisplayWarning: false
|
|
75
75
|
};
|
package/src/react-spa/types.tsx
CHANGED
|
@@ -158,7 +158,7 @@ export namespace ParamsOfBootstrap {
|
|
|
158
158
|
* This is a server policy (that can be overwrote by idleSessionLifetimeInSeconds)
|
|
159
159
|
* See: https://docs.oidc-spa.dev/v/v8/auto-logout
|
|
160
160
|
*/
|
|
161
|
-
|
|
161
|
+
warnUserSecondsBeforeAutoLogout?: number;
|
|
162
162
|
/**
|
|
163
163
|
* This parameter defines after how many seconds of inactivity the user should be
|
|
164
164
|
* logged out automatically.
|
|
@@ -31,6 +31,7 @@ import { getRequest, setResponseHeader, setResponseStatus } from "@tanstack/reac
|
|
|
31
31
|
import { toFullyQualifiedUrl } from "../../tools/toFullyQualifiedUrl";
|
|
32
32
|
import { UnifiedClientRetryForSsrLoadersError } from "./rfcUnifiedClientRetryForSsrLoaders/UnifiedClientRetryForSsrLoadersError";
|
|
33
33
|
import { setDesiredPostLoginRedirectUrl } from "../../core/desiredPostLoginRedirectUrl";
|
|
34
|
+
import type { MaybeAsync } from "../../tools/MaybeAsync";
|
|
34
35
|
|
|
35
36
|
export function createOidcSpaApi<
|
|
36
37
|
AutoLogin extends boolean,
|
|
@@ -77,7 +78,7 @@ export function createOidcSpaApi<
|
|
|
77
78
|
}
|
|
78
79
|
assert<Equals<typeof paramsOfBootstrap.implementation, "real">>;
|
|
79
80
|
|
|
80
|
-
const {
|
|
81
|
+
const { warnUserSecondsBeforeAutoLogout = 45 } = paramsOfBootstrap;
|
|
81
82
|
|
|
82
83
|
if (
|
|
83
84
|
oidcCoreOrInitializationError === undefined ||
|
|
@@ -100,7 +101,7 @@ export function createOidcSpaApi<
|
|
|
100
101
|
};
|
|
101
102
|
}
|
|
102
103
|
|
|
103
|
-
if (secondsLeft >
|
|
104
|
+
if (secondsLeft > warnUserSecondsBeforeAutoLogout) {
|
|
104
105
|
return {
|
|
105
106
|
shouldDisplayWarning: false
|
|
106
107
|
};
|
|
@@ -823,7 +824,9 @@ export function createOidcSpaApi<
|
|
|
823
824
|
|
|
824
825
|
function createFunctionMiddlewareServerFn(params?: {
|
|
825
826
|
assert?: "user logged in";
|
|
826
|
-
hasRequiredClaims?: (params: {
|
|
827
|
+
hasRequiredClaims?: (params: {
|
|
828
|
+
accessTokenClaims: AccessTokenClaims;
|
|
829
|
+
}) => MaybeAsync<boolean | undefined>;
|
|
827
830
|
}) {
|
|
828
831
|
return async (options: {
|
|
829
832
|
next: (options: { context: { oidc: OidcServerContext<AccessTokenClaims> } }) => any;
|
|
@@ -972,7 +975,9 @@ export function createOidcSpaApi<
|
|
|
972
975
|
|
|
973
976
|
function oidcRequestMiddleware(params?: {
|
|
974
977
|
assert?: "user logged in";
|
|
975
|
-
hasRequiredClaims?: (params: {
|
|
978
|
+
hasRequiredClaims?: (params: {
|
|
979
|
+
accessTokenClaims: AccessTokenClaims;
|
|
980
|
+
}) => MaybeAsync<boolean | undefined>;
|
|
976
981
|
}) {
|
|
977
982
|
return createMiddleware({ type: "request" }).server<{
|
|
978
983
|
oidc: OidcServerContext<AccessTokenClaims>;
|
|
@@ -981,7 +986,9 @@ export function createOidcSpaApi<
|
|
|
981
986
|
|
|
982
987
|
function oidcFnMiddleware(params?: {
|
|
983
988
|
assert?: "user logged in";
|
|
984
|
-
hasRequiredClaims?: (params: {
|
|
989
|
+
hasRequiredClaims?: (params: {
|
|
990
|
+
accessTokenClaims: AccessTokenClaims;
|
|
991
|
+
}) => MaybeAsync<boolean | undefined>;
|
|
985
992
|
}) {
|
|
986
993
|
return createMiddleware({ type: "function" })
|
|
987
994
|
.client(async ({ next }) => {
|
|
@@ -3,6 +3,7 @@ import type { Oidc as Oidc_core, OidcInitializationError } from "../../core";
|
|
|
3
3
|
import type { FunctionMiddlewareAfterServer, RequestMiddlewareAfterServer } from "@tanstack/react-start";
|
|
4
4
|
import type { GetterOrDirectValue } from "../../tools/GetterOrDirectValue";
|
|
5
5
|
import type { OidcMetadata } from "../../core/OidcMetadata";
|
|
6
|
+
import type { MaybeAsync } from "../../tools/MaybeAsync";
|
|
6
7
|
|
|
7
8
|
export type CreateOidcComponent<DecodedIdToken> = <
|
|
8
9
|
Assert extends "user logged in" | "user not logged in" | undefined,
|
|
@@ -148,13 +149,17 @@ export namespace GetOidc {
|
|
|
148
149
|
export type OidcFnMiddleware<AccessTokenClaims> = {
|
|
149
150
|
(params?: {
|
|
150
151
|
assert?: undefined;
|
|
151
|
-
hasRequiredClaims?: (params: {
|
|
152
|
+
hasRequiredClaims?: (params: {
|
|
153
|
+
accessTokenClaims: AccessTokenClaims;
|
|
154
|
+
}) => MaybeAsync<boolean | undefined>;
|
|
152
155
|
}): OidcFnMiddleware.TanStackFnMiddleware<{
|
|
153
156
|
oidc: OidcServerContext<AccessTokenClaims>;
|
|
154
157
|
}>;
|
|
155
158
|
(params?: {
|
|
156
159
|
assert?: "user logged in";
|
|
157
|
-
hasRequiredClaims?: (params: {
|
|
160
|
+
hasRequiredClaims?: (params: {
|
|
161
|
+
accessTokenClaims: AccessTokenClaims;
|
|
162
|
+
}) => MaybeAsync<boolean | undefined>;
|
|
158
163
|
}): OidcFnMiddleware.TanStackFnMiddleware<{
|
|
159
164
|
oidc: OidcServerContext.LoggedIn<AccessTokenClaims>;
|
|
160
165
|
}>;
|
|
@@ -163,7 +168,9 @@ export type OidcFnMiddleware<AccessTokenClaims> = {
|
|
|
163
168
|
export namespace OidcFnMiddleware {
|
|
164
169
|
export type WithAutoLogin<AccessTokenClaims> = (params?: {
|
|
165
170
|
assert?: "user logged in";
|
|
166
|
-
hasRequiredClaims?: (params: {
|
|
171
|
+
hasRequiredClaims?: (params: {
|
|
172
|
+
accessTokenClaims: AccessTokenClaims;
|
|
173
|
+
}) => MaybeAsync<boolean | undefined>;
|
|
167
174
|
}) => TanStackFnMiddleware<{
|
|
168
175
|
oidc: OidcServerContext.LoggedIn<AccessTokenClaims>;
|
|
169
176
|
}>;
|
|
@@ -201,13 +208,17 @@ export namespace OidcServerContext {
|
|
|
201
208
|
export type OidcRequestMiddleware<AccessTokenClaims> = {
|
|
202
209
|
(params?: {
|
|
203
210
|
assert?: undefined;
|
|
204
|
-
hasRequiredClaims?: (params: {
|
|
211
|
+
hasRequiredClaims?: (params: {
|
|
212
|
+
accessTokenClaims: AccessTokenClaims;
|
|
213
|
+
}) => MaybeAsync<boolean | undefined>;
|
|
205
214
|
}): OidcRequestMiddleware.TanstackRequestMiddleware<{
|
|
206
215
|
oidc: OidcServerContext<AccessTokenClaims>;
|
|
207
216
|
}>;
|
|
208
217
|
(params?: {
|
|
209
218
|
assert?: "user logged in";
|
|
210
|
-
hasRequiredClaims?: (params: {
|
|
219
|
+
hasRequiredClaims?: (params: {
|
|
220
|
+
accessTokenClaims: AccessTokenClaims;
|
|
221
|
+
}) => MaybeAsync<boolean | undefined>;
|
|
211
222
|
}): OidcRequestMiddleware.TanstackRequestMiddleware<{
|
|
212
223
|
oidc: OidcServerContext.LoggedIn<AccessTokenClaims>;
|
|
213
224
|
}>;
|
|
@@ -216,7 +227,9 @@ export type OidcRequestMiddleware<AccessTokenClaims> = {
|
|
|
216
227
|
export namespace OidcRequestMiddleware {
|
|
217
228
|
export type WithAutoLogin<AccessTokenClaims> = (params?: {
|
|
218
229
|
assert?: "user logged in";
|
|
219
|
-
hasRequiredClaims?: (params: {
|
|
230
|
+
hasRequiredClaims?: (params: {
|
|
231
|
+
accessTokenClaims: AccessTokenClaims;
|
|
232
|
+
}) => MaybeAsync<boolean | undefined>;
|
|
220
233
|
}) => TanstackRequestMiddleware<{
|
|
221
234
|
oidc: OidcServerContext.LoggedIn<AccessTokenClaims>;
|
|
222
235
|
}>;
|
|
@@ -251,7 +264,7 @@ export namespace ParamsOfBootstrap {
|
|
|
251
264
|
* This is a server policy (that can be overwrote by idleSessionLifetimeInSeconds)
|
|
252
265
|
* See: https://docs.oidc-spa.dev/v/v8/auto-logout
|
|
253
266
|
*/
|
|
254
|
-
|
|
267
|
+
warnUserSecondsBeforeAutoLogout?: number;
|
|
255
268
|
/**
|
|
256
269
|
* This parameter defines after how many seconds of inactivity the user should be
|
|
257
270
|
* logged out automatically.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type MaybeAsync<T> = Promise<T> | T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type MaybeAsync<T> = Promise<T> | T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MaybeAsync.js","sourceRoot":"","sources":["../src/tools/MaybeAsync.ts"],"names":[],"mappings":""}
|