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/esm/core/OidcMetadata.js
CHANGED
|
@@ -1,3 +1,57 @@
|
|
|
1
1
|
import { assert } from "../tools/tsafe/assert";
|
|
2
|
+
import { getIsLikelyDevServer } from "../tools/isLikelyDevServer";
|
|
2
3
|
assert;
|
|
4
|
+
export const WELL_KNOWN_PATH = "/.well-known/openid-configuration";
|
|
5
|
+
function getSessionStorageKey(params) {
|
|
6
|
+
const { issuerUri } = params;
|
|
7
|
+
return `oidc-spa:openid-configuration:${issuerUri}`;
|
|
8
|
+
}
|
|
9
|
+
function readSessionStorage(params) {
|
|
10
|
+
const { issuerUri } = params;
|
|
11
|
+
const value = sessionStorage.getItem(getSessionStorageKey({ issuerUri }));
|
|
12
|
+
if (value === null) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
return JSON.parse(value);
|
|
16
|
+
}
|
|
17
|
+
function setSessionStorage(params) {
|
|
18
|
+
const { issuerUri, oidcMetadata } = params;
|
|
19
|
+
sessionStorage.setItem(getSessionStorageKey({ issuerUri }), JSON.stringify(oidcMetadata));
|
|
20
|
+
}
|
|
21
|
+
export async function fetchOidcMetadata(params) {
|
|
22
|
+
const { issuerUri } = params;
|
|
23
|
+
from_cache: {
|
|
24
|
+
const oidcMetadata = readSessionStorage({ issuerUri });
|
|
25
|
+
if (oidcMetadata === undefined) {
|
|
26
|
+
break from_cache;
|
|
27
|
+
}
|
|
28
|
+
return oidcMetadata;
|
|
29
|
+
}
|
|
30
|
+
let oidcMetadata;
|
|
31
|
+
try {
|
|
32
|
+
const response = await fetch(`${issuerUri}${WELL_KNOWN_PATH}`, {
|
|
33
|
+
headers: {
|
|
34
|
+
Accept: "application/jwk-set+json, application/json"
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
throw new Error();
|
|
39
|
+
}
|
|
40
|
+
const obj = await response.json();
|
|
41
|
+
{
|
|
42
|
+
const { authorization_endpoint } = obj;
|
|
43
|
+
if (typeof authorization_endpoint !== "string") {
|
|
44
|
+
throw new Error();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
oidcMetadata = obj;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
if (!getIsLikelyDevServer()) {
|
|
53
|
+
setSessionStorage({ issuerUri, oidcMetadata });
|
|
54
|
+
}
|
|
55
|
+
return oidcMetadata;
|
|
56
|
+
}
|
|
3
57
|
//# sourceMappingURL=OidcMetadata.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OidcMetadata.js","sourceRoot":"","sources":["../../src/core/OidcMetadata.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAe,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"OidcMetadata.js","sourceRoot":"","sources":["../../src/core/OidcMetadata.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAe,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AA6QlE,MAAsD,CAAC;AAEvD,MAAM,CAAC,MAAM,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;AAED,MAAM,CAAC,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,eAAe,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,oBAAoB,EAAE,EAAE,CAAC;QAC1B,iBAAiB,CAAC,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,OAAO,YAAY,CAAC;AACxB,CAAC"}
|
package/esm/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/esm/core/createOidc.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { UserManager as OidcClientTsUserManager, WebStorageStateStore, InMemoryWebStorage } from "../vendor/frontend/oidc-client-ts";
|
|
2
|
+
import { fetchOidcMetadata } from "./OidcMetadata";
|
|
2
3
|
import { assert, is } from "../tools/tsafe/assert";
|
|
3
4
|
import { id } from "../tools/tsafe/id";
|
|
4
5
|
import { setTimeout, clearTimeout } from "../tools/workerTimers";
|
|
@@ -26,9 +27,12 @@ import { createGetIsNewBrowserSession } from "./isNewBrowserSession";
|
|
|
26
27
|
import { getIsOnline } from "../tools/getIsOnline";
|
|
27
28
|
import { isKeycloak } from "../keycloak/isKeycloak";
|
|
28
29
|
import { INFINITY_TIME } from "../tools/INFINITY_TIME";
|
|
29
|
-
import {
|
|
30
|
+
import { prShouldLoadApp } from "./prShouldLoadApp";
|
|
31
|
+
import { getBASE_URL } from "./BASE_URL";
|
|
32
|
+
import { getIsLikelyDevServer } from "../tools/isLikelyDevServer";
|
|
33
|
+
import { createObjectThatThrowsIfAccessed } from "../tools/createObjectThatThrowsIfAccessed";
|
|
30
34
|
// NOTE: Replaced at build time
|
|
31
|
-
const VERSION = "8.1
|
|
35
|
+
const VERSION = "8.2.1";
|
|
32
36
|
const globalContext = {
|
|
33
37
|
prOidcByConfigId: new Map(),
|
|
34
38
|
hasLogoutBeenCalled: id(false),
|
|
@@ -102,7 +106,23 @@ export async function createOidc(params) {
|
|
|
102
106
|
return oidc;
|
|
103
107
|
}
|
|
104
108
|
export async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
105
|
-
|
|
109
|
+
{
|
|
110
|
+
const timer = window.setTimeout(() => {
|
|
111
|
+
console.warn([
|
|
112
|
+
"oidc-spa: Setup error.",
|
|
113
|
+
"oidcEarlyInit() wasn't called.",
|
|
114
|
+
"This is supposed to be handled by the oidc-spa Vite plugin",
|
|
115
|
+
"or manually in other environments."
|
|
116
|
+
].join(" "));
|
|
117
|
+
}, 3000);
|
|
118
|
+
const shouldLoadApp = await prShouldLoadApp;
|
|
119
|
+
window.clearTimeout(timer);
|
|
120
|
+
if (!shouldLoadApp) {
|
|
121
|
+
return new Promise(() => { });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
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;
|
|
125
|
+
const BASE_URL_params = params.BASE_URL ?? params.homeUrl;
|
|
106
126
|
const { issuerUri, clientId, scopes, configId, log } = preProcessedParams;
|
|
107
127
|
const getExtraQueryParams = (() => {
|
|
108
128
|
if (extraQueryParamsOrGetter === undefined) {
|
|
@@ -123,7 +143,24 @@ export async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
123
143
|
return extraTokenParamsOrGetter;
|
|
124
144
|
})();
|
|
125
145
|
const homeUrlAndRedirectUri = toFullyQualifiedUrl({
|
|
126
|
-
urlish:
|
|
146
|
+
urlish: (() => {
|
|
147
|
+
if (BASE_URL_params !== undefined) {
|
|
148
|
+
return BASE_URL_params;
|
|
149
|
+
}
|
|
150
|
+
const BASE_URL = getBASE_URL();
|
|
151
|
+
if (BASE_URL === undefined) {
|
|
152
|
+
throw new Error([
|
|
153
|
+
"oidc-spa: If you do not use the oidc-spa Vite plugin",
|
|
154
|
+
"you must provide the BASE_URL to the earlyInit() examples:",
|
|
155
|
+
"oidcSpaEarlyInit({ BASE_URL: import.meta.env.BASE_URL })",
|
|
156
|
+
"oidcSpaEarlyInit({ BASE_URL: '/' })",
|
|
157
|
+
"",
|
|
158
|
+
"You can also pass this parameter to createOidc({ BASE_URL: '...' })",
|
|
159
|
+
"or bootstrapOidc({ BASE_URL: '...' })"
|
|
160
|
+
].join("\n"));
|
|
161
|
+
}
|
|
162
|
+
return BASE_URL;
|
|
163
|
+
})(),
|
|
127
164
|
doAssertNoQueryParams: true,
|
|
128
165
|
doOutputWithTrailingSlash: true
|
|
129
166
|
});
|
|
@@ -135,71 +172,168 @@ export async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
135
172
|
homeUrlAndRedirectUri
|
|
136
173
|
}, null, 2)}`);
|
|
137
174
|
const stateUrlParamValue_instance = generateStateUrlParamValue();
|
|
175
|
+
const oidcMetadata = __metadata ?? (await fetchOidcMetadata({ issuerUri }));
|
|
138
176
|
const canUseIframe = (() => {
|
|
139
177
|
if (noIframe) {
|
|
140
178
|
return false;
|
|
141
179
|
}
|
|
142
180
|
third_party_cookies: {
|
|
143
|
-
|
|
181
|
+
if (oidcMetadata === undefined) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
const { authorization_endpoint } = oidcMetadata;
|
|
185
|
+
assert(authorization_endpoint !== undefined, "Missing authorization_endpoint on the provided __metadata");
|
|
186
|
+
const isOidcServerThirdPartyRelativeToApp = !getHaveSharedParentDomain({
|
|
144
187
|
url1: window.location.origin,
|
|
145
|
-
|
|
146
|
-
|
|
188
|
+
// TODO: No, here we should test against the authorization endpoint!
|
|
189
|
+
url2: authorization_endpoint
|
|
190
|
+
});
|
|
147
191
|
if (!isOidcServerThirdPartyRelativeToApp) {
|
|
148
192
|
break third_party_cookies;
|
|
149
193
|
}
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
194
|
+
const isLikelyDevServer = getIsLikelyDevServer();
|
|
195
|
+
const domain_auth = new URL(authorization_endpoint).origin.split("//")[1];
|
|
196
|
+
assert(domain_auth !== undefined, "33921384");
|
|
197
|
+
const domain_here = window.location.origin.split("//")[1];
|
|
198
|
+
let isWellKnownProviderDomain = false;
|
|
199
|
+
let isIp = false;
|
|
200
|
+
const suggestedDeployments = (() => {
|
|
201
|
+
if (/^(?:\d{1,3}\.){3}\d{1,3}$|^\[?[A-Fa-f0-9:]+\]?$/.test(domain_auth)) {
|
|
202
|
+
isIp = true;
|
|
203
|
+
return [];
|
|
204
|
+
}
|
|
205
|
+
const baseDomain = (() => {
|
|
206
|
+
const segments = domain_auth.split(".");
|
|
207
|
+
if (segments.length >= 3) {
|
|
208
|
+
segments.shift();
|
|
209
|
+
}
|
|
210
|
+
return segments.join(".");
|
|
211
|
+
})();
|
|
212
|
+
{
|
|
213
|
+
const baseDomain_low = baseDomain.toLowerCase();
|
|
214
|
+
if (baseDomain_low.includes("auth0") ||
|
|
215
|
+
baseDomain_low.includes("clerk") ||
|
|
216
|
+
baseDomain_low.includes("microsoft") ||
|
|
217
|
+
baseDomain_low.includes("okta") ||
|
|
218
|
+
baseDomain_low.includes("aws")) {
|
|
219
|
+
isWellKnownProviderDomain = true;
|
|
220
|
+
return [];
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const baseUrl = new URL(homeUrlAndRedirectUri).pathname;
|
|
224
|
+
return [
|
|
225
|
+
`myapp.${baseDomain}`,
|
|
226
|
+
baseDomain === domain_auth ? undefined : baseDomain,
|
|
227
|
+
`${baseDomain}/${baseUrl === "/" ? "dashboard" : baseUrl}`
|
|
228
|
+
].filter(x => x !== undefined);
|
|
154
229
|
})();
|
|
155
|
-
if (
|
|
156
|
-
|
|
230
|
+
if (isLikelyDevServer) {
|
|
231
|
+
log?.([
|
|
232
|
+
"Detected localhost environment.",
|
|
233
|
+
"\nWhen reloading while logged in, you may briefly see",
|
|
234
|
+
"some URL params appear in the address bar.",
|
|
235
|
+
"\nThis happens because session restore via iframe is disabled,",
|
|
236
|
+
"the browser treats your auth server as a third party.",
|
|
237
|
+
`\nAuth server: ${domain_auth}`,
|
|
238
|
+
`\nApp domain: ${domain_here}`,
|
|
239
|
+
...(() => {
|
|
240
|
+
if (isIp) {
|
|
241
|
+
return [];
|
|
242
|
+
}
|
|
243
|
+
if (isWellKnownProviderDomain) {
|
|
244
|
+
return [
|
|
245
|
+
"\nYou seem to be using a well-known auth provider.",
|
|
246
|
+
"Check your provider's docs, some allow configuring",
|
|
247
|
+
`a your custom domain at least for the authorization endpoint.`,
|
|
248
|
+
"\nIf configured, oidc-spa will restore sessions silently",
|
|
249
|
+
"and improve the user experience."
|
|
250
|
+
];
|
|
251
|
+
}
|
|
252
|
+
return [
|
|
253
|
+
"\nOnce deployed under the same root domain as your auth server,",
|
|
254
|
+
"oidc-spa will use iframes to restore sessions silently.",
|
|
255
|
+
"\nSuggested deployments:",
|
|
256
|
+
...suggestedDeployments.map(d => `\n • ${d}`)
|
|
257
|
+
];
|
|
258
|
+
})(),
|
|
259
|
+
"\n\nMore info:",
|
|
260
|
+
"https://docs.oidc-spa.dev/v/v8/resources/end-of-third-party-cookies#when-are-cookies-considered-third-party"
|
|
261
|
+
].join(" "));
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
log?.([
|
|
265
|
+
"Silent session restore via iframe is disabled.",
|
|
266
|
+
`\nAuth server: ${domain_auth}`,
|
|
267
|
+
`App domain: ${domain_here}`,
|
|
268
|
+
"\nThey do not share a common root domain.",
|
|
269
|
+
...(() => {
|
|
270
|
+
if (isIp) {
|
|
271
|
+
return [];
|
|
272
|
+
}
|
|
273
|
+
if (isWellKnownProviderDomain) {
|
|
274
|
+
return [
|
|
275
|
+
"\nYou seem to be using a well-known auth provider.",
|
|
276
|
+
"Check if you can configure a custom auth domain.",
|
|
277
|
+
"\nIf so, oidc-spa can restore sessions silently",
|
|
278
|
+
"and improve the user experience."
|
|
279
|
+
];
|
|
280
|
+
}
|
|
281
|
+
return [
|
|
282
|
+
"\nTo improve the experience, here are some examples of deployment for your app:",
|
|
283
|
+
...suggestedDeployments.map(d => `\n • ${d}`)
|
|
284
|
+
];
|
|
285
|
+
})(),
|
|
286
|
+
"\nMore info:",
|
|
287
|
+
"https://docs.oidc-spa.dev/v/v8/resources/end-of-third-party-cookies#when-are-cookies-considered-third-party"
|
|
288
|
+
].join(" "));
|
|
157
289
|
}
|
|
158
|
-
log?.([
|
|
159
|
-
"Can't use iframe because your auth server is on a third party domain relative",
|
|
160
|
-
"to the domain of your app and third party cookies are blocked by navigators."
|
|
161
|
-
].join(" "));
|
|
162
290
|
return false;
|
|
163
291
|
}
|
|
164
|
-
// NOTE: Maybe not, it depend if the app can iframe itself.
|
|
165
292
|
return true;
|
|
166
293
|
})();
|
|
167
|
-
let isUserStoreInMemoryOnly;
|
|
168
|
-
const oidcClientTsUserManager =
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
});
|
|
189
|
-
const { evtRequestToPersistTokens } = globalContext;
|
|
190
|
-
evtRequestToPersistTokens.subscribe(({ configIdOfInstancePostingTheRequest }) => {
|
|
191
|
-
if (configIdOfInstancePostingTheRequest === configId) {
|
|
192
|
-
return;
|
|
294
|
+
let isUserStoreInMemoryOnly = undefined;
|
|
295
|
+
const oidcClientTsUserManager = oidcMetadata === undefined
|
|
296
|
+
? createObjectThatThrowsIfAccessed({
|
|
297
|
+
debugMessage: "oidc-spa: Wrong assertion 43943"
|
|
298
|
+
})
|
|
299
|
+
: new OidcClientTsUserManager({
|
|
300
|
+
stateUrlParamValue: stateUrlParamValue_instance,
|
|
301
|
+
authority: issuerUri,
|
|
302
|
+
client_id: clientId,
|
|
303
|
+
redirect_uri: homeUrlAndRedirectUri,
|
|
304
|
+
silent_redirect_uri: homeUrlAndRedirectUri,
|
|
305
|
+
post_logout_redirect_uri: homeUrlAndRedirectUri,
|
|
306
|
+
response_mode: isKeycloak({ issuerUri }) ? "fragment" : "query",
|
|
307
|
+
response_type: "code",
|
|
308
|
+
scope: Array.from(new Set(["openid", ...scopes])).join(" "),
|
|
309
|
+
automaticSilentRenew: false,
|
|
310
|
+
userStore: new WebStorageStateStore({
|
|
311
|
+
store: (() => {
|
|
312
|
+
if (canUseIframe) {
|
|
313
|
+
isUserStoreInMemoryOnly = true;
|
|
314
|
+
return new InMemoryWebStorage();
|
|
193
315
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
316
|
+
isUserStoreInMemoryOnly = false;
|
|
317
|
+
const storage = createEphemeralSessionStorage({
|
|
318
|
+
sessionStorageTtlMs: 3 * 60000
|
|
319
|
+
});
|
|
320
|
+
const { evtRequestToPersistTokens } = globalContext;
|
|
321
|
+
evtRequestToPersistTokens.subscribe(({ configIdOfInstancePostingTheRequest }) => {
|
|
322
|
+
if (configIdOfInstancePostingTheRequest === configId) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
storage.persistCurrentStateAndSubsequentChanges();
|
|
326
|
+
});
|
|
327
|
+
return storage;
|
|
328
|
+
})()
|
|
329
|
+
}),
|
|
330
|
+
stateStore: new WebStorageStateStore({
|
|
331
|
+
store: localStorage,
|
|
332
|
+
prefix: STATE_STORE_KEY_PREFIX
|
|
333
|
+
}),
|
|
334
|
+
client_secret: __unsafe_clientSecret,
|
|
335
|
+
metadata: oidcMetadata
|
|
336
|
+
});
|
|
203
337
|
const evtInitializationOutcomeUserNotLoggedIn = createEvt();
|
|
204
338
|
const { loginOrGoToAuthServer } = createLoginOrGoToAuthServer({
|
|
205
339
|
configId,
|
|
@@ -217,6 +351,11 @@ export async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
217
351
|
});
|
|
218
352
|
const { completeLoginOrRefreshProcess } = await startLoginOrRefreshProcess();
|
|
219
353
|
const resultOfLoginProcess = await (async () => {
|
|
354
|
+
if (oidcMetadata === undefined) {
|
|
355
|
+
return (await import("./diagnostic")).createWellKnownOidcConfigurationEndpointUnreachableInitializationError({
|
|
356
|
+
issuerUri
|
|
357
|
+
});
|
|
358
|
+
}
|
|
220
359
|
handle_redirect_auth_response: {
|
|
221
360
|
let stateDataAndAuthResponse = undefined;
|
|
222
361
|
get_stateData_and_authResponse: {
|
|
@@ -346,6 +485,7 @@ export async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
346
485
|
// NOTE: We almost never persist tokens, we have to only to support edge case
|
|
347
486
|
// of multiple oidc instance in a single App with no iframe support.
|
|
348
487
|
restore_from_session_storage: {
|
|
488
|
+
assert(isUserStoreInMemoryOnly !== undefined, "3392204");
|
|
349
489
|
if (isUserStoreInMemoryOnly) {
|
|
350
490
|
break restore_from_session_storage;
|
|
351
491
|
}
|
|
@@ -403,11 +543,6 @@ export async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
403
543
|
break actual_silent_signin;
|
|
404
544
|
}
|
|
405
545
|
if (!canUseIframe) {
|
|
406
|
-
if (!(await getIsValidRemoteJson(`${issuerUri}${id("/.well-known/openid-configuration")}`))) {
|
|
407
|
-
return (await import("./diagnostic")).createWellKnownOidcConfigurationEndpointUnreachableInitializationError({
|
|
408
|
-
issuerUri
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
546
|
break actual_silent_signin;
|
|
412
547
|
}
|
|
413
548
|
log?.("Trying to restore the auth from the http only cookie (silent signin with iframe)");
|
|
@@ -422,21 +557,13 @@ export async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
422
557
|
log
|
|
423
558
|
});
|
|
424
559
|
assert(result_loginSilent.outcome !== "token refreshed using refresh token", "876995");
|
|
425
|
-
if (result_loginSilent.outcome === "
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
return (await import("./diagnostic")).createIframeTimeoutInitializationError({
|
|
433
|
-
redirectUri: homeUrlAndRedirectUri,
|
|
434
|
-
clientId,
|
|
435
|
-
issuerUri,
|
|
436
|
-
noIframe
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
assert(false);
|
|
560
|
+
if (result_loginSilent.outcome === "timeout") {
|
|
561
|
+
return (await import("./diagnostic")).createIframeTimeoutInitializationError({
|
|
562
|
+
redirectUri: homeUrlAndRedirectUri,
|
|
563
|
+
clientId,
|
|
564
|
+
issuerUri,
|
|
565
|
+
noIframe
|
|
566
|
+
});
|
|
440
567
|
}
|
|
441
568
|
assert();
|
|
442
569
|
const { authResponse } = result_loginSilent;
|
|
@@ -480,8 +607,7 @@ export async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
480
607
|
configIdOfInstancePostingTheRequest: configId
|
|
481
608
|
});
|
|
482
609
|
}
|
|
483
|
-
|
|
484
|
-
loginOrGoToAuthServer({
|
|
610
|
+
await loginOrGoToAuthServer({
|
|
485
611
|
action: "login",
|
|
486
612
|
doForceReloadOnBfCache: true,
|
|
487
613
|
redirectUrl: getRootRelativeOriginalLocationHref(),
|
|
@@ -498,15 +624,7 @@ export async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
498
624
|
return "directly redirect if active session show login otherwise";
|
|
499
625
|
}
|
|
500
626
|
return "ensure no interaction";
|
|
501
|
-
})()
|
|
502
|
-
onCantFetchWellKnownEndpointError: () => {
|
|
503
|
-
dCantFetchWellKnownEndpointOrNever.resolve();
|
|
504
|
-
}
|
|
505
|
-
});
|
|
506
|
-
await dCantFetchWellKnownEndpointOrNever.pr;
|
|
507
|
-
return (await import("./diagnostic")).createFailedToFetchTokenEndpointInitializationError({
|
|
508
|
-
clientId,
|
|
509
|
-
issuerUri
|
|
627
|
+
})()
|
|
510
628
|
});
|
|
511
629
|
}
|
|
512
630
|
if (authResponse_error !== undefined) {
|
|
@@ -593,11 +711,7 @@ export async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
593
711
|
transformUrlBeforeRedirect_local: transformUrlBeforeRedirect,
|
|
594
712
|
interaction: getPersistedAuthState({ configId }) === "explicitly logged out"
|
|
595
713
|
? "ensure interaction"
|
|
596
|
-
: "directly redirect if active session show login otherwise"
|
|
597
|
-
onCantFetchWellKnownEndpointError: () => {
|
|
598
|
-
log?.("Login called but the auth server seems to be down..");
|
|
599
|
-
alert("Authentication unavailable please try again later.");
|
|
600
|
-
}
|
|
714
|
+
: "directly redirect if active session show login otherwise"
|
|
601
715
|
});
|
|
602
716
|
},
|
|
603
717
|
initializationError: undefined
|
|
@@ -781,14 +895,7 @@ export async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
781
895
|
extraQueryParams_local: undefined,
|
|
782
896
|
transformUrlBeforeRedirect_local: undefined,
|
|
783
897
|
doNavigateBackToLastPublicUrlIfTheTheUserNavigateBack: false,
|
|
784
|
-
interaction: "directly redirect if active session show login otherwise"
|
|
785
|
-
onCantFetchWellKnownEndpointError: () => {
|
|
786
|
-
log?.([
|
|
787
|
-
"The auth server seems to be down while we needed to refresh the token",
|
|
788
|
-
"with a full page redirect. Reloading the page"
|
|
789
|
-
].join(" "));
|
|
790
|
-
window.location.reload();
|
|
791
|
-
}
|
|
898
|
+
interaction: "directly redirect if active session show login otherwise"
|
|
792
899
|
});
|
|
793
900
|
assert(false, "136134");
|
|
794
901
|
};
|
|
@@ -814,9 +921,9 @@ export async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
814
921
|
autoLogin,
|
|
815
922
|
log
|
|
816
923
|
});
|
|
817
|
-
if (result_loginSilent.outcome === "
|
|
924
|
+
if (result_loginSilent.outcome === "timeout") {
|
|
818
925
|
log?.([
|
|
819
|
-
`Silent refresh of the token failed
|
|
926
|
+
`Silent refresh of the token failed the iframe didn't post a response (timeout).`,
|
|
820
927
|
`This isn't recoverable, reloading the page.`
|
|
821
928
|
].join(" "));
|
|
822
929
|
window.location.reload();
|
|
@@ -954,11 +1061,7 @@ export async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
954
1061
|
action: "go to auth server",
|
|
955
1062
|
redirectUrl: redirectUrl ?? window.location.href,
|
|
956
1063
|
extraQueryParams_local: extraQueryParams,
|
|
957
|
-
transformUrlBeforeRedirect_local: transformUrlBeforeRedirect
|
|
958
|
-
onCantFetchWellKnownEndpointError: () => {
|
|
959
|
-
log?.("goToAuthServer called but the auth server seems to be down..");
|
|
960
|
-
alert("Authentication unavailable please try again later.");
|
|
961
|
-
}
|
|
1064
|
+
transformUrlBeforeRedirect_local: transformUrlBeforeRedirect
|
|
962
1065
|
}),
|
|
963
1066
|
backFromAuthServer: resultOfLoginProcess.backFromAuthServer,
|
|
964
1067
|
isNewBrowserSession: (() => {
|