oidc-spa 8.1.15 → 8.2.1
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/core/BASE_URL.d.ts +4 -0
- package/core/BASE_URL.js +12 -0
- package/core/BASE_URL.js.map +1 -0
- package/core/OidcMetadata.d.ts +5 -0
- package/core/OidcMetadata.js +56 -0
- package/core/OidcMetadata.js.map +1 -1
- package/core/createOidc.d.ts +15 -8
- package/core/createOidc.js +207 -104
- package/core/createOidc.js.map +1 -1
- package/core/diagnostic.d.ts +0 -1
- package/core/diagnostic.js +18 -5
- package/core/diagnostic.js.map +1 -1
- package/core/earlyInit.d.ts +1 -0
- package/core/earlyInit.js +8 -8
- package/core/earlyInit.js.map +1 -1
- package/core/loginOrGoToAuthServer.d.ts +0 -1
- package/core/loginOrGoToAuthServer.js +1 -16
- package/core/loginOrGoToAuthServer.js.map +1 -1
- package/core/loginSilent.d.ts +1 -2
- package/core/loginSilent.js +3 -21
- package/core/loginSilent.js.map +1 -1
- package/core/prShouldLoadApp.d.ts +4 -0
- package/core/prShouldLoadApp.js +13 -0
- package/core/prShouldLoadApp.js.map +1 -0
- package/esm/core/BASE_URL.d.ts +4 -0
- package/esm/core/BASE_URL.js +8 -0
- package/esm/core/BASE_URL.js.map +1 -0
- package/esm/core/OidcMetadata.d.ts +5 -0
- package/esm/core/OidcMetadata.js +54 -0
- package/esm/core/OidcMetadata.js.map +1 -1
- package/esm/core/createOidc.d.ts +15 -8
- package/esm/core/createOidc.js +207 -104
- package/esm/core/createOidc.js.map +1 -1
- package/esm/core/diagnostic.d.ts +0 -1
- package/esm/core/diagnostic.js +15 -1
- package/esm/core/diagnostic.js.map +1 -1
- package/esm/core/earlyInit.d.ts +1 -0
- package/esm/core/earlyInit.js +8 -8
- package/esm/core/earlyInit.js.map +1 -1
- package/esm/core/loginOrGoToAuthServer.d.ts +0 -1
- package/esm/core/loginOrGoToAuthServer.js +1 -16
- package/esm/core/loginOrGoToAuthServer.js.map +1 -1
- package/esm/core/loginSilent.d.ts +1 -2
- package/esm/core/loginSilent.js +3 -21
- package/esm/core/loginSilent.js.map +1 -1
- package/esm/core/prShouldLoadApp.d.ts +4 -0
- package/esm/core/prShouldLoadApp.js +9 -0
- package/esm/core/prShouldLoadApp.js.map +1 -0
- package/esm/keycloak/keycloak-js/Keycloak.d.ts +1 -1
- package/esm/keycloak/keycloak-js/Keycloak.js +1 -1
- package/esm/keycloak/keycloak-js/Keycloak.js.map +1 -1
- package/esm/keycloak/keycloakIssuerUriParsed.js +8 -1
- package/esm/keycloak/keycloakIssuerUriParsed.js.map +1 -1
- package/esm/mock/oidc.d.ts +3 -1
- package/esm/mock/oidc.js +4 -2
- package/esm/mock/oidc.js.map +1 -1
- package/esm/react-spa/apiBuilder.d.ts +12 -0
- package/esm/react-spa/apiBuilder.js +26 -0
- package/esm/react-spa/apiBuilder.js.map +1 -0
- package/esm/react-spa/createOidcSpaApi.d.ts +8 -0
- package/esm/react-spa/createOidcSpaApi.js +387 -0
- package/esm/react-spa/createOidcSpaApi.js.map +1 -0
- package/esm/react-spa/index.d.ts +2 -0
- package/esm/react-spa/index.js +3 -0
- package/esm/react-spa/index.js.map +1 -0
- package/esm/react-spa/types.d.ts +279 -0
- package/esm/react-spa/types.js +2 -0
- package/esm/react-spa/types.js.map +1 -0
- package/esm/tanstack-start/react/apiBuilder.js.map +1 -1
- package/esm/tanstack-start/react/createOidcSpaApi.js +13 -9
- package/esm/tanstack-start/react/createOidcSpaApi.js.map +1 -1
- package/esm/tanstack-start/react/types.d.ts +5 -4
- package/esm/tools/isLikelyDevServer.d.ts +1 -0
- package/esm/tools/isLikelyDevServer.js +14 -0
- package/esm/tools/isLikelyDevServer.js.map +1 -0
- package/keycloak/keycloak-js/Keycloak.d.ts +1 -1
- package/keycloak/keycloak-js/Keycloak.js +1 -1
- package/keycloak/keycloak-js/Keycloak.js.map +1 -1
- package/keycloak/keycloakIssuerUriParsed.js +8 -1
- package/keycloak/keycloakIssuerUriParsed.js.map +1 -1
- package/mock/oidc.d.ts +3 -1
- package/mock/oidc.js +4 -2
- package/mock/oidc.js.map +1 -1
- package/package.json +5 -1
- package/react-spa/apiBuilder.d.ts +12 -0
- package/react-spa/apiBuilder.js +29 -0
- package/react-spa/apiBuilder.js.map +1 -0
- package/react-spa/createOidcSpaApi.d.ts +8 -0
- package/react-spa/createOidcSpaApi.js +423 -0
- package/react-spa/createOidcSpaApi.js.map +1 -0
- package/react-spa/index.d.ts +2 -0
- package/react-spa/index.js +6 -0
- package/react-spa/index.js.map +1 -0
- package/react-spa/types.d.ts +279 -0
- package/react-spa/types.js +3 -0
- package/react-spa/types.js.map +1 -0
- package/src/angular.ts +1 -1
- package/src/core/BASE_URL.ts +9 -0
- package/src/core/OidcMetadata.ts +75 -0
- package/src/core/createOidc.ts +273 -147
- package/src/core/diagnostic.ts +21 -2
- package/src/core/earlyInit.ts +14 -11
- package/src/core/loginOrGoToAuthServer.ts +0 -22
- package/src/core/loginSilent.ts +4 -27
- package/src/core/prShouldLoadApp.ts +11 -0
- package/src/keycloak/keycloak-js/Keycloak.ts +2 -2
- package/src/keycloak/keycloakIssuerUriParsed.ts +10 -1
- package/src/mock/oidc.ts +9 -3
- package/src/react-spa/apiBuilder.ts +70 -0
- package/src/react-spa/createOidcSpaApi.tsx +527 -0
- package/src/react-spa/index.ts +4 -0
- package/src/react-spa/types.tsx +308 -0
- package/src/tanstack-start/react/apiBuilder.ts +0 -1
- package/src/tanstack-start/react/createOidcSpaApi.tsx +24 -20
- package/src/tanstack-start/react/types.tsx +3 -4
- package/src/tools/isLikelyDevServer.ts +17 -0
- package/src/vite-plugin/handleClientEntrypoint.ts +5 -5
- package/src/vite-plugin/manageOptimizedDeps.ts +64 -0
- package/src/vite-plugin/projectType.ts +18 -0
- package/src/vite-plugin/vite-plugin.ts +40 -10
- package/tools/isLikelyDevServer.d.ts +1 -0
- package/tools/isLikelyDevServer.js +17 -0
- package/tools/isLikelyDevServer.js.map +1 -0
- package/vite-plugin/handleClientEntrypoint.d.ts +2 -0
- package/vite-plugin/handleClientEntrypoint.js +3 -4
- package/vite-plugin/handleClientEntrypoint.js.map +1 -1
- package/vite-plugin/manageOptimizedDeps.d.ts +6 -0
- package/vite-plugin/{excludeModuleExportFromOptimizedDeps.js → manageOptimizedDeps.js} +42 -7
- package/vite-plugin/manageOptimizedDeps.js.map +1 -0
- package/vite-plugin/projectType.d.ts +4 -0
- package/vite-plugin/projectType.js +15 -0
- package/vite-plugin/projectType.js.map +1 -0
- package/vite-plugin/{transformCreateFileRoute.js → transformTanstackRouterCreateFileRoute.js} +1 -1
- package/vite-plugin/transformTanstackRouterCreateFileRoute.js.map +1 -0
- package/vite-plugin/vite-plugin.d.ts +1 -1
- package/vite-plugin/vite-plugin.js +28 -8
- package/vite-plugin/vite-plugin.js.map +1 -1
- package/esm/tools/infer_import_meta_env_BASE_URL.d.ts +0 -1
- package/esm/tools/infer_import_meta_env_BASE_URL.js +0 -15
- package/esm/tools/infer_import_meta_env_BASE_URL.js.map +0 -1
- package/src/tools/infer_import_meta_env_BASE_URL.ts +0 -19
- package/src/vite-plugin/detectProjectType.ts +0 -20
- package/src/vite-plugin/excludeModuleExportFromOptimizedDeps.ts +0 -20
- package/vite-plugin/detectProjectType.d.ts +0 -10
- package/vite-plugin/detectProjectType.js +0 -15
- package/vite-plugin/detectProjectType.js.map +0 -1
- package/vite-plugin/excludeModuleExportFromOptimizedDeps.d.ts +0 -4
- package/vite-plugin/excludeModuleExportFromOptimizedDeps.js.map +0 -1
- package/vite-plugin/transformCreateFileRoute.js.map +0 -1
- /package/src/vite-plugin/{transformCreateFileRoute.ts → transformTanstackRouterCreateFileRoute.ts} +0 -0
- /package/vite-plugin/{transformCreateFileRoute.d.ts → transformTanstackRouterCreateFileRoute.d.ts} +0 -0
package/core/BASE_URL.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBASE_URL = getBASE_URL;
|
|
4
|
+
exports.setBASE_URL = setBASE_URL;
|
|
5
|
+
let BASE_URL = undefined;
|
|
6
|
+
function getBASE_URL() {
|
|
7
|
+
return BASE_URL;
|
|
8
|
+
}
|
|
9
|
+
function setBASE_URL(params) {
|
|
10
|
+
BASE_URL = params.BASE_URL;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=BASE_URL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BASE_URL.js","sourceRoot":"","sources":["../src/core/BASE_URL.ts"],"names":[],"mappings":";;AAEA,kCAEC;AAED,kCAEC;AARD,IAAI,QAAQ,GAAuB,SAAS,CAAC;AAE7C,SAAgB,WAAW;IACvB,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED,SAAgB,WAAW,CAAC,MAA4B;IACpD,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;AAC/B,CAAC"}
|
package/core/OidcMetadata.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type OidcMetadata as OidcClientTsOidcMetadata } from "../vendor/frontend/oidc-client-ts";
|
|
1
2
|
/**
|
|
2
3
|
* OpenID Providers have metadata describing their configuration.
|
|
3
4
|
*
|
|
@@ -264,3 +265,7 @@ export type OidcMetadata = {
|
|
|
264
265
|
*/
|
|
265
266
|
code_challenge_methods_supported: string[];
|
|
266
267
|
};
|
|
268
|
+
export declare const WELL_KNOWN_PATH = "/.well-known/openid-configuration";
|
|
269
|
+
export declare function fetchOidcMetadata(params: {
|
|
270
|
+
issuerUri: string;
|
|
271
|
+
}): Promise<Partial<OidcClientTsOidcMetadata> | undefined>;
|
package/core/OidcMetadata.js
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WELL_KNOWN_PATH = void 0;
|
|
4
|
+
exports.fetchOidcMetadata = fetchOidcMetadata;
|
|
3
5
|
const assert_1 = require("../tools/tsafe/assert");
|
|
6
|
+
const isLikelyDevServer_1 = require("../tools/isLikelyDevServer");
|
|
4
7
|
assert_1.assert;
|
|
8
|
+
exports.WELL_KNOWN_PATH = "/.well-known/openid-configuration";
|
|
9
|
+
function getSessionStorageKey(params) {
|
|
10
|
+
const { issuerUri } = params;
|
|
11
|
+
return `oidc-spa:openid-configuration:${issuerUri}`;
|
|
12
|
+
}
|
|
13
|
+
function readSessionStorage(params) {
|
|
14
|
+
const { issuerUri } = params;
|
|
15
|
+
const value = sessionStorage.getItem(getSessionStorageKey({ issuerUri }));
|
|
16
|
+
if (value === null) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
return JSON.parse(value);
|
|
20
|
+
}
|
|
21
|
+
function setSessionStorage(params) {
|
|
22
|
+
const { issuerUri, oidcMetadata } = params;
|
|
23
|
+
sessionStorage.setItem(getSessionStorageKey({ issuerUri }), JSON.stringify(oidcMetadata));
|
|
24
|
+
}
|
|
25
|
+
async function fetchOidcMetadata(params) {
|
|
26
|
+
const { issuerUri } = params;
|
|
27
|
+
from_cache: {
|
|
28
|
+
const oidcMetadata = readSessionStorage({ issuerUri });
|
|
29
|
+
if (oidcMetadata === undefined) {
|
|
30
|
+
break from_cache;
|
|
31
|
+
}
|
|
32
|
+
return oidcMetadata;
|
|
33
|
+
}
|
|
34
|
+
let oidcMetadata;
|
|
35
|
+
try {
|
|
36
|
+
const response = await fetch(`${issuerUri}${exports.WELL_KNOWN_PATH}`, {
|
|
37
|
+
headers: {
|
|
38
|
+
Accept: "application/jwk-set+json, application/json"
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
throw new Error();
|
|
43
|
+
}
|
|
44
|
+
const obj = await response.json();
|
|
45
|
+
{
|
|
46
|
+
const { authorization_endpoint } = obj;
|
|
47
|
+
if (typeof authorization_endpoint !== "string") {
|
|
48
|
+
throw new Error();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
oidcMetadata = obj;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
if (!(0, isLikelyDevServer_1.getIsLikelyDevServer)()) {
|
|
57
|
+
setSessionStorage({ issuerUri, oidcMetadata });
|
|
58
|
+
}
|
|
59
|
+
return oidcMetadata;
|
|
60
|
+
}
|
|
5
61
|
//# sourceMappingURL=OidcMetadata.js.map
|
package/core/OidcMetadata.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OidcMetadata.js","sourceRoot":"","sources":["../src/core/OidcMetadata.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"OidcMetadata.js","sourceRoot":"","sources":["../src/core/OidcMetadata.ts"],"names":[],"mappings":";;;AA2SA,8CA8CC;AAxVD,kDAA4D;AAC5D,kEAAkE;AA6QlE,eAAsD,CAAC;AAE1C,QAAA,eAAe,GAAG,mCAAmC,CAAC;AAEnE,SAAS,oBAAoB,CAAC,MAA6B;IACvD,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAE7B,OAAO,iCAAiC,SAAS,EAAE,CAAC;AACxD,CAAC;AAED,SAAS,kBAAkB,CAAC,MAA6B;IACrD,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAE7B,MAAM,KAAK,GAAG,cAAc,CAAC,OAAO,CAAC,oBAAoB,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;IAE1E,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACjB,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAsC,CAAC;AAClE,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAkE;IACzF,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;IAE3C,cAAc,CAAC,OAAO,CAAC,oBAAoB,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC;AAC9F,CAAC;AAEM,KAAK,UAAU,iBAAiB,CAAC,MAA6B;IACjE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAE7B,UAAU,EAAE,CAAC;QACT,MAAM,YAAY,GAAG,kBAAkB,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;QAEvD,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YAC7B,MAAM,UAAU,CAAC;QACrB,CAAC;QAED,OAAO,YAAY,CAAC;IACxB,CAAC;IAED,IAAI,YAAmC,CAAC;IAExC,IAAI,CAAC;QACD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,SAAS,GAAG,uBAAe,EAAE,EAAE;YAC3D,OAAO,EAAE;gBACL,MAAM,EAAE,4CAA4C;aACvD;SACJ,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,EAAE,CAAC;QACtB,CAAC;QAED,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAElC,CAAC;YACG,MAAM,EAAE,sBAAsB,EAAE,GAAG,GAAG,CAAC;YAEvC,IAAI,OAAO,sBAAsB,KAAK,QAAQ,EAAE,CAAC;gBAC7C,MAAM,IAAI,KAAK,EAAE,CAAC;YACtB,CAAC;QACL,CAAC;QAED,YAAY,GAAG,GAAG,CAAC;IACvB,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,IAAI,CAAC,IAAA,wCAAoB,GAAE,EAAE,CAAC;QAC1B,iBAAiB,CAAC,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,OAAO,YAAY,CAAC;AACxB,CAAC"}
|
package/core/createOidc.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type OidcMetadata } from "./OidcMetadata";
|
|
2
2
|
import type { Oidc } from "./Oidc";
|
|
3
3
|
export type ParamsOfCreateOidc<DecodedIdToken extends Record<string, unknown> = Oidc.Tokens.DecodedIdToken_OidcCoreSpec, AutoLogin extends boolean = false> = {
|
|
4
|
-
/**
|
|
5
|
-
* What should you put in this parameter?
|
|
6
|
-
* - Vite project: `BASE_URL: import.meta.env.BASE_URL`
|
|
7
|
-
* - Create React App project: `BASE_URL: process.env.PUBLIC_URL`
|
|
8
|
-
* - Other: `BASE_URL: "/"` (Usually, or `/dashboard` if your app is not at the root of the domain)
|
|
9
|
-
*/
|
|
10
|
-
homeUrl: string;
|
|
11
4
|
/**
|
|
12
5
|
* See: https://docs.oidc-spa.dev/v/v8/providers-configuration/provider-configuration
|
|
13
6
|
*/
|
|
@@ -129,6 +122,20 @@ export type ParamsOfCreateOidc<DecodedIdToken extends Record<string, unknown> =
|
|
|
129
122
|
* or non-standard deployments), and you cannot fix the server-side configuration.
|
|
130
123
|
*/
|
|
131
124
|
__metadata?: Partial<OidcMetadata>;
|
|
125
|
+
/**
|
|
126
|
+
* NOTE: This parameter is optional if you use the Vite plugin.
|
|
127
|
+
*
|
|
128
|
+
* This parameter let's you overwrite the value provided in
|
|
129
|
+
* oidcEarlyInit({ BASE_URL: xxx });
|
|
130
|
+
*
|
|
131
|
+
* What should you put in this parameter?
|
|
132
|
+
* - Vite project: `BASE_URL: import.meta.env.BASE_URL`
|
|
133
|
+
* - Create React App project: `BASE_URL: process.env.PUBLIC_URL`
|
|
134
|
+
* - Other: `BASE_URL: "/"` (Usually, or `/dashboard` if your app is not at the root of the domain)
|
|
135
|
+
*/
|
|
136
|
+
BASE_URL?: string;
|
|
137
|
+
/** @deprecated: Use BASE_URL (same thing, just renamed). */
|
|
138
|
+
homeUrl?: string;
|
|
132
139
|
};
|
|
133
140
|
/** @see: https://docs.oidc-spa.dev/v/v8/usage */
|
|
134
141
|
export declare function createOidc<DecodedIdToken extends Record<string, unknown> = Oidc.Tokens.DecodedIdToken_OidcCoreSpec, AutoLogin extends boolean = false>(params: ParamsOfCreateOidc<DecodedIdToken, AutoLogin>): Promise<AutoLogin extends true ? Oidc.LoggedIn<DecodedIdToken> : Oidc<DecodedIdToken>>;
|
package/core/createOidc.js
CHANGED
|
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.createOidc = createOidc;
|
|
37
37
|
exports.createOidc_nonMemoized = createOidc_nonMemoized;
|
|
38
38
|
const oidc_client_ts_1 = require("../vendor/frontend/oidc-client-ts");
|
|
39
|
+
const OidcMetadata_1 = require("./OidcMetadata");
|
|
39
40
|
const assert_1 = require("../tools/tsafe/assert");
|
|
40
41
|
const id_1 = require("../tools/tsafe/id");
|
|
41
42
|
const workerTimers_1 = require("../tools/workerTimers");
|
|
@@ -63,9 +64,12 @@ const isNewBrowserSession_1 = require("./isNewBrowserSession");
|
|
|
63
64
|
const getIsOnline_1 = require("../tools/getIsOnline");
|
|
64
65
|
const isKeycloak_1 = require("../keycloak/isKeycloak");
|
|
65
66
|
const INFINITY_TIME_1 = require("../tools/INFINITY_TIME");
|
|
66
|
-
const
|
|
67
|
+
const prShouldLoadApp_1 = require("./prShouldLoadApp");
|
|
68
|
+
const BASE_URL_1 = require("./BASE_URL");
|
|
69
|
+
const isLikelyDevServer_1 = require("../tools/isLikelyDevServer");
|
|
70
|
+
const createObjectThatThrowsIfAccessed_1 = require("../tools/createObjectThatThrowsIfAccessed");
|
|
67
71
|
// NOTE: Replaced at build time
|
|
68
|
-
const VERSION = "8.1
|
|
72
|
+
const VERSION = "8.2.1";
|
|
69
73
|
const globalContext = {
|
|
70
74
|
prOidcByConfigId: new Map(),
|
|
71
75
|
hasLogoutBeenCalled: (0, id_1.id)(false),
|
|
@@ -139,7 +143,23 @@ async function createOidc(params) {
|
|
|
139
143
|
return oidc;
|
|
140
144
|
}
|
|
141
145
|
async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
142
|
-
|
|
146
|
+
{
|
|
147
|
+
const timer = window.setTimeout(() => {
|
|
148
|
+
console.warn([
|
|
149
|
+
"oidc-spa: Setup error.",
|
|
150
|
+
"oidcEarlyInit() wasn't called.",
|
|
151
|
+
"This is supposed to be handled by the oidc-spa Vite plugin",
|
|
152
|
+
"or manually in other environments."
|
|
153
|
+
].join(" "));
|
|
154
|
+
}, 3000);
|
|
155
|
+
const shouldLoadApp = await prShouldLoadApp_1.prShouldLoadApp;
|
|
156
|
+
window.clearTimeout(timer);
|
|
157
|
+
if (!shouldLoadApp) {
|
|
158
|
+
return new Promise(() => { });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const { transformUrlBeforeRedirect, extraQueryParams: extraQueryParamsOrGetter, extraTokenParams: extraTokenParamsOrGetter, decodedIdTokenSchema, idleSessionLifetimeInSeconds, autoLogoutParams = { redirectTo: "current page" }, autoLogin = false, postLoginRedirectUrl: postLoginRedirectUrl_default, __unsafe_clientSecret, __unsafe_useIdTokenAsAccessToken = false, __metadata, noIframe = false } = params;
|
|
162
|
+
const BASE_URL_params = params.BASE_URL ?? params.homeUrl;
|
|
143
163
|
const { issuerUri, clientId, scopes, configId, log } = preProcessedParams;
|
|
144
164
|
const getExtraQueryParams = (() => {
|
|
145
165
|
if (extraQueryParamsOrGetter === undefined) {
|
|
@@ -160,7 +180,24 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
160
180
|
return extraTokenParamsOrGetter;
|
|
161
181
|
})();
|
|
162
182
|
const homeUrlAndRedirectUri = (0, toFullyQualifiedUrl_1.toFullyQualifiedUrl)({
|
|
163
|
-
urlish:
|
|
183
|
+
urlish: (() => {
|
|
184
|
+
if (BASE_URL_params !== undefined) {
|
|
185
|
+
return BASE_URL_params;
|
|
186
|
+
}
|
|
187
|
+
const BASE_URL = (0, BASE_URL_1.getBASE_URL)();
|
|
188
|
+
if (BASE_URL === undefined) {
|
|
189
|
+
throw new Error([
|
|
190
|
+
"oidc-spa: If you do not use the oidc-spa Vite plugin",
|
|
191
|
+
"you must provide the BASE_URL to the earlyInit() examples:",
|
|
192
|
+
"oidcSpaEarlyInit({ BASE_URL: import.meta.env.BASE_URL })",
|
|
193
|
+
"oidcSpaEarlyInit({ BASE_URL: '/' })",
|
|
194
|
+
"",
|
|
195
|
+
"You can also pass this parameter to createOidc({ BASE_URL: '...' })",
|
|
196
|
+
"or bootstrapOidc({ BASE_URL: '...' })"
|
|
197
|
+
].join("\n"));
|
|
198
|
+
}
|
|
199
|
+
return BASE_URL;
|
|
200
|
+
})(),
|
|
164
201
|
doAssertNoQueryParams: true,
|
|
165
202
|
doOutputWithTrailingSlash: true
|
|
166
203
|
});
|
|
@@ -172,71 +209,168 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
172
209
|
homeUrlAndRedirectUri
|
|
173
210
|
}, null, 2)}`);
|
|
174
211
|
const stateUrlParamValue_instance = (0, StateData_1.generateStateUrlParamValue)();
|
|
212
|
+
const oidcMetadata = __metadata ?? (await (0, OidcMetadata_1.fetchOidcMetadata)({ issuerUri }));
|
|
175
213
|
const canUseIframe = (() => {
|
|
176
214
|
if (noIframe) {
|
|
177
215
|
return false;
|
|
178
216
|
}
|
|
179
217
|
third_party_cookies: {
|
|
180
|
-
|
|
218
|
+
if (oidcMetadata === undefined) {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
const { authorization_endpoint } = oidcMetadata;
|
|
222
|
+
(0, assert_1.assert)(authorization_endpoint !== undefined, "Missing authorization_endpoint on the provided __metadata");
|
|
223
|
+
const isOidcServerThirdPartyRelativeToApp = !(0, haveSharedParentDomain_1.getHaveSharedParentDomain)({
|
|
181
224
|
url1: window.location.origin,
|
|
182
|
-
|
|
183
|
-
|
|
225
|
+
// TODO: No, here we should test against the authorization endpoint!
|
|
226
|
+
url2: authorization_endpoint
|
|
227
|
+
});
|
|
184
228
|
if (!isOidcServerThirdPartyRelativeToApp) {
|
|
185
229
|
break third_party_cookies;
|
|
186
230
|
}
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
231
|
+
const isLikelyDevServer = (0, isLikelyDevServer_1.getIsLikelyDevServer)();
|
|
232
|
+
const domain_auth = new URL(authorization_endpoint).origin.split("//")[1];
|
|
233
|
+
(0, assert_1.assert)(domain_auth !== undefined, "33921384");
|
|
234
|
+
const domain_here = window.location.origin.split("//")[1];
|
|
235
|
+
let isWellKnownProviderDomain = false;
|
|
236
|
+
let isIp = false;
|
|
237
|
+
const suggestedDeployments = (() => {
|
|
238
|
+
if (/^(?:\d{1,3}\.){3}\d{1,3}$|^\[?[A-Fa-f0-9:]+\]?$/.test(domain_auth)) {
|
|
239
|
+
isIp = true;
|
|
240
|
+
return [];
|
|
241
|
+
}
|
|
242
|
+
const baseDomain = (() => {
|
|
243
|
+
const segments = domain_auth.split(".");
|
|
244
|
+
if (segments.length >= 3) {
|
|
245
|
+
segments.shift();
|
|
246
|
+
}
|
|
247
|
+
return segments.join(".");
|
|
248
|
+
})();
|
|
249
|
+
{
|
|
250
|
+
const baseDomain_low = baseDomain.toLowerCase();
|
|
251
|
+
if (baseDomain_low.includes("auth0") ||
|
|
252
|
+
baseDomain_low.includes("clerk") ||
|
|
253
|
+
baseDomain_low.includes("microsoft") ||
|
|
254
|
+
baseDomain_low.includes("okta") ||
|
|
255
|
+
baseDomain_low.includes("aws")) {
|
|
256
|
+
isWellKnownProviderDomain = true;
|
|
257
|
+
return [];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
const baseUrl = new URL(homeUrlAndRedirectUri).pathname;
|
|
261
|
+
return [
|
|
262
|
+
`myapp.${baseDomain}`,
|
|
263
|
+
baseDomain === domain_auth ? undefined : baseDomain,
|
|
264
|
+
`${baseDomain}/${baseUrl === "/" ? "dashboard" : baseUrl}`
|
|
265
|
+
].filter(x => x !== undefined);
|
|
191
266
|
})();
|
|
192
|
-
if (
|
|
193
|
-
|
|
267
|
+
if (isLikelyDevServer) {
|
|
268
|
+
log?.([
|
|
269
|
+
"Detected localhost environment.",
|
|
270
|
+
"\nWhen reloading while logged in, you may briefly see",
|
|
271
|
+
"some URL params appear in the address bar.",
|
|
272
|
+
"\nThis happens because session restore via iframe is disabled,",
|
|
273
|
+
"the browser treats your auth server as a third party.",
|
|
274
|
+
`\nAuth server: ${domain_auth}`,
|
|
275
|
+
`\nApp domain: ${domain_here}`,
|
|
276
|
+
...(() => {
|
|
277
|
+
if (isIp) {
|
|
278
|
+
return [];
|
|
279
|
+
}
|
|
280
|
+
if (isWellKnownProviderDomain) {
|
|
281
|
+
return [
|
|
282
|
+
"\nYou seem to be using a well-known auth provider.",
|
|
283
|
+
"Check your provider's docs, some allow configuring",
|
|
284
|
+
`a your custom domain at least for the authorization endpoint.`,
|
|
285
|
+
"\nIf configured, oidc-spa will restore sessions silently",
|
|
286
|
+
"and improve the user experience."
|
|
287
|
+
];
|
|
288
|
+
}
|
|
289
|
+
return [
|
|
290
|
+
"\nOnce deployed under the same root domain as your auth server,",
|
|
291
|
+
"oidc-spa will use iframes to restore sessions silently.",
|
|
292
|
+
"\nSuggested deployments:",
|
|
293
|
+
...suggestedDeployments.map(d => `\n • ${d}`)
|
|
294
|
+
];
|
|
295
|
+
})(),
|
|
296
|
+
"\n\nMore info:",
|
|
297
|
+
"https://docs.oidc-spa.dev/v/v8/resources/end-of-third-party-cookies#when-are-cookies-considered-third-party"
|
|
298
|
+
].join(" "));
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
log?.([
|
|
302
|
+
"Silent session restore via iframe is disabled.",
|
|
303
|
+
`\nAuth server: ${domain_auth}`,
|
|
304
|
+
`App domain: ${domain_here}`,
|
|
305
|
+
"\nThey do not share a common root domain.",
|
|
306
|
+
...(() => {
|
|
307
|
+
if (isIp) {
|
|
308
|
+
return [];
|
|
309
|
+
}
|
|
310
|
+
if (isWellKnownProviderDomain) {
|
|
311
|
+
return [
|
|
312
|
+
"\nYou seem to be using a well-known auth provider.",
|
|
313
|
+
"Check if you can configure a custom auth domain.",
|
|
314
|
+
"\nIf so, oidc-spa can restore sessions silently",
|
|
315
|
+
"and improve the user experience."
|
|
316
|
+
];
|
|
317
|
+
}
|
|
318
|
+
return [
|
|
319
|
+
"\nTo improve the experience, here are some examples of deployment for your app:",
|
|
320
|
+
...suggestedDeployments.map(d => `\n • ${d}`)
|
|
321
|
+
];
|
|
322
|
+
})(),
|
|
323
|
+
"\nMore info:",
|
|
324
|
+
"https://docs.oidc-spa.dev/v/v8/resources/end-of-third-party-cookies#when-are-cookies-considered-third-party"
|
|
325
|
+
].join(" "));
|
|
194
326
|
}
|
|
195
|
-
log?.([
|
|
196
|
-
"Can't use iframe because your auth server is on a third party domain relative",
|
|
197
|
-
"to the domain of your app and third party cookies are blocked by navigators."
|
|
198
|
-
].join(" "));
|
|
199
327
|
return false;
|
|
200
328
|
}
|
|
201
|
-
// NOTE: Maybe not, it depend if the app can iframe itself.
|
|
202
329
|
return true;
|
|
203
330
|
})();
|
|
204
|
-
let isUserStoreInMemoryOnly;
|
|
205
|
-
const oidcClientTsUserManager =
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
});
|
|
226
|
-
const { evtRequestToPersistTokens } = globalContext;
|
|
227
|
-
evtRequestToPersistTokens.subscribe(({ configIdOfInstancePostingTheRequest }) => {
|
|
228
|
-
if (configIdOfInstancePostingTheRequest === configId) {
|
|
229
|
-
return;
|
|
331
|
+
let isUserStoreInMemoryOnly = undefined;
|
|
332
|
+
const oidcClientTsUserManager = oidcMetadata === undefined
|
|
333
|
+
? (0, createObjectThatThrowsIfAccessed_1.createObjectThatThrowsIfAccessed)({
|
|
334
|
+
debugMessage: "oidc-spa: Wrong assertion 43943"
|
|
335
|
+
})
|
|
336
|
+
: new oidc_client_ts_1.UserManager({
|
|
337
|
+
stateUrlParamValue: stateUrlParamValue_instance,
|
|
338
|
+
authority: issuerUri,
|
|
339
|
+
client_id: clientId,
|
|
340
|
+
redirect_uri: homeUrlAndRedirectUri,
|
|
341
|
+
silent_redirect_uri: homeUrlAndRedirectUri,
|
|
342
|
+
post_logout_redirect_uri: homeUrlAndRedirectUri,
|
|
343
|
+
response_mode: (0, isKeycloak_1.isKeycloak)({ issuerUri }) ? "fragment" : "query",
|
|
344
|
+
response_type: "code",
|
|
345
|
+
scope: Array.from(new Set(["openid", ...scopes])).join(" "),
|
|
346
|
+
automaticSilentRenew: false,
|
|
347
|
+
userStore: new oidc_client_ts_1.WebStorageStateStore({
|
|
348
|
+
store: (() => {
|
|
349
|
+
if (canUseIframe) {
|
|
350
|
+
isUserStoreInMemoryOnly = true;
|
|
351
|
+
return new oidc_client_ts_1.InMemoryWebStorage();
|
|
230
352
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
353
|
+
isUserStoreInMemoryOnly = false;
|
|
354
|
+
const storage = (0, EphemeralSessionStorage_1.createEphemeralSessionStorage)({
|
|
355
|
+
sessionStorageTtlMs: 3 * 60000
|
|
356
|
+
});
|
|
357
|
+
const { evtRequestToPersistTokens } = globalContext;
|
|
358
|
+
evtRequestToPersistTokens.subscribe(({ configIdOfInstancePostingTheRequest }) => {
|
|
359
|
+
if (configIdOfInstancePostingTheRequest === configId) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
storage.persistCurrentStateAndSubsequentChanges();
|
|
363
|
+
});
|
|
364
|
+
return storage;
|
|
365
|
+
})()
|
|
366
|
+
}),
|
|
367
|
+
stateStore: new oidc_client_ts_1.WebStorageStateStore({
|
|
368
|
+
store: localStorage,
|
|
369
|
+
prefix: StateData_1.STATE_STORE_KEY_PREFIX
|
|
370
|
+
}),
|
|
371
|
+
client_secret: __unsafe_clientSecret,
|
|
372
|
+
metadata: oidcMetadata
|
|
373
|
+
});
|
|
240
374
|
const evtInitializationOutcomeUserNotLoggedIn = (0, Evt_1.createEvt)();
|
|
241
375
|
const { loginOrGoToAuthServer } = (0, loginOrGoToAuthServer_1.createLoginOrGoToAuthServer)({
|
|
242
376
|
configId,
|
|
@@ -254,6 +388,11 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
254
388
|
});
|
|
255
389
|
const { completeLoginOrRefreshProcess } = await (0, ongoingLoginOrRefreshProcesses_1.startLoginOrRefreshProcess)();
|
|
256
390
|
const resultOfLoginProcess = await (async () => {
|
|
391
|
+
if (oidcMetadata === undefined) {
|
|
392
|
+
return (await Promise.resolve().then(() => __importStar(require("./diagnostic")))).createWellKnownOidcConfigurationEndpointUnreachableInitializationError({
|
|
393
|
+
issuerUri
|
|
394
|
+
});
|
|
395
|
+
}
|
|
257
396
|
handle_redirect_auth_response: {
|
|
258
397
|
let stateDataAndAuthResponse = undefined;
|
|
259
398
|
get_stateData_and_authResponse: {
|
|
@@ -383,6 +522,7 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
383
522
|
// NOTE: We almost never persist tokens, we have to only to support edge case
|
|
384
523
|
// of multiple oidc instance in a single App with no iframe support.
|
|
385
524
|
restore_from_session_storage: {
|
|
525
|
+
(0, assert_1.assert)(isUserStoreInMemoryOnly !== undefined, "3392204");
|
|
386
526
|
if (isUserStoreInMemoryOnly) {
|
|
387
527
|
break restore_from_session_storage;
|
|
388
528
|
}
|
|
@@ -440,11 +580,6 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
440
580
|
break actual_silent_signin;
|
|
441
581
|
}
|
|
442
582
|
if (!canUseIframe) {
|
|
443
|
-
if (!(await (0, getIsValidRemoteJson_1.getIsValidRemoteJson)(`${issuerUri}${(0, id_1.id)("/.well-known/openid-configuration")}`))) {
|
|
444
|
-
return (await Promise.resolve().then(() => __importStar(require("./diagnostic")))).createWellKnownOidcConfigurationEndpointUnreachableInitializationError({
|
|
445
|
-
issuerUri
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
583
|
break actual_silent_signin;
|
|
449
584
|
}
|
|
450
585
|
log?.("Trying to restore the auth from the http only cookie (silent signin with iframe)");
|
|
@@ -459,21 +594,13 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
459
594
|
log
|
|
460
595
|
});
|
|
461
596
|
(0, assert_1.assert)(result_loginSilent.outcome !== "token refreshed using refresh token", "876995");
|
|
462
|
-
if (result_loginSilent.outcome === "
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
return (await Promise.resolve().then(() => __importStar(require("./diagnostic")))).createIframeTimeoutInitializationError({
|
|
470
|
-
redirectUri: homeUrlAndRedirectUri,
|
|
471
|
-
clientId,
|
|
472
|
-
issuerUri,
|
|
473
|
-
noIframe
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
(0, assert_1.assert)(false);
|
|
597
|
+
if (result_loginSilent.outcome === "timeout") {
|
|
598
|
+
return (await Promise.resolve().then(() => __importStar(require("./diagnostic")))).createIframeTimeoutInitializationError({
|
|
599
|
+
redirectUri: homeUrlAndRedirectUri,
|
|
600
|
+
clientId,
|
|
601
|
+
issuerUri,
|
|
602
|
+
noIframe
|
|
603
|
+
});
|
|
477
604
|
}
|
|
478
605
|
(0, assert_1.assert)();
|
|
479
606
|
const { authResponse } = result_loginSilent;
|
|
@@ -517,8 +644,7 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
517
644
|
configIdOfInstancePostingTheRequest: configId
|
|
518
645
|
});
|
|
519
646
|
}
|
|
520
|
-
|
|
521
|
-
loginOrGoToAuthServer({
|
|
647
|
+
await loginOrGoToAuthServer({
|
|
522
648
|
action: "login",
|
|
523
649
|
doForceReloadOnBfCache: true,
|
|
524
650
|
redirectUrl: (0, earlyInit_1.getRootRelativeOriginalLocationHref)(),
|
|
@@ -535,15 +661,7 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
535
661
|
return "directly redirect if active session show login otherwise";
|
|
536
662
|
}
|
|
537
663
|
return "ensure no interaction";
|
|
538
|
-
})()
|
|
539
|
-
onCantFetchWellKnownEndpointError: () => {
|
|
540
|
-
dCantFetchWellKnownEndpointOrNever.resolve();
|
|
541
|
-
}
|
|
542
|
-
});
|
|
543
|
-
await dCantFetchWellKnownEndpointOrNever.pr;
|
|
544
|
-
return (await Promise.resolve().then(() => __importStar(require("./diagnostic")))).createFailedToFetchTokenEndpointInitializationError({
|
|
545
|
-
clientId,
|
|
546
|
-
issuerUri
|
|
664
|
+
})()
|
|
547
665
|
});
|
|
548
666
|
}
|
|
549
667
|
if (authResponse_error !== undefined) {
|
|
@@ -630,11 +748,7 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
630
748
|
transformUrlBeforeRedirect_local: transformUrlBeforeRedirect,
|
|
631
749
|
interaction: (0, persistedAuthState_1.getPersistedAuthState)({ configId }) === "explicitly logged out"
|
|
632
750
|
? "ensure interaction"
|
|
633
|
-
: "directly redirect if active session show login otherwise"
|
|
634
|
-
onCantFetchWellKnownEndpointError: () => {
|
|
635
|
-
log?.("Login called but the auth server seems to be down..");
|
|
636
|
-
alert("Authentication unavailable please try again later.");
|
|
637
|
-
}
|
|
751
|
+
: "directly redirect if active session show login otherwise"
|
|
638
752
|
});
|
|
639
753
|
},
|
|
640
754
|
initializationError: undefined
|
|
@@ -818,14 +932,7 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
818
932
|
extraQueryParams_local: undefined,
|
|
819
933
|
transformUrlBeforeRedirect_local: undefined,
|
|
820
934
|
doNavigateBackToLastPublicUrlIfTheTheUserNavigateBack: false,
|
|
821
|
-
interaction: "directly redirect if active session show login otherwise"
|
|
822
|
-
onCantFetchWellKnownEndpointError: () => {
|
|
823
|
-
log?.([
|
|
824
|
-
"The auth server seems to be down while we needed to refresh the token",
|
|
825
|
-
"with a full page redirect. Reloading the page"
|
|
826
|
-
].join(" "));
|
|
827
|
-
window.location.reload();
|
|
828
|
-
}
|
|
935
|
+
interaction: "directly redirect if active session show login otherwise"
|
|
829
936
|
});
|
|
830
937
|
(0, assert_1.assert)(false, "136134");
|
|
831
938
|
};
|
|
@@ -851,9 +958,9 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
851
958
|
autoLogin,
|
|
852
959
|
log
|
|
853
960
|
});
|
|
854
|
-
if (result_loginSilent.outcome === "
|
|
961
|
+
if (result_loginSilent.outcome === "timeout") {
|
|
855
962
|
log?.([
|
|
856
|
-
`Silent refresh of the token failed
|
|
963
|
+
`Silent refresh of the token failed the iframe didn't post a response (timeout).`,
|
|
857
964
|
`This isn't recoverable, reloading the page.`
|
|
858
965
|
].join(" "));
|
|
859
966
|
window.location.reload();
|
|
@@ -991,11 +1098,7 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
991
1098
|
action: "go to auth server",
|
|
992
1099
|
redirectUrl: redirectUrl ?? window.location.href,
|
|
993
1100
|
extraQueryParams_local: extraQueryParams,
|
|
994
|
-
transformUrlBeforeRedirect_local: transformUrlBeforeRedirect
|
|
995
|
-
onCantFetchWellKnownEndpointError: () => {
|
|
996
|
-
log?.("goToAuthServer called but the auth server seems to be down..");
|
|
997
|
-
alert("Authentication unavailable please try again later.");
|
|
998
|
-
}
|
|
1101
|
+
transformUrlBeforeRedirect_local: transformUrlBeforeRedirect
|
|
999
1102
|
}),
|
|
1000
1103
|
backFromAuthServer: resultOfLoginProcess.backFromAuthServer,
|
|
1001
1104
|
isNewBrowserSession: (() => {
|