oidc-spa 8.1.10 → 8.1.12
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/backend.d.ts +27 -6
- package/backend.js +124 -139
- package/backend.js.map +1 -1
- package/core/Oidc.d.ts +28 -4
- package/core/createOidc.d.ts +12 -3
- package/core/createOidc.js +1 -1
- package/core/createOidc.js.map +1 -1
- package/core/earlyInit.d.ts +1 -0
- package/core/earlyInit.js +11 -4
- package/core/earlyInit.js.map +1 -1
- package/core/loginOrGoToAuthServer.js +8 -3
- package/core/loginOrGoToAuthServer.js.map +1 -1
- package/core/oidcClientTsUserToTokens.d.ts +1 -1
- package/core/oidcClientTsUserToTokens.js.map +1 -1
- package/core/requiredPostHydrationReplaceNavigationUrl.d.ts +6 -0
- package/core/requiredPostHydrationReplaceNavigationUrl.js +12 -0
- package/core/requiredPostHydrationReplaceNavigationUrl.js.map +1 -0
- package/entrypoint.d.ts +1 -0
- package/entrypoint.js +3 -1
- package/entrypoint.js.map +1 -1
- package/esm/angular.d.ts +14 -4
- package/esm/angular.js +155 -10
- package/esm/angular.js.map +1 -1
- package/esm/backend.d.ts +48 -0
- package/esm/backend.js +259 -0
- package/esm/backend.js.map +1 -0
- package/esm/core/Oidc.d.ts +28 -4
- package/esm/core/createOidc.d.ts +12 -3
- package/esm/core/createOidc.js +1 -1
- package/esm/core/createOidc.js.map +1 -1
- package/esm/core/earlyInit.d.ts +1 -0
- package/esm/core/earlyInit.js +11 -4
- package/esm/core/earlyInit.js.map +1 -1
- package/esm/core/loginOrGoToAuthServer.js +8 -3
- package/esm/core/loginOrGoToAuthServer.js.map +1 -1
- package/esm/core/oidcClientTsUserToTokens.d.ts +1 -1
- package/esm/core/oidcClientTsUserToTokens.js.map +1 -1
- package/esm/core/requiredPostHydrationReplaceNavigationUrl.d.ts +6 -0
- package/esm/core/requiredPostHydrationReplaceNavigationUrl.js +8 -0
- package/esm/core/requiredPostHydrationReplaceNavigationUrl.js.map +1 -0
- package/esm/entrypoint.d.ts +1 -0
- package/esm/entrypoint.js +1 -0
- package/esm/entrypoint.js.map +1 -1
- package/esm/mock/oidc.d.ts +1 -1
- package/esm/mock/oidc.js.map +1 -1
- package/esm/react/react.d.ts +1 -1
- package/esm/tanstack-start/react/accessTokenValidation_rfc9068.d.ts +12 -0
- package/esm/tanstack-start/react/accessTokenValidation_rfc9068.js +95 -0
- package/esm/tanstack-start/react/accessTokenValidation_rfc9068.js.map +1 -0
- package/esm/tanstack-start/react/apiBuilder.d.ts +27 -0
- package/esm/tanstack-start/react/apiBuilder.js +58 -0
- package/esm/tanstack-start/react/apiBuilder.js.map +1 -0
- package/esm/tanstack-start/react/createOidcSpaApi.d.ts +9 -0
- package/esm/tanstack-start/react/createOidcSpaApi.js +679 -0
- package/esm/tanstack-start/react/createOidcSpaApi.js.map +1 -0
- package/esm/tanstack-start/react/index.d.ts +3 -0
- package/esm/tanstack-start/react/index.js +4 -0
- package/esm/tanstack-start/react/index.js.map +1 -0
- package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/UnifiedClientRetryForSsrLoadersError.d.ts +4 -0
- package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/UnifiedClientRetryForSsrLoadersError.js +8 -0
- package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/UnifiedClientRetryForSsrLoadersError.js.map +1 -0
- package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/enableUnifiedClientRetryForSsrLoaders.d.ts +4 -0
- package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/enableUnifiedClientRetryForSsrLoaders.js +86 -0
- package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/enableUnifiedClientRetryForSsrLoaders.js.map +1 -0
- package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/entrypoint.d.ts +1 -0
- package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/entrypoint.js +13 -0
- package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/entrypoint.js.map +1 -0
- package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/index.d.ts +2 -0
- package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/index.js +3 -0
- package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/index.js.map +1 -0
- package/esm/tanstack-start/react/types.d.ts +355 -0
- package/esm/tanstack-start/react/types.js +2 -0
- package/esm/tanstack-start/react/types.js.map +1 -0
- package/esm/tanstack-start/react/withHandlingOidcPostLoginNavigation.d.ts +2 -0
- package/esm/tanstack-start/react/withHandlingOidcPostLoginNavigation.js +25 -0
- package/esm/tanstack-start/react/withHandlingOidcPostLoginNavigation.js.map +1 -0
- package/esm/tools/GetterOrDirectValue.d.ts +1 -0
- package/esm/tools/GetterOrDirectValue.js +2 -0
- package/esm/tools/GetterOrDirectValue.js.map +1 -0
- package/esm/tools/ZodSchemaLike.d.ts +3 -0
- package/esm/tools/ZodSchemaLike.js +2 -0
- package/esm/tools/ZodSchemaLike.js.map +1 -0
- package/esm/tools/inferIsViteDev.d.ts +1 -0
- package/esm/tools/inferIsViteDev.js +6 -0
- package/esm/tools/inferIsViteDev.js.map +1 -0
- package/esm/tools/infer_import_meta_env_BASE_URL.d.ts +1 -0
- package/esm/tools/infer_import_meta_env_BASE_URL.js +15 -0
- package/esm/tools/infer_import_meta_env_BASE_URL.js.map +1 -0
- package/esm/tools/tsafe/uncapitalize.d.ts +2 -0
- package/esm/tools/tsafe/uncapitalize.js +5 -0
- package/esm/tools/tsafe/uncapitalize.js.map +1 -0
- package/esm/vendor/backend/evt.d.ts +2 -0
- package/esm/vendor/backend/evt.js +3286 -0
- package/esm/vendor/backend/jose.d.ts +1 -0
- package/esm/vendor/backend/jose.js +3546 -0
- package/esm/vendor/backend/tsafe.d.ts +5 -0
- package/esm/vendor/backend/tsafe.js +68 -0
- package/esm/vendor/backend/zod.d.ts +1 -0
- package/esm/vendor/backend/zod.js +4023 -0
- package/esm/vendor/frontend/worker-timers.js +261 -1
- package/mock/oidc.d.ts +1 -1
- package/mock/oidc.js.map +1 -1
- package/package.json +40 -4
- package/react/react.d.ts +1 -1
- package/src/angular.ts +224 -9
- package/src/backend.ts +201 -166
- package/src/core/Oidc.ts +41 -11
- package/src/core/createOidc.ts +12 -3
- package/src/core/earlyInit.ts +19 -4
- package/src/core/loginOrGoToAuthServer.ts +11 -3
- package/src/core/oidcClientTsUserToTokens.ts +2 -2
- package/src/core/requiredPostHydrationReplaceNavigationUrl.ts +11 -0
- package/src/entrypoint.ts +1 -0
- package/src/mock/oidc.ts +2 -2
- package/src/react/react.tsx +1 -1
- package/src/tanstack-start/react/accessTokenValidation_rfc9068.ts +135 -0
- package/src/tanstack-start/react/apiBuilder.ts +151 -0
- package/src/tanstack-start/react/createOidcSpaApi.tsx +1011 -0
- package/src/tanstack-start/react/index.ts +5 -0
- package/src/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/UnifiedClientRetryForSsrLoadersError.ts +8 -0
- package/src/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/enableUnifiedClientRetryForSsrLoaders.tsx +127 -0
- package/src/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/entrypoint.ts +15 -0
- package/src/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/index.ts +2 -0
- package/src/tanstack-start/react/types.tsx +415 -0
- package/src/tanstack-start/react/withHandlingOidcPostLoginNavigation.tsx +35 -0
- package/src/tools/GetterOrDirectValue.ts +1 -0
- package/src/tools/ZodSchemaLike.ts +3 -0
- package/src/tools/getThisCodebaseRootDirPath_cjs.ts +19 -0
- package/src/tools/inferIsViteDev.ts +6 -0
- package/src/tools/infer_import_meta_env_BASE_URL.ts +19 -0
- package/src/tools/tsafe/uncapitalize.ts +4 -0
- package/src/vendor/backend/jose.ts +1 -0
- package/src/vendor/build-runtime/babel.ts +6 -0
- package/src/vendor/build-runtime/magic-string.ts +3 -0
- package/src/vite-plugin/detectProjectType.ts +20 -0
- package/src/vite-plugin/excludeModuleExportFromOptimizedDeps.ts +20 -0
- package/src/vite-plugin/handleClientEntrypoint.ts +260 -0
- package/src/vite-plugin/index.ts +1 -0
- package/src/vite-plugin/transformCreateFileRoute.ts +240 -0
- package/src/vite-plugin/vite-plugin.ts +54 -0
- package/tools/GetterOrDirectValue.d.ts +1 -0
- package/tools/GetterOrDirectValue.js +3 -0
- package/tools/GetterOrDirectValue.js.map +1 -0
- package/tools/ZodSchemaLike.d.ts +3 -0
- package/tools/ZodSchemaLike.js +3 -0
- package/tools/ZodSchemaLike.js.map +1 -0
- package/tools/getThisCodebaseRootDirPath_cjs.d.ts +2 -0
- package/tools/getThisCodebaseRootDirPath_cjs.js +53 -0
- package/tools/getThisCodebaseRootDirPath_cjs.js.map +1 -0
- package/tools/tsafe/uncapitalize.d.ts +2 -0
- package/tools/tsafe/uncapitalize.js +8 -0
- package/tools/tsafe/uncapitalize.js.map +1 -0
- package/vendor/backend/jose.d.ts +1 -0
- package/vendor/backend/jose.js +3 -0
- package/vendor/build-runtime/babel.d.ts +6 -0
- package/vendor/build-runtime/babel.js +3 -0
- package/vendor/build-runtime/magic-string.d.ts +2 -0
- package/vendor/build-runtime/magic-string.js +2 -0
- package/vendor/frontend/oidc-client-ts.js +0 -2
- package/vite-plugin/detectProjectType.d.ts +10 -0
- package/vite-plugin/detectProjectType.js +15 -0
- package/vite-plugin/detectProjectType.js.map +1 -0
- package/vite-plugin/excludeModuleExportFromOptimizedDeps.d.ts +4 -0
- package/vite-plugin/excludeModuleExportFromOptimizedDeps.js +50 -0
- package/vite-plugin/excludeModuleExportFromOptimizedDeps.js.map +1 -0
- package/vite-plugin/handleClientEntrypoint.d.ts +10 -0
- package/vite-plugin/handleClientEntrypoint.js +211 -0
- package/vite-plugin/handleClientEntrypoint.js.map +1 -0
- package/vite-plugin/index.d.ts +1 -0
- package/vite-plugin/index.js +6 -0
- package/vite-plugin/index.js.map +1 -0
- package/vite-plugin/transformCreateFileRoute.d.ts +10 -0
- package/vite-plugin/transformCreateFileRoute.js +173 -0
- package/vite-plugin/transformCreateFileRoute.js.map +1 -0
- package/vite-plugin/vite-plugin.d.ts +5 -0
- package/vite-plugin/vite-plugin.js +46 -0
- package/vite-plugin/vite-plugin.js.map +1 -0
- package/src/vendor/backend/jsonwebtoken.ts +0 -1
- package/src/vendor/backend/node-fetch.ts +0 -2
- package/src/vendor/backend/node-jose.ts +0 -1
- package/vendor/backend/jsonwebtoken.d.ts +0 -1
- package/vendor/backend/jsonwebtoken.js +0 -3
- package/vendor/backend/node-fetch.d.ts +0 -2
- package/vendor/backend/node-fetch.js +0 -2
- package/vendor/backend/node-jose.d.ts +0 -1
- package/vendor/backend/node-jose.js +0 -3
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const ERROR_MESSAGE_SINGULAR_STRING = "__RETRY_ON_CLIENT_SENTINEL__";
|
|
2
|
+
|
|
3
|
+
export class UnifiedClientRetryForSsrLoadersError extends Error {
|
|
4
|
+
constructor(message: string) {
|
|
5
|
+
super(`(${ERROR_MESSAGE_SINGULAR_STRING}) ${message}`);
|
|
6
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { type createFileRoute, useRouter } from "@tanstack/react-router";
|
|
3
|
+
import { ERROR_MESSAGE_SINGULAR_STRING } from "./UnifiedClientRetryForSsrLoadersError";
|
|
4
|
+
import { inferIsViteDev } from "../../../tools/inferIsViteDev";
|
|
5
|
+
|
|
6
|
+
type OptionsOfCreateFileRoute = NonNullable<Parameters<ReturnType<typeof createFileRoute>>[0]>;
|
|
7
|
+
|
|
8
|
+
export function enableUnifiedClientRetryForSsrLoaders<Options extends OptionsOfCreateFileRoute>(
|
|
9
|
+
options: Options
|
|
10
|
+
): Options {
|
|
11
|
+
if (options.ssr === false) {
|
|
12
|
+
return options;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
common_case_exception: {
|
|
16
|
+
const { beforeLoad } = options;
|
|
17
|
+
|
|
18
|
+
if (beforeLoad === undefined) {
|
|
19
|
+
break common_case_exception;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// @ts-expect-error
|
|
23
|
+
if (!beforeLoad.__isOidcSpaEnforceLogin) {
|
|
24
|
+
break common_case_exception;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
...options,
|
|
29
|
+
ssr: false
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function ErrorComponentWithUnifiedClientRetryForSsrLoader(
|
|
34
|
+
props: Parameters<
|
|
35
|
+
Exclude<OptionsOfCreateFileRoute["errorComponent"], null | false | undefined>
|
|
36
|
+
>[0]
|
|
37
|
+
) {
|
|
38
|
+
unified_client_retry: {
|
|
39
|
+
const { error } = props;
|
|
40
|
+
|
|
41
|
+
const isSentinelError =
|
|
42
|
+
error instanceof Error && error.message.includes(ERROR_MESSAGE_SINGULAR_STRING);
|
|
43
|
+
|
|
44
|
+
const router = useRouter();
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (!isSentinelError) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const isDev = inferIsViteDev();
|
|
52
|
+
|
|
53
|
+
console.info(
|
|
54
|
+
[
|
|
55
|
+
`oidc-spa: The '500 (Internal Server Error)'${
|
|
56
|
+
!isDev ? "" : " and 'Warning: Error in route match'"
|
|
57
|
+
} above can be safely ignored.`,
|
|
58
|
+
"\nIt's not a real error, but an expected and recoverable case.",
|
|
59
|
+
"\nThis happens when a server action requires user authentication",
|
|
60
|
+
"before the client has finished establishing it."
|
|
61
|
+
].join(" ")
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
router.invalidate();
|
|
65
|
+
}, []);
|
|
66
|
+
|
|
67
|
+
if (!isSentinelError) {
|
|
68
|
+
break unified_client_retry;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const PendingComponent = options.pendingComponent;
|
|
72
|
+
|
|
73
|
+
if (PendingComponent === undefined) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return <PendingComponent />;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Default behavior
|
|
81
|
+
{
|
|
82
|
+
const { errorComponent } = options;
|
|
83
|
+
|
|
84
|
+
if (errorComponent === false) {
|
|
85
|
+
queueMicrotask(() => {
|
|
86
|
+
throw props.error;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (errorComponent === null || errorComponent === undefined) {
|
|
93
|
+
throw props.error;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const ErrorComponent = errorComponent;
|
|
97
|
+
|
|
98
|
+
return <ErrorComponent {...props} />;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
forward_properties: {
|
|
103
|
+
const { errorComponent } = options;
|
|
104
|
+
|
|
105
|
+
if (!errorComponent) {
|
|
106
|
+
ErrorComponentWithUnifiedClientRetryForSsrLoader.displayName =
|
|
107
|
+
ErrorComponentWithUnifiedClientRetryForSsrLoader.name;
|
|
108
|
+
break forward_properties;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const ErrorComponent = errorComponent;
|
|
112
|
+
|
|
113
|
+
ErrorComponentWithUnifiedClientRetryForSsrLoader.displayName = `${
|
|
114
|
+
(ErrorComponent as any).displayName ?? ErrorComponent.name ?? "ErrorComponent"
|
|
115
|
+
}WithUnifiedClientRetryForSsrLoader`;
|
|
116
|
+
|
|
117
|
+
if (ErrorComponent.preload !== undefined) {
|
|
118
|
+
ErrorComponentWithUnifiedClientRetryForSsrLoader.preload =
|
|
119
|
+
ErrorComponent.preload.bind(ErrorComponent);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
...options,
|
|
125
|
+
errorComponent: ErrorComponentWithUnifiedClientRetryForSsrLoader
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ERROR_MESSAGE_SINGULAR_STRING } from "./UnifiedClientRetryForSsrLoadersError";
|
|
2
|
+
|
|
3
|
+
export function preventConsoleLoggingOfUnifiedClientRetryForSsrLoadersError() {
|
|
4
|
+
const originalConsoleError = console.error;
|
|
5
|
+
|
|
6
|
+
console.error = function error(...args) {
|
|
7
|
+
for (const arg of args) {
|
|
8
|
+
if (arg instanceof Error && arg.message.includes(ERROR_MESSAGE_SINGULAR_STRING)) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
originalConsoleError.call(console, ...args);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { Oidc as Oidc_core, OidcInitializationError } from "../../core";
|
|
3
|
+
import type { FunctionMiddlewareAfterServer, RequestMiddlewareAfterServer } from "@tanstack/react-start";
|
|
4
|
+
import type { GetterOrDirectValue } from "../../tools/GetterOrDirectValue";
|
|
5
|
+
import type { OidcMetadata } from "../../core/OidcMetadata";
|
|
6
|
+
|
|
7
|
+
export type CreateOidcComponent<DecodedIdToken> = <
|
|
8
|
+
Assert extends "user logged in" | "user not logged in" | undefined,
|
|
9
|
+
Props
|
|
10
|
+
>(params: {
|
|
11
|
+
assert?: Assert;
|
|
12
|
+
pendingComponent?: Assert extends undefined ? (props: NoInfer<Props>) => ReactNode : undefined;
|
|
13
|
+
component: (props: Props) => any;
|
|
14
|
+
}) => ((props: Props) => ReactNode) & {
|
|
15
|
+
useOidc: () => undefined extends Assert
|
|
16
|
+
? CreateOidcComponent.Oidc<DecodedIdToken>
|
|
17
|
+
: "user logged in" extends Assert
|
|
18
|
+
? CreateOidcComponent.Oidc.LoggedIn<DecodedIdToken>
|
|
19
|
+
: CreateOidcComponent.Oidc.NotLoggedIn;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export namespace CreateOidcComponent {
|
|
23
|
+
export type WithAutoLogin<DecodedIdToken> = <Props>(params: {
|
|
24
|
+
pendingComponent?: (params: NoInfer<Props>) => ReactNode;
|
|
25
|
+
component: (props: Props) => ReactNode;
|
|
26
|
+
}) => ((props: Props) => ReactNode) & {
|
|
27
|
+
useOidc: () => Oidc.LoggedIn<DecodedIdToken>;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type Oidc<DecodedIdToken> =
|
|
31
|
+
| (Oidc.NotLoggedIn & {
|
|
32
|
+
decodedIdToken?: never;
|
|
33
|
+
logout?: never;
|
|
34
|
+
renewTokens?: never;
|
|
35
|
+
goToAuthServer?: never;
|
|
36
|
+
backFromAuthServer?: never;
|
|
37
|
+
isNewBrowserSession?: never;
|
|
38
|
+
})
|
|
39
|
+
| (Oidc.LoggedIn<DecodedIdToken> & {
|
|
40
|
+
login?: never;
|
|
41
|
+
initializationError?: never;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export namespace Oidc {
|
|
45
|
+
type Common = {
|
|
46
|
+
issuerUri: string;
|
|
47
|
+
clientId: string;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type NotLoggedIn = Common & {
|
|
51
|
+
login: (params?: {
|
|
52
|
+
extraQueryParams?: Record<string, string | undefined>;
|
|
53
|
+
redirectUrl?: string;
|
|
54
|
+
transformUrlBeforeRedirect?: (url: string) => string;
|
|
55
|
+
}) => Promise<never>;
|
|
56
|
+
autoLogoutState: {
|
|
57
|
+
shouldDisplayWarning: false;
|
|
58
|
+
};
|
|
59
|
+
isUserLoggedIn: false;
|
|
60
|
+
initializationError: OidcInitializationError | undefined;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type LoggedIn<DecodedIdToken> = Common & {
|
|
64
|
+
isUserLoggedIn: true;
|
|
65
|
+
decodedIdToken: DecodedIdToken;
|
|
66
|
+
logout: Oidc_core.LoggedIn["logout"];
|
|
67
|
+
renewTokens: Oidc_core.LoggedIn["renewTokens"];
|
|
68
|
+
goToAuthServer: Oidc_core.LoggedIn["goToAuthServer"];
|
|
69
|
+
backFromAuthServer: Oidc_core.LoggedIn["backFromAuthServer"];
|
|
70
|
+
isNewBrowserSession: boolean;
|
|
71
|
+
autoLogoutState:
|
|
72
|
+
| {
|
|
73
|
+
shouldDisplayWarning: true;
|
|
74
|
+
secondsLeftBeforeAutoLogout: number;
|
|
75
|
+
}
|
|
76
|
+
| {
|
|
77
|
+
shouldDisplayWarning: false;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export type GetOidc<DecodedIdToken> = {
|
|
84
|
+
(params?: { assert?: undefined }): Promise<GetOidc.Oidc<DecodedIdToken>>;
|
|
85
|
+
(params: { assert: "user logged in" }): Promise<GetOidc.Oidc.LoggedIn<DecodedIdToken>>;
|
|
86
|
+
(params: { assert: "user not logged in" }): Promise<GetOidc.Oidc.NotLoggedIn>;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export namespace GetOidc {
|
|
90
|
+
export type WithAutoLogin<DecodedIdToken> = (params?: {
|
|
91
|
+
assert: "user logged in";
|
|
92
|
+
}) => Promise<Oidc.LoggedIn<DecodedIdToken>>;
|
|
93
|
+
|
|
94
|
+
export type Oidc<DecodedIdToken> =
|
|
95
|
+
| (Oidc.NotLoggedIn & {
|
|
96
|
+
getAccessToken?: never;
|
|
97
|
+
getDecodedIdToken?: never;
|
|
98
|
+
logout?: never;
|
|
99
|
+
renewTokens?: never;
|
|
100
|
+
goToAuthServer?: never;
|
|
101
|
+
backFromAuthServer?: never;
|
|
102
|
+
isNewBrowserSession?: never;
|
|
103
|
+
subscribeToAutoLogoutState?: never;
|
|
104
|
+
})
|
|
105
|
+
| (Oidc.LoggedIn<DecodedIdToken> & {
|
|
106
|
+
initializationError?: never;
|
|
107
|
+
login?: never;
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
export namespace Oidc {
|
|
111
|
+
type Common = {
|
|
112
|
+
issuerUri: string;
|
|
113
|
+
clientId: string;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export type NotLoggedIn = Common & {
|
|
117
|
+
isUserLoggedIn: false;
|
|
118
|
+
initializationError: OidcInitializationError | undefined;
|
|
119
|
+
login: Oidc_core.NotLoggedIn["login"];
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export type LoggedIn<DecodedIdToken> = Common & {
|
|
123
|
+
isUserLoggedIn: true;
|
|
124
|
+
getAccessToken: () => Promise<string>;
|
|
125
|
+
getDecodedIdToken: () => DecodedIdToken;
|
|
126
|
+
logout: Oidc_core.LoggedIn["logout"];
|
|
127
|
+
renewTokens: Oidc_core.LoggedIn["renewTokens"];
|
|
128
|
+
goToAuthServer: Oidc_core.LoggedIn["goToAuthServer"];
|
|
129
|
+
backFromAuthServer: Oidc_core.LoggedIn["backFromAuthServer"];
|
|
130
|
+
isNewBrowserSession: boolean;
|
|
131
|
+
subscribeToAutoLogoutState: (
|
|
132
|
+
next: (
|
|
133
|
+
autoLogoutState:
|
|
134
|
+
| {
|
|
135
|
+
shouldDisplayWarning: true;
|
|
136
|
+
secondsLeftBeforeAutoLogout: number;
|
|
137
|
+
}
|
|
138
|
+
| {
|
|
139
|
+
shouldDisplayWarning: false;
|
|
140
|
+
}
|
|
141
|
+
) => void
|
|
142
|
+
) => { unsubscribeFromAutoLogoutState: () => void };
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export type OidcFnMiddleware<AccessTokenClaims> = {
|
|
148
|
+
(params?: {
|
|
149
|
+
assert?: undefined;
|
|
150
|
+
hasRequiredClaims?: (params: { accessTokenClaims: AccessTokenClaims }) => Promise<boolean>;
|
|
151
|
+
}): OidcFnMiddleware.TanStackFnMiddleware<{
|
|
152
|
+
oidc: OidcServerContext<AccessTokenClaims>;
|
|
153
|
+
}>;
|
|
154
|
+
(params?: {
|
|
155
|
+
assert?: "user logged in";
|
|
156
|
+
hasRequiredClaims?: (params: { accessTokenClaims: AccessTokenClaims }) => Promise<boolean>;
|
|
157
|
+
}): OidcFnMiddleware.TanStackFnMiddleware<{
|
|
158
|
+
oidc: OidcServerContext.LoggedIn<AccessTokenClaims>;
|
|
159
|
+
}>;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export namespace OidcFnMiddleware {
|
|
163
|
+
export type WithAutoLogin<AccessTokenClaims> = (params?: {
|
|
164
|
+
assert?: "user logged in";
|
|
165
|
+
hasRequiredClaims?: (params: { accessTokenClaims: AccessTokenClaims }) => Promise<boolean>;
|
|
166
|
+
}) => TanStackFnMiddleware<{
|
|
167
|
+
oidc: OidcServerContext.LoggedIn<AccessTokenClaims>;
|
|
168
|
+
}>;
|
|
169
|
+
|
|
170
|
+
export type TanStackFnMiddleware<T> = FunctionMiddlewareAfterServer<
|
|
171
|
+
{},
|
|
172
|
+
unknown,
|
|
173
|
+
undefined,
|
|
174
|
+
T,
|
|
175
|
+
{},
|
|
176
|
+
undefined,
|
|
177
|
+
undefined
|
|
178
|
+
>;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export type OidcServerContext<AccessTokenClaims> =
|
|
182
|
+
| OidcServerContext.LoggedIn<AccessTokenClaims>
|
|
183
|
+
| (OidcServerContext.NotLoggedIn & {
|
|
184
|
+
accessTokenClaims?: never;
|
|
185
|
+
accessToken?: never;
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
export namespace OidcServerContext {
|
|
189
|
+
export type NotLoggedIn = {
|
|
190
|
+
isUserLoggedIn: false;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
export type LoggedIn<AccessTokenClaims> = {
|
|
194
|
+
isUserLoggedIn: true;
|
|
195
|
+
accessTokenClaims: AccessTokenClaims;
|
|
196
|
+
accessToken: string;
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export type OidcRequestMiddleware<AccessTokenClaims> = {
|
|
201
|
+
(params?: {
|
|
202
|
+
assert?: undefined;
|
|
203
|
+
hasRequiredClaims?: (params: { accessTokenClaims: AccessTokenClaims }) => Promise<boolean>;
|
|
204
|
+
}): OidcRequestMiddleware.TanstackRequestMiddleware<{
|
|
205
|
+
oidc: OidcServerContext<AccessTokenClaims>;
|
|
206
|
+
}>;
|
|
207
|
+
(params?: {
|
|
208
|
+
assert?: "user logged in";
|
|
209
|
+
hasRequiredClaims?: (params: { accessTokenClaims: AccessTokenClaims }) => Promise<boolean>;
|
|
210
|
+
}): OidcRequestMiddleware.TanstackRequestMiddleware<{
|
|
211
|
+
oidc: OidcServerContext.LoggedIn<AccessTokenClaims>;
|
|
212
|
+
}>;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
export namespace OidcRequestMiddleware {
|
|
216
|
+
export type WithAutoLogin<AccessTokenClaims> = (params?: {
|
|
217
|
+
assert?: "user logged in";
|
|
218
|
+
hasRequiredClaims?: (params: { accessTokenClaims: AccessTokenClaims }) => Promise<boolean>;
|
|
219
|
+
}) => TanstackRequestMiddleware<{
|
|
220
|
+
oidc: OidcServerContext.LoggedIn<AccessTokenClaims>;
|
|
221
|
+
}>;
|
|
222
|
+
|
|
223
|
+
export type TanstackRequestMiddleware<T> = RequestMiddlewareAfterServer<{}, undefined, T>;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export type ParamsOfBootstrap<AutoLogin, DecodedIdToken, AccessTokenClaims> =
|
|
227
|
+
| ParamsOfBootstrap.Real<AutoLogin>
|
|
228
|
+
| ParamsOfBootstrap.Mock<AutoLogin, DecodedIdToken, AccessTokenClaims>;
|
|
229
|
+
|
|
230
|
+
export namespace ParamsOfBootstrap {
|
|
231
|
+
export type Real<AutoLogin> = {
|
|
232
|
+
implementation: "real";
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* See: https://docs.oidc-spa.dev/v/v8/providers-configuration/provider-configuration
|
|
236
|
+
*/
|
|
237
|
+
issuerUri: string;
|
|
238
|
+
/**
|
|
239
|
+
* See: https://docs.oidc-spa.dev/v/v8/providers-configuration/provider-configuration
|
|
240
|
+
*/
|
|
241
|
+
clientId: string;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Default: 45 second.
|
|
245
|
+
* It defines how long before the auto logout we should start
|
|
246
|
+
* displaying an overlay message to the user alerting them
|
|
247
|
+
* like: "Are you still there? You'll be disconnected in 45...44..."
|
|
248
|
+
* NOTE: This parameter is only UI related! It does not defines
|
|
249
|
+
* after how much time of inactivity the user should be auto logged out.
|
|
250
|
+
* This is a server policy (that can be overwrote by idleSessionLifetimeInSeconds)
|
|
251
|
+
* See: https://docs.oidc-spa.dev/v/v8/auto-logout
|
|
252
|
+
*/
|
|
253
|
+
startCountdownSecondsBeforeAutoLogout?: number;
|
|
254
|
+
/**
|
|
255
|
+
* This parameter defines after how many seconds of inactivity the user should be
|
|
256
|
+
* logged out automatically.
|
|
257
|
+
*
|
|
258
|
+
* WARNING: It should be configured on the identity server side
|
|
259
|
+
* as it's the authoritative source for security policies and not the client.
|
|
260
|
+
* If you don't provide this parameter it will be inferred from the refresh token expiration time.
|
|
261
|
+
* Some provider however don't issue a refresh token or do not correctly set the
|
|
262
|
+
* expiration time. This parameter enable you to hard code the value to compensate
|
|
263
|
+
* the shortcoming of your auth server.
|
|
264
|
+
* */
|
|
265
|
+
idleSessionLifetimeInSeconds?: number;
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* The scopes being requested from the OIDC/OAuth2 provider (default: `["profile"]`
|
|
269
|
+
* (the scope "openid" is added automatically as it's mandatory)
|
|
270
|
+
**/
|
|
271
|
+
scopes?: string[];
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Transform the url (authorization endpoint) before redirecting to the login pages.
|
|
275
|
+
*
|
|
276
|
+
* The isSilent parameter is true when the redirect is initiated in the background iframe for silent signin.
|
|
277
|
+
* This can be used to omit ui related query parameters (like `ui_locales`).
|
|
278
|
+
*/
|
|
279
|
+
transformUrlBeforeRedirect?: (params: { authorizationUrl: string; isSilent: boolean }) => string;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Extra query params to be added to the authorization endpoint url before redirecting or silent signing in.
|
|
283
|
+
* You can provide a function that returns those extra query params, it will be called
|
|
284
|
+
* when login() is called.
|
|
285
|
+
*
|
|
286
|
+
* Example: extraQueryParams: ()=> ({ ui_locales: "fr" })
|
|
287
|
+
*
|
|
288
|
+
* This parameter can also be passed to login() directly.
|
|
289
|
+
*/
|
|
290
|
+
extraQueryParams?:
|
|
291
|
+
| Record<string, string | undefined>
|
|
292
|
+
| ((params: { isSilent: boolean; url: string }) => Record<string, string | undefined>);
|
|
293
|
+
/**
|
|
294
|
+
* Extra body params to be added to the /token POST request.
|
|
295
|
+
*
|
|
296
|
+
* It will be used when for the initial request, whenever the token is getting refreshed and if you call `renewTokens()`.
|
|
297
|
+
* You can also provide this parameter directly to the `renewTokens()` method.
|
|
298
|
+
*
|
|
299
|
+
* It can be either a string to string record or a function that returns a string to string record.
|
|
300
|
+
*
|
|
301
|
+
* Example: extraTokenParams: ()=> ({ selectedCustomer: "xxx" })
|
|
302
|
+
* extraTokenParams: { selectedCustomer: "xxx" }
|
|
303
|
+
*/
|
|
304
|
+
extraTokenParams?:
|
|
305
|
+
| Record<string, string | undefined>
|
|
306
|
+
| (() => Record<string, string | undefined>);
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Default: false
|
|
310
|
+
*
|
|
311
|
+
* See: https://docs.oidc-spa.dev/v/v8/resources/iframe-related-issues
|
|
312
|
+
*/
|
|
313
|
+
noIframe?: boolean;
|
|
314
|
+
|
|
315
|
+
debugLogs?: boolean;
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* WARNING: This option exists solely as a workaround
|
|
319
|
+
* for limitations in the Google OAuth API.
|
|
320
|
+
* See: https://docs.oidc-spa.dev/providers-configuration/google-oauth
|
|
321
|
+
*
|
|
322
|
+
* Do not use this for other providers.
|
|
323
|
+
* If you think you need a client secret in a SPA, you are likely
|
|
324
|
+
* trying to use a confidential (private) client in the browser,
|
|
325
|
+
* which is insecure and not supported.
|
|
326
|
+
*/
|
|
327
|
+
__unsafe_clientSecret?: string;
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* This option should only be used as a last resort.
|
|
331
|
+
*
|
|
332
|
+
* If your OIDC provider is correctly configured, this should not be necessary.
|
|
333
|
+
*
|
|
334
|
+
* The metadata is normally retrieved automatically from:
|
|
335
|
+
* `${issuerUri}/.well-known/openid-configuration`
|
|
336
|
+
*
|
|
337
|
+
* Use this only if that endpoint is not accessible (e.g. due to missing CORS headers
|
|
338
|
+
* or non-standard deployments), and you cannot fix the server-side configuration.
|
|
339
|
+
*/
|
|
340
|
+
__metadata?: Partial<OidcMetadata>;
|
|
341
|
+
} & (AutoLogin extends true ? {} : {});
|
|
342
|
+
|
|
343
|
+
export type Mock<AutoLogin, DecodedIdToken, AccessTokenClaims> = {
|
|
344
|
+
implementation: "mock";
|
|
345
|
+
issuerUri_mock?: string;
|
|
346
|
+
clientId_mock?: string;
|
|
347
|
+
decodedIdToken_mock?: DecodedIdToken;
|
|
348
|
+
} & (AccessTokenClaims extends undefined
|
|
349
|
+
? {}
|
|
350
|
+
: {
|
|
351
|
+
accessTokenClaims_mock?: AccessTokenClaims;
|
|
352
|
+
}) &
|
|
353
|
+
(AutoLogin extends true
|
|
354
|
+
? {
|
|
355
|
+
isUserInitiallyLoggedIn?: true;
|
|
356
|
+
}
|
|
357
|
+
: {
|
|
358
|
+
isUserInitiallyLoggedIn: boolean;
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export type OidcSpaApi<AutoLogin, DecodedIdToken, AccessTokenClaims> = {
|
|
363
|
+
bootstrapOidc: (
|
|
364
|
+
params: GetterOrDirectValue<
|
|
365
|
+
{ process: { env: Record<string, string> } },
|
|
366
|
+
ParamsOfBootstrap<AutoLogin, DecodedIdToken, AccessTokenClaims>
|
|
367
|
+
>
|
|
368
|
+
) => void;
|
|
369
|
+
createOidcComponent: AutoLogin extends true
|
|
370
|
+
? CreateOidcComponent.WithAutoLogin<DecodedIdToken>
|
|
371
|
+
: CreateOidcComponent<DecodedIdToken>;
|
|
372
|
+
getOidc: AutoLogin extends true ? GetOidc.WithAutoLogin<DecodedIdToken> : GetOidc<DecodedIdToken>;
|
|
373
|
+
} & (AccessTokenClaims extends undefined
|
|
374
|
+
? {}
|
|
375
|
+
: {
|
|
376
|
+
oidcFnMiddleware: AutoLogin extends true
|
|
377
|
+
? OidcFnMiddleware.WithAutoLogin<AccessTokenClaims>
|
|
378
|
+
: OidcFnMiddleware<AccessTokenClaims>;
|
|
379
|
+
oidcRequestMiddleware: AutoLogin extends true
|
|
380
|
+
? OidcRequestMiddleware.WithAutoLogin<AccessTokenClaims>
|
|
381
|
+
: OidcRequestMiddleware<AccessTokenClaims>;
|
|
382
|
+
}) &
|
|
383
|
+
(AutoLogin extends true
|
|
384
|
+
? {
|
|
385
|
+
OidcInitializationGate: (props: {
|
|
386
|
+
renderFallback: (props: {
|
|
387
|
+
initializationError: OidcInitializationError | undefined;
|
|
388
|
+
}) => ReactNode;
|
|
389
|
+
children: ReactNode;
|
|
390
|
+
}) => ReactNode;
|
|
391
|
+
}
|
|
392
|
+
: {
|
|
393
|
+
enforceLogin: (loaderContext: {
|
|
394
|
+
cause: "preload" | string;
|
|
395
|
+
location: {
|
|
396
|
+
href: string;
|
|
397
|
+
};
|
|
398
|
+
}) => Promise<void | never>;
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
export type CreateValidateAndGetAccessTokenClaims<AccessTokenClaims> = (params: {
|
|
402
|
+
paramsOfBootstrap: ParamsOfBootstrap<boolean, Record<string, unknown>, AccessTokenClaims>;
|
|
403
|
+
}) => {
|
|
404
|
+
validateAndGetAccessTokenClaims: (params: { accessToken: string }) => Promise<
|
|
405
|
+
| {
|
|
406
|
+
isValid: true;
|
|
407
|
+
accessTokenClaims: AccessTokenClaims;
|
|
408
|
+
}
|
|
409
|
+
| {
|
|
410
|
+
isValid: false;
|
|
411
|
+
errorMessage: string;
|
|
412
|
+
wwwAuthenticateHeaderErrorDescription: string;
|
|
413
|
+
}
|
|
414
|
+
>;
|
|
415
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type ComponentType, type FC, useEffect } from "react";
|
|
2
|
+
import { getOidcRequiredPostHydrationReplaceNavigationUrl } from "../../core/requiredPostHydrationReplaceNavigationUrl";
|
|
3
|
+
import { useRouter } from "@tanstack/react-router";
|
|
4
|
+
|
|
5
|
+
export function withHandlingOidcPostLoginNavigation<Props extends Record<string, unknown>>(
|
|
6
|
+
Component: ComponentType<Props>
|
|
7
|
+
): FC<Props> {
|
|
8
|
+
let { rootRelativeRedirectUrl } = getOidcRequiredPostHydrationReplaceNavigationUrl();
|
|
9
|
+
|
|
10
|
+
if (rootRelativeRedirectUrl === undefined) {
|
|
11
|
+
// @ts-expect-error
|
|
12
|
+
return Component;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function ComponentWithHandlingOidcPostLoginNavigation(props: Props) {
|
|
16
|
+
const router = useRouter();
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (rootRelativeRedirectUrl === undefined) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
router.navigate({ to: rootRelativeRedirectUrl, replace: true });
|
|
24
|
+
rootRelativeRedirectUrl = undefined;
|
|
25
|
+
}, []);
|
|
26
|
+
|
|
27
|
+
return <Component {...props} />;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
ComponentWithHandlingOidcPostLoginNavigation.displayName = `${
|
|
31
|
+
Component.displayName ?? Component.name ?? "Component"
|
|
32
|
+
}WithHandlingOidcPostLoginNavigation`;
|
|
33
|
+
|
|
34
|
+
return ComponentWithHandlingOidcPostLoginNavigation;
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type GetterOrDirectValue<P, T> = ((params: P) => T) | T;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
|
|
4
|
+
let result: string | undefined = undefined;
|
|
5
|
+
|
|
6
|
+
export function getThisCodebaseRootDirPath(): string {
|
|
7
|
+
if (result !== undefined) {
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return (result = getNearestPackageJsonDirPath(__dirname));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function getNearestPackageJsonDirPath(dirPath: string): string {
|
|
15
|
+
if (fs.existsSync(path.join(dirPath, "package.json"))) {
|
|
16
|
+
return dirPath;
|
|
17
|
+
}
|
|
18
|
+
return getNearestPackageJsonDirPath(path.join(dirPath, ".."));
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { assert } from "./tsafe/assert";
|
|
2
|
+
|
|
3
|
+
export function infer_import_meta_env_BASE_URL() {
|
|
4
|
+
const url = new URL(import.meta.url);
|
|
5
|
+
const pathname = url.pathname;
|
|
6
|
+
|
|
7
|
+
for (const searched of ["/assets/", "/node_modules/"]) {
|
|
8
|
+
// In Vite builds, JS files live under `${BASE_URL}/assets/...`
|
|
9
|
+
const index = pathname.indexOf(searched);
|
|
10
|
+
|
|
11
|
+
if (index === -1) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return pathname.slice(0, index + 1); // keep trailing slash
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
assert(false, "Couldn't infer import.meta.BASE_URL");
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "jose";
|