oidc-spa 8.2.1 → 8.2.3
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/AuthResponse.d.ts +0 -5
- package/core/AuthResponse.js +0 -25
- package/core/AuthResponse.js.map +1 -1
- package/core/createOidc.d.ts +49 -16
- package/core/createOidc.js +97 -122
- package/core/createOidc.js.map +1 -1
- package/core/desiredPostLoginRedirectUrl.d.ts +4 -0
- package/core/desiredPostLoginRedirectUrl.js +12 -0
- package/core/desiredPostLoginRedirectUrl.js.map +1 -0
- package/core/diagnostic.d.ts +1 -1
- package/core/diagnostic.js +3 -3
- package/core/diagnostic.js.map +1 -1
- package/core/instancesThatCantUseIframes.d.ts +2 -0
- package/core/instancesThatCantUseIframes.js +20 -0
- package/core/instancesThatCantUseIframes.js.map +1 -0
- package/core/loginOrGoToAuthServer.d.ts +1 -0
- package/core/loginOrGoToAuthServer.js +3 -0
- package/core/loginOrGoToAuthServer.js.map +1 -1
- package/core/persistedAuthState.d.ts +1 -0
- package/core/persistedAuthState.js +14 -4
- package/core/persistedAuthState.js.map +1 -1
- package/esm/angular.d.ts +27 -4
- package/esm/angular.js +28 -6
- package/esm/angular.js.map +1 -1
- package/esm/core/AuthResponse.d.ts +0 -5
- package/esm/core/AuthResponse.js +0 -23
- package/esm/core/AuthResponse.js.map +1 -1
- package/esm/core/createOidc.d.ts +49 -16
- package/esm/core/createOidc.js +98 -123
- package/esm/core/createOidc.js.map +1 -1
- package/esm/core/desiredPostLoginRedirectUrl.d.ts +4 -0
- package/esm/core/desiredPostLoginRedirectUrl.js +8 -0
- package/esm/core/desiredPostLoginRedirectUrl.js.map +1 -0
- package/esm/core/diagnostic.d.ts +1 -1
- package/esm/core/diagnostic.js +3 -3
- package/esm/core/diagnostic.js.map +1 -1
- package/esm/core/instancesThatCantUseIframes.d.ts +2 -0
- package/esm/core/instancesThatCantUseIframes.js +16 -0
- package/esm/core/instancesThatCantUseIframes.js.map +1 -0
- package/esm/core/loginOrGoToAuthServer.d.ts +1 -0
- package/esm/core/loginOrGoToAuthServer.js +3 -0
- package/esm/core/loginOrGoToAuthServer.js.map +1 -1
- package/esm/core/persistedAuthState.d.ts +1 -0
- package/esm/core/persistedAuthState.js +14 -4
- package/esm/core/persistedAuthState.js.map +1 -1
- package/esm/keycloak/keycloak-js/Keycloak.d.ts +40 -0
- package/esm/keycloak/keycloak-js/Keycloak.js +2 -1
- package/esm/keycloak/keycloak-js/Keycloak.js.map +1 -1
- package/esm/react/react.js +24 -2
- package/esm/react/react.js.map +1 -1
- package/esm/react-spa/createOidcSpaApi.js +26 -4
- package/esm/react-spa/createOidcSpaApi.js.map +1 -1
- package/esm/react-spa/types.d.ts +26 -3
- package/esm/tanstack-start/react/createOidcSpaApi.js +25 -3
- package/esm/tanstack-start/react/createOidcSpaApi.js.map +1 -1
- package/esm/tanstack-start/react/types.d.ts +26 -3
- package/esm/tools/{EphemeralSessionStorage.d.ts → lazySessionStorage.d.ts} +4 -4
- package/esm/tools/lazySessionStorage.js +83 -0
- package/esm/tools/lazySessionStorage.js.map +1 -0
- package/keycloak/keycloak-js/Keycloak.d.ts +40 -0
- package/keycloak/keycloak-js/Keycloak.js +2 -1
- package/keycloak/keycloak-js/Keycloak.js.map +1 -1
- package/package.json +5 -1
- package/react/react.js +24 -2
- package/react/react.js.map +1 -1
- package/react-spa/createOidcSpaApi.js +26 -4
- package/react-spa/createOidcSpaApi.js.map +1 -1
- package/react-spa/types.d.ts +26 -3
- package/src/angular.ts +72 -18
- package/src/core/AuthResponse.ts +0 -36
- package/src/core/createOidc.ts +160 -173
- package/src/core/desiredPostLoginRedirectUrl.ts +9 -0
- package/src/core/diagnostic.ts +4 -4
- package/src/core/instancesThatCantUseIframes.ts +24 -0
- package/src/core/loginOrGoToAuthServer.ts +5 -0
- package/src/core/persistedAuthState.ts +27 -5
- package/src/keycloak/keycloak-js/Keycloak.ts +43 -1
- package/src/react/react.tsx +32 -3
- package/src/react-spa/createOidcSpaApi.tsx +34 -5
- package/src/react-spa/types.tsx +26 -3
- package/src/tanstack-start/react/createOidcSpaApi.tsx +33 -4
- package/src/tanstack-start/react/types.tsx +26 -3
- package/src/tools/lazySessionStorage.ts +123 -0
- package/src/vite-plugin/manageOptimizedDeps.ts +4 -1
- package/tools/{EphemeralSessionStorage.d.ts → lazySessionStorage.d.ts} +4 -4
- package/tools/lazySessionStorage.js +86 -0
- package/tools/lazySessionStorage.js.map +1 -0
- package/vite-plugin/manageOptimizedDeps.js +3 -1
- package/vite-plugin/manageOptimizedDeps.js.map +1 -1
- package/esm/tools/EphemeralSessionStorage.js +0 -143
- package/esm/tools/EphemeralSessionStorage.js.map +0 -1
- package/src/tools/EphemeralSessionStorage.ts +0 -225
- package/tools/EphemeralSessionStorage.js +0 -146
- package/tools/EphemeralSessionStorage.js.map +0 -1
package/core/AuthResponse.d.ts
CHANGED
|
@@ -3,8 +3,3 @@ export type AuthResponse = {
|
|
|
3
3
|
[key: string]: string | undefined;
|
|
4
4
|
};
|
|
5
5
|
export declare function authResponseToUrl(authResponse: AuthResponse): string;
|
|
6
|
-
export declare const setPersistedRedirectAuthResponses: (params: {
|
|
7
|
-
authResponses: AuthResponse[];
|
|
8
|
-
}) => void, getPersistedRedirectAuthResponses: () => {
|
|
9
|
-
authResponses: AuthResponse[];
|
|
10
|
-
};
|
package/core/AuthResponse.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.getPersistedRedirectAuthResponses = exports.setPersistedRedirectAuthResponses = void 0;
|
|
5
3
|
exports.authResponseToUrl = authResponseToUrl;
|
|
6
4
|
const urlSearchParams_1 = require("../tools/urlSearchParams");
|
|
7
|
-
const EphemeralSessionStorage_1 = require("../tools/EphemeralSessionStorage");
|
|
8
5
|
function authResponseToUrl(authResponse) {
|
|
9
6
|
let authResponseUrl = "https://dummy.com";
|
|
10
7
|
for (const [name, value] of Object.entries(authResponse)) {
|
|
@@ -21,26 +18,4 @@ function authResponseToUrl(authResponse) {
|
|
|
21
18
|
authResponseUrl = `${authResponseUrl}#${authResponseUrl.split("?")[1]}`;
|
|
22
19
|
return authResponseUrl;
|
|
23
20
|
}
|
|
24
|
-
_a = (() => {
|
|
25
|
-
const { getEphemeralSessionStorage } = (() => {
|
|
26
|
-
let cache = undefined;
|
|
27
|
-
const getEphemeralSessionStorage = () => (cache ?? (cache = (0, EphemeralSessionStorage_1.createEphemeralSessionStorage)({
|
|
28
|
-
sessionStorageTtlMs: 30000
|
|
29
|
-
})));
|
|
30
|
-
return { getEphemeralSessionStorage };
|
|
31
|
-
})();
|
|
32
|
-
const KEY = "oidc-spa:persisted-redirect-auth-response";
|
|
33
|
-
function setPersistedRedirectAuthResponses(params) {
|
|
34
|
-
const { authResponses } = params;
|
|
35
|
-
const storage = getEphemeralSessionStorage();
|
|
36
|
-
storage.persistCurrentStateAndSubsequentChanges();
|
|
37
|
-
storage.setItem(KEY, JSON.stringify(authResponses));
|
|
38
|
-
}
|
|
39
|
-
function getPersistedRedirectAuthResponses() {
|
|
40
|
-
const value = getEphemeralSessionStorage().getItem(KEY);
|
|
41
|
-
const authResponses = value === null ? [] : JSON.parse(value);
|
|
42
|
-
return { authResponses };
|
|
43
|
-
}
|
|
44
|
-
return { setPersistedRedirectAuthResponses, getPersistedRedirectAuthResponses };
|
|
45
|
-
})(), exports.setPersistedRedirectAuthResponses = _a.setPersistedRedirectAuthResponses, exports.getPersistedRedirectAuthResponses = _a.getPersistedRedirectAuthResponses;
|
|
46
21
|
//# sourceMappingURL=AuthResponse.js.map
|
package/core/AuthResponse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthResponse.js","sourceRoot":"","sources":["../src/core/AuthResponse.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AuthResponse.js","sourceRoot":"","sources":["../src/core/AuthResponse.ts"],"names":[],"mappings":";;AAOA,8CAkBC;AAzBD,8DAAkE;AAOlE,SAAgB,iBAAiB,CAAC,YAA0B;IACxD,IAAI,eAAe,GAAG,mBAAmB,CAAC;IAE1C,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;QACvD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACtB,SAAS;QACb,CAAC;QACD,eAAe,GAAG,IAAA,wCAAsB,EAAC;YACrC,GAAG,EAAE,eAAe;YACpB,IAAI;YACJ,KAAK;YACL,YAAY,EAAE,UAAU;SAC3B,CAAC,CAAC;IACP,CAAC;IAED,eAAe,GAAG,GAAG,eAAe,IAAI,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAExE,OAAO,eAAe,CAAC;AAC3B,CAAC"}
|
package/core/createOidc.d.ts
CHANGED
|
@@ -49,19 +49,6 @@ export type ParamsOfCreateOidc<DecodedIdToken extends Record<string, unknown> =
|
|
|
49
49
|
* extraTokenParams: { selectedCustomer: "xxx" }
|
|
50
50
|
*/
|
|
51
51
|
extraTokenParams?: Record<string, string | undefined> | (() => Record<string, string | undefined>);
|
|
52
|
-
/**
|
|
53
|
-
* Usage discouraged, it's here because we don't want to assume too much on your
|
|
54
|
-
* usecase but I can't think of a scenario where you would want anything
|
|
55
|
-
* other than the current page.
|
|
56
|
-
*
|
|
57
|
-
* Where to redirect after successful login.
|
|
58
|
-
* Default: window.location.href (here)
|
|
59
|
-
*
|
|
60
|
-
* It does not need to include the origin, eg: "/dashboard"
|
|
61
|
-
*
|
|
62
|
-
* This parameter can also be passed to login() directly as `redirectUrl`.
|
|
63
|
-
*/
|
|
64
|
-
postLoginRedirectUrl?: string;
|
|
65
52
|
decodedIdTokenSchema?: {
|
|
66
53
|
parse: (decodedIdToken_original: Oidc.Tokens.DecodedIdToken_OidcCoreSpec) => DecodedIdToken;
|
|
67
54
|
};
|
|
@@ -87,9 +74,42 @@ export type ParamsOfCreateOidc<DecodedIdToken extends Record<string, unknown> =
|
|
|
87
74
|
autoLogoutParams?: Parameters<Oidc.LoggedIn<any>["logout"]>[0];
|
|
88
75
|
autoLogin?: AutoLogin;
|
|
89
76
|
/**
|
|
77
|
+
* Determines how session restoration is handled.
|
|
78
|
+
* Session restoration allows users to stay logged in between visits
|
|
79
|
+
* without needing to explicitly sign in each time.
|
|
80
|
+
*
|
|
81
|
+
* Options:
|
|
82
|
+
*
|
|
83
|
+
* - **"auto" (default)**:
|
|
84
|
+
* Automatically selects the best method.
|
|
85
|
+
* If the app’s domain shares a common parent domain with the authorization endpoint,
|
|
86
|
+
* an iframe is used for silent session restoration.
|
|
87
|
+
* Otherwise, a full-page redirect is used.
|
|
88
|
+
*
|
|
89
|
+
* - **"full page redirect"**:
|
|
90
|
+
* Forces full-page reloads for session restoration.
|
|
91
|
+
* Use this if your application is served with a restrictive CSP
|
|
92
|
+
* (e.g., `Content-Security-Policy: frame-ancestors "none"`)
|
|
93
|
+
* or `X-Frame-Options: DENY`, and you cannot modify those headers.
|
|
94
|
+
* This mode provides a slightly less seamless UX and will lead oidc-spa to
|
|
95
|
+
* store tokens in `localStorage` if multiple OIDC clients are used
|
|
96
|
+
* (e.g., your app communicates with several APIs).
|
|
97
|
+
*
|
|
98
|
+
* - **"iframe"**:
|
|
99
|
+
* Forces iframe-based session restoration.
|
|
100
|
+
* In development, if you go in your browser setting and allow your auth server’s domain
|
|
101
|
+
* to set third-party cookies this value will let you test your app
|
|
102
|
+
* with the local dev server as it will behave in production.
|
|
103
|
+
*
|
|
104
|
+
* See: https://docs.oidc-spa.dev/v/v8/resources/third-party-cookies-and-session-restoration
|
|
105
|
+
*/
|
|
106
|
+
sessionRestorationMethod?: "iframe" | "full page redirect" | "auto";
|
|
107
|
+
/**
|
|
108
|
+
* @deprecated Use `sessionRestorationMethod: "full page redirect"` instead.
|
|
109
|
+
*
|
|
90
110
|
* Default: false
|
|
91
111
|
*
|
|
92
|
-
* See: https://docs.oidc-spa.dev/v/v8/resources/
|
|
112
|
+
* See: https://docs.oidc-spa.dev/v/v8/resources/third-party-cookies-and-session-restoration
|
|
93
113
|
*/
|
|
94
114
|
noIframe?: boolean;
|
|
95
115
|
debugLogs?: boolean;
|
|
@@ -136,13 +156,26 @@ export type ParamsOfCreateOidc<DecodedIdToken extends Record<string, unknown> =
|
|
|
136
156
|
BASE_URL?: string;
|
|
137
157
|
/** @deprecated: Use BASE_URL (same thing, just renamed). */
|
|
138
158
|
homeUrl?: string;
|
|
159
|
+
/**
|
|
160
|
+
* This parameter is irrelevant in most usecases.
|
|
161
|
+
* It tells where to redirect after a successful login or autoLogin.
|
|
162
|
+
*
|
|
163
|
+
* If you are not in autoLogin mode there is absolutely no reason to use
|
|
164
|
+
* this parameter since you can pass `login({ redirectUrl: "..." })`.
|
|
165
|
+
*
|
|
166
|
+
* It can only be useful in some edge case with `autoLogin: true`
|
|
167
|
+
* When you want to precisely redirect somewhere after login.
|
|
168
|
+
*
|
|
169
|
+
* This can make sense if you have multiple clients to talk with different
|
|
170
|
+
* API and no iframe capabilities.
|
|
171
|
+
*/
|
|
172
|
+
postLoginRedirectUrl?: string;
|
|
139
173
|
};
|
|
140
174
|
/** @see: https://docs.oidc-spa.dev/v/v8/usage */
|
|
141
175
|
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>>;
|
|
142
|
-
export declare function createOidc_nonMemoized<DecodedIdToken extends Record<string, unknown>, AutoLogin extends boolean>(params: Omit<ParamsOfCreateOidc<DecodedIdToken, AutoLogin>, "issuerUri" | "clientId" | "
|
|
176
|
+
export declare function createOidc_nonMemoized<DecodedIdToken extends Record<string, unknown>, AutoLogin extends boolean>(params: Omit<ParamsOfCreateOidc<DecodedIdToken, AutoLogin>, "issuerUri" | "clientId" | "debugLogs">, preProcessedParams: {
|
|
143
177
|
issuerUri: string;
|
|
144
178
|
clientId: string;
|
|
145
|
-
scopes: string[];
|
|
146
179
|
configId: string;
|
|
147
180
|
log: typeof console.log | undefined;
|
|
148
181
|
}): Promise<AutoLogin extends true ? Oidc.LoggedIn<DecodedIdToken> : Oidc<DecodedIdToken>>;
|
package/core/createOidc.js
CHANGED
|
@@ -58,7 +58,7 @@ const persistedAuthState_1 = require("./persistedAuthState");
|
|
|
58
58
|
const Evt_1 = require("../tools/Evt");
|
|
59
59
|
const haveSharedParentDomain_1 = require("../tools/haveSharedParentDomain");
|
|
60
60
|
const loginOrGoToAuthServer_1 = require("./loginOrGoToAuthServer");
|
|
61
|
-
const
|
|
61
|
+
const lazySessionStorage_1 = require("../tools/lazySessionStorage");
|
|
62
62
|
const ongoingLoginOrRefreshProcesses_1 = require("./ongoingLoginOrRefreshProcesses");
|
|
63
63
|
const isNewBrowserSession_1 = require("./isNewBrowserSession");
|
|
64
64
|
const getIsOnline_1 = require("../tools/getIsOnline");
|
|
@@ -68,23 +68,14 @@ const prShouldLoadApp_1 = require("./prShouldLoadApp");
|
|
|
68
68
|
const BASE_URL_1 = require("./BASE_URL");
|
|
69
69
|
const isLikelyDevServer_1 = require("../tools/isLikelyDevServer");
|
|
70
70
|
const createObjectThatThrowsIfAccessed_1 = require("../tools/createObjectThatThrowsIfAccessed");
|
|
71
|
+
const instancesThatCantUseIframes_1 = require("./instancesThatCantUseIframes");
|
|
72
|
+
const desiredPostLoginRedirectUrl_1 = require("./desiredPostLoginRedirectUrl");
|
|
71
73
|
// NOTE: Replaced at build time
|
|
72
|
-
const VERSION = "8.2.
|
|
74
|
+
const VERSION = "8.2.3";
|
|
73
75
|
const globalContext = {
|
|
74
76
|
prOidcByConfigId: new Map(),
|
|
75
|
-
hasLogoutBeenCalled: (0, id_1.id)(false)
|
|
76
|
-
evtRequestToPersistTokens: (0, Evt_1.createEvt)()
|
|
77
|
+
hasLogoutBeenCalled: (0, id_1.id)(false)
|
|
77
78
|
};
|
|
78
|
-
globalContext.evtRequestToPersistTokens.subscribe(() => {
|
|
79
|
-
const { authResponse } = (0, earlyInit_1.getRedirectAuthResponse)();
|
|
80
|
-
if (authResponse === undefined) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
const { authResponses } = (0, AuthResponse_1.getPersistedRedirectAuthResponses)();
|
|
84
|
-
(0, AuthResponse_1.setPersistedRedirectAuthResponses)({
|
|
85
|
-
authResponses: [...authResponses, authResponse]
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
79
|
/** @see: https://docs.oidc-spa.dev/v/v8/usage */
|
|
89
80
|
async function createOidc(params) {
|
|
90
81
|
for (const name of ["issuerUri", "clientId"]) {
|
|
@@ -93,7 +84,7 @@ async function createOidc(params) {
|
|
|
93
84
|
throw new Error(`The parameter "${name}" is required, you provided: ${value}. (Forgot a .env variable?)`);
|
|
94
85
|
}
|
|
95
86
|
}
|
|
96
|
-
const { issuerUri: issuerUri_params, clientId,
|
|
87
|
+
const { issuerUri: issuerUri_params, clientId, debugLogs, ...rest } = params;
|
|
97
88
|
const issuerUri = (0, toFullyQualifiedUrl_1.toFullyQualifiedUrl)({
|
|
98
89
|
urlish: issuerUri_params,
|
|
99
90
|
doAssertNoQueryParams: true,
|
|
@@ -135,7 +126,6 @@ async function createOidc(params) {
|
|
|
135
126
|
const oidc = await createOidc_nonMemoized(rest, {
|
|
136
127
|
issuerUri,
|
|
137
128
|
clientId,
|
|
138
|
-
scopes,
|
|
139
129
|
configId,
|
|
140
130
|
log
|
|
141
131
|
});
|
|
@@ -158,9 +148,9 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
158
148
|
return new Promise(() => { });
|
|
159
149
|
}
|
|
160
150
|
}
|
|
161
|
-
const { transformUrlBeforeRedirect, extraQueryParams: extraQueryParamsOrGetter, extraTokenParams: extraTokenParamsOrGetter, decodedIdTokenSchema, idleSessionLifetimeInSeconds, autoLogoutParams = { redirectTo: "current page" }, autoLogin = false, postLoginRedirectUrl: postLoginRedirectUrl_default, __unsafe_clientSecret, __unsafe_useIdTokenAsAccessToken = false, __metadata,
|
|
151
|
+
const { transformUrlBeforeRedirect, extraQueryParams: extraQueryParamsOrGetter, extraTokenParams: extraTokenParamsOrGetter, decodedIdTokenSchema, idleSessionLifetimeInSeconds, autoLogoutParams = { redirectTo: "current page" }, autoLogin = false, postLoginRedirectUrl: postLoginRedirectUrl_default, __unsafe_clientSecret, __unsafe_useIdTokenAsAccessToken = false, __metadata, scopes = ["openid", "profile"], sessionRestorationMethod = params.autoLogin === true ? "full page redirect" : "auto" } = params;
|
|
162
152
|
const BASE_URL_params = params.BASE_URL ?? params.homeUrl;
|
|
163
|
-
const { issuerUri, clientId,
|
|
153
|
+
const { issuerUri, clientId, configId, log } = preProcessedParams;
|
|
164
154
|
const getExtraQueryParams = (() => {
|
|
165
155
|
if (extraQueryParamsOrGetter === undefined) {
|
|
166
156
|
return undefined;
|
|
@@ -205,14 +195,20 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
205
195
|
issuerUri,
|
|
206
196
|
clientId,
|
|
207
197
|
scopes,
|
|
208
|
-
|
|
209
|
-
homeUrlAndRedirectUri
|
|
198
|
+
oidcRedirectUri: homeUrlAndRedirectUri
|
|
210
199
|
}, null, 2)}`);
|
|
211
200
|
const stateUrlParamValue_instance = (0, StateData_1.generateStateUrlParamValue)();
|
|
212
201
|
const oidcMetadata = __metadata ?? (await (0, OidcMetadata_1.fetchOidcMetadata)({ issuerUri }));
|
|
213
202
|
const canUseIframe = (() => {
|
|
214
|
-
|
|
215
|
-
|
|
203
|
+
switch (sessionRestorationMethod) {
|
|
204
|
+
case "auto":
|
|
205
|
+
break;
|
|
206
|
+
case "full page redirect":
|
|
207
|
+
return false;
|
|
208
|
+
case "iframe":
|
|
209
|
+
return true;
|
|
210
|
+
default:
|
|
211
|
+
assert_1.assert;
|
|
216
212
|
}
|
|
217
213
|
third_party_cookies: {
|
|
218
214
|
if (oidcMetadata === undefined) {
|
|
@@ -267,7 +263,7 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
267
263
|
if (isLikelyDevServer) {
|
|
268
264
|
log?.([
|
|
269
265
|
"Detected localhost environment.",
|
|
270
|
-
"\nWhen reloading while logged in, you
|
|
266
|
+
"\nWhen reloading while logged in, you will briefly see",
|
|
271
267
|
"some URL params appear in the address bar.",
|
|
272
268
|
"\nThis happens because session restore via iframe is disabled,",
|
|
273
269
|
"the browser treats your auth server as a third party.",
|
|
@@ -294,7 +290,7 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
294
290
|
];
|
|
295
291
|
})(),
|
|
296
292
|
"\n\nMore info:",
|
|
297
|
-
"https://docs.oidc-spa.dev/v/v8/resources/
|
|
293
|
+
"https://docs.oidc-spa.dev/v/v8/resources/third-party-cookies-and-session-restoration"
|
|
298
294
|
].join(" "));
|
|
299
295
|
}
|
|
300
296
|
else {
|
|
@@ -321,14 +317,20 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
321
317
|
];
|
|
322
318
|
})(),
|
|
323
319
|
"\nMore info:",
|
|
324
|
-
"https://docs.oidc-spa.dev/v/v8/resources/
|
|
320
|
+
"https://docs.oidc-spa.dev/v/v8/resources/third-party-cookies-and-session-restoration"
|
|
325
321
|
].join(" "));
|
|
326
322
|
}
|
|
327
323
|
return false;
|
|
328
324
|
}
|
|
329
325
|
return true;
|
|
330
326
|
})();
|
|
331
|
-
|
|
327
|
+
(0, instancesThatCantUseIframes_1.notifyNewInstanceThatCantUseIframes)();
|
|
328
|
+
if (instancesThatCantUseIframes_1.evtIsThereMoreThanOneInstanceThatCantUserIframes.current) {
|
|
329
|
+
log?.([
|
|
330
|
+
"More than one oidc instance can't use iframe",
|
|
331
|
+
"falling back to persisting tokens in session storage"
|
|
332
|
+
].join(" "));
|
|
333
|
+
}
|
|
332
334
|
const oidcClientTsUserManager = oidcMetadata === undefined
|
|
333
335
|
? (0, createObjectThatThrowsIfAccessed_1.createObjectThatThrowsIfAccessed)({
|
|
334
336
|
debugMessage: "oidc-spa: Wrong assertion 43943"
|
|
@@ -347,20 +349,17 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
347
349
|
userStore: new oidc_client_ts_1.WebStorageStateStore({
|
|
348
350
|
store: (() => {
|
|
349
351
|
if (canUseIframe) {
|
|
350
|
-
isUserStoreInMemoryOnly = true;
|
|
351
352
|
return new oidc_client_ts_1.InMemoryWebStorage();
|
|
352
353
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
sessionStorageTtlMs: 3 * 60000
|
|
356
|
-
});
|
|
357
|
-
const { evtRequestToPersistTokens } = globalContext;
|
|
358
|
-
evtRequestToPersistTokens.subscribe(({ configIdOfInstancePostingTheRequest }) => {
|
|
359
|
-
if (configIdOfInstancePostingTheRequest === configId) {
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
354
|
+
const storage = (0, lazySessionStorage_1.createLazySessionStorage)({ storageId: configId });
|
|
355
|
+
if (instancesThatCantUseIframes_1.evtIsThereMoreThanOneInstanceThatCantUserIframes.current) {
|
|
362
356
|
storage.persistCurrentStateAndSubsequentChanges();
|
|
363
|
-
}
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
instancesThatCantUseIframes_1.evtIsThereMoreThanOneInstanceThatCantUserIframes.subscribe(() => {
|
|
360
|
+
storage.persistCurrentStateAndSubsequentChanges();
|
|
361
|
+
});
|
|
362
|
+
}
|
|
364
363
|
return storage;
|
|
365
364
|
})()
|
|
366
365
|
}),
|
|
@@ -393,54 +392,52 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
393
392
|
issuerUri
|
|
394
393
|
});
|
|
395
394
|
}
|
|
395
|
+
restore_from_session_storage: {
|
|
396
|
+
if (canUseIframe) {
|
|
397
|
+
break restore_from_session_storage;
|
|
398
|
+
}
|
|
399
|
+
if (!instancesThatCantUseIframes_1.evtIsThereMoreThanOneInstanceThatCantUserIframes.current) {
|
|
400
|
+
break restore_from_session_storage;
|
|
401
|
+
}
|
|
402
|
+
let oidcClientTsUser;
|
|
403
|
+
try {
|
|
404
|
+
oidcClientTsUser = await oidcClientTsUserManager.getUser();
|
|
405
|
+
}
|
|
406
|
+
catch {
|
|
407
|
+
// NOTE: Not sure if it can throw, but let's be safe.
|
|
408
|
+
oidcClientTsUser = null;
|
|
409
|
+
try {
|
|
410
|
+
await oidcClientTsUserManager.removeUser();
|
|
411
|
+
}
|
|
412
|
+
catch { }
|
|
413
|
+
}
|
|
414
|
+
if (oidcClientTsUser === null) {
|
|
415
|
+
break restore_from_session_storage;
|
|
416
|
+
}
|
|
417
|
+
log?.("Session was restored from session storage");
|
|
418
|
+
return {
|
|
419
|
+
oidcClientTsUser,
|
|
420
|
+
backFromAuthServer: undefined
|
|
421
|
+
};
|
|
422
|
+
}
|
|
396
423
|
handle_redirect_auth_response: {
|
|
397
424
|
let stateDataAndAuthResponse = undefined;
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
if (stateData === undefined) {
|
|
406
|
-
clearAuthResponse();
|
|
407
|
-
break from_memory;
|
|
408
|
-
}
|
|
409
|
-
if (stateData.configId !== configId) {
|
|
410
|
-
break from_memory;
|
|
411
|
-
}
|
|
412
|
-
(0, assert_1.assert)(stateData.context === "redirect", "3229492");
|
|
425
|
+
{
|
|
426
|
+
const { authResponse, clearAuthResponse } = (0, earlyInit_1.getRedirectAuthResponse)();
|
|
427
|
+
if (authResponse === undefined) {
|
|
428
|
+
break handle_redirect_auth_response;
|
|
429
|
+
}
|
|
430
|
+
const stateData = (0, StateData_1.getStateData)({ stateUrlParamValue: authResponse.state });
|
|
431
|
+
if (stateData === undefined) {
|
|
413
432
|
clearAuthResponse();
|
|
414
|
-
|
|
415
|
-
break get_stateData_and_authResponse;
|
|
433
|
+
break handle_redirect_auth_response;
|
|
416
434
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
// the authResponse in memory had the chance to be processed.
|
|
420
|
-
// This can only happen if:
|
|
421
|
-
// 1) There are multiple oidc instances in the App.
|
|
422
|
-
// 2) They are instantiated in a non deterministic order.
|
|
423
|
-
// 3) We can't use iframe
|
|
424
|
-
// We practically never persist the auth response and do it only in session
|
|
425
|
-
// an ephemeral session storage, when we know it's gonna be required.
|
|
426
|
-
{
|
|
427
|
-
const { authResponses } = (0, AuthResponse_1.getPersistedRedirectAuthResponses)();
|
|
428
|
-
for (const authResponse of authResponses) {
|
|
429
|
-
const stateData = (0, StateData_1.getStateData)({ stateUrlParamValue: authResponse.state });
|
|
430
|
-
if (stateData === undefined) {
|
|
431
|
-
continue;
|
|
432
|
-
}
|
|
433
|
-
if (stateData.configId !== configId) {
|
|
434
|
-
continue;
|
|
435
|
-
}
|
|
436
|
-
(0, assert_1.assert)(stateData.context === "redirect", "35935591");
|
|
437
|
-
(0, AuthResponse_1.setPersistedRedirectAuthResponses)({
|
|
438
|
-
authResponses: authResponses.filter(authResponse_i => authResponse_i !== authResponse)
|
|
439
|
-
});
|
|
440
|
-
stateDataAndAuthResponse = { stateData, authResponse };
|
|
441
|
-
break get_stateData_and_authResponse;
|
|
442
|
-
}
|
|
435
|
+
if (stateData.configId !== configId) {
|
|
436
|
+
break handle_redirect_auth_response;
|
|
443
437
|
}
|
|
438
|
+
(0, assert_1.assert)(stateData.context === "redirect", "3229492");
|
|
439
|
+
clearAuthResponse();
|
|
440
|
+
stateDataAndAuthResponse = { stateData, authResponse };
|
|
444
441
|
}
|
|
445
442
|
if (stateDataAndAuthResponse === undefined) {
|
|
446
443
|
break handle_redirect_auth_response;
|
|
@@ -519,34 +516,6 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
519
516
|
(0, assert_1.assert)(false);
|
|
520
517
|
}
|
|
521
518
|
}
|
|
522
|
-
// NOTE: We almost never persist tokens, we have to only to support edge case
|
|
523
|
-
// of multiple oidc instance in a single App with no iframe support.
|
|
524
|
-
restore_from_session_storage: {
|
|
525
|
-
(0, assert_1.assert)(isUserStoreInMemoryOnly !== undefined, "3392204");
|
|
526
|
-
if (isUserStoreInMemoryOnly) {
|
|
527
|
-
break restore_from_session_storage;
|
|
528
|
-
}
|
|
529
|
-
let oidcClientTsUser;
|
|
530
|
-
try {
|
|
531
|
-
oidcClientTsUser = await oidcClientTsUserManager.getUser();
|
|
532
|
-
}
|
|
533
|
-
catch {
|
|
534
|
-
// NOTE: Not sure if it can throw, but let's be safe.
|
|
535
|
-
oidcClientTsUser = null;
|
|
536
|
-
try {
|
|
537
|
-
await oidcClientTsUserManager.removeUser();
|
|
538
|
-
}
|
|
539
|
-
catch { }
|
|
540
|
-
}
|
|
541
|
-
if (oidcClientTsUser === null) {
|
|
542
|
-
break restore_from_session_storage;
|
|
543
|
-
}
|
|
544
|
-
log?.("Restored the auth from ephemeral session storage");
|
|
545
|
-
return {
|
|
546
|
-
oidcClientTsUser,
|
|
547
|
-
backFromAuthServer: undefined
|
|
548
|
-
};
|
|
549
|
-
}
|
|
550
519
|
silent_login_if_possible_and_auto_login: {
|
|
551
520
|
const persistedAuthState = (0, persistedAuthState_1.getPersistedAuthState)({ configId });
|
|
552
521
|
if (persistedAuthState === "explicitly logged out" && !autoLogin) {
|
|
@@ -599,7 +568,7 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
599
568
|
redirectUri: homeUrlAndRedirectUri,
|
|
600
569
|
clientId,
|
|
601
570
|
issuerUri,
|
|
602
|
-
|
|
571
|
+
canUseIframe
|
|
603
572
|
});
|
|
604
573
|
}
|
|
605
574
|
(0, assert_1.assert)();
|
|
@@ -631,7 +600,6 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
631
600
|
authResponse_error === "consent_required" ||
|
|
632
601
|
authResponse_error === "account_selection_required"))) {
|
|
633
602
|
log?.("Performing auto login with redirect");
|
|
634
|
-
(0, persistedAuthState_1.persistAuthState)({ configId, state: undefined });
|
|
635
603
|
completeLoginOrRefreshProcess();
|
|
636
604
|
if (autoLogin && persistedAuthState !== "logged in") {
|
|
637
605
|
evtInitializationOutcomeUserNotLoggedIn.post();
|
|
@@ -639,15 +607,18 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
639
607
|
await (0, ongoingLoginOrRefreshProcesses_1.waitForAllOtherOngoingLoginOrRefreshProcessesToComplete)({
|
|
640
608
|
prUnlock: (0, loginOrGoToAuthServer_1.getPrSafelyRestoredFromBfCacheAfterLoginBackNavigationOrInitializationError)()
|
|
641
609
|
});
|
|
642
|
-
if (persistedAuthState === "logged in") {
|
|
643
|
-
globalContext.evtRequestToPersistTokens.post({
|
|
644
|
-
configIdOfInstancePostingTheRequest: configId
|
|
645
|
-
});
|
|
646
|
-
}
|
|
647
610
|
await loginOrGoToAuthServer({
|
|
648
611
|
action: "login",
|
|
649
612
|
doForceReloadOnBfCache: true,
|
|
650
|
-
redirectUrl: (
|
|
613
|
+
redirectUrl: (() => {
|
|
614
|
+
if (postLoginRedirectUrl_default) {
|
|
615
|
+
return postLoginRedirectUrl_default;
|
|
616
|
+
}
|
|
617
|
+
if (!instancesThatCantUseIframes_1.evtIsThereMoreThanOneInstanceThatCantUserIframes.current) {
|
|
618
|
+
return (0, earlyInit_1.getRootRelativeOriginalLocationHref)();
|
|
619
|
+
}
|
|
620
|
+
return (0, desiredPostLoginRedirectUrl_1.getDesiredPostLoginRedirectUrl)() ?? window.location.href;
|
|
621
|
+
})(),
|
|
651
622
|
// NOTE: Wether or not it's the preferred behavior, pushing to history
|
|
652
623
|
// only works on user interaction so it have to be false
|
|
653
624
|
doNavigateBackToLastPublicUrlIfTheTheUserNavigateBack: false,
|
|
@@ -661,7 +632,10 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
661
632
|
return "directly redirect if active session show login otherwise";
|
|
662
633
|
}
|
|
663
634
|
return "ensure no interaction";
|
|
664
|
-
})()
|
|
635
|
+
})(),
|
|
636
|
+
preRedirectHook: () => {
|
|
637
|
+
(0, persistedAuthState_1.persistAuthState)({ configId, state: undefined });
|
|
638
|
+
}
|
|
665
639
|
});
|
|
666
640
|
}
|
|
667
641
|
if (authResponse_error !== undefined) {
|
|
@@ -748,7 +722,8 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
748
722
|
transformUrlBeforeRedirect_local: transformUrlBeforeRedirect,
|
|
749
723
|
interaction: (0, persistedAuthState_1.getPersistedAuthState)({ configId }) === "explicitly logged out"
|
|
750
724
|
? "ensure interaction"
|
|
751
|
-
: "directly redirect if active session show login otherwise"
|
|
725
|
+
: "directly redirect if active session show login otherwise",
|
|
726
|
+
preRedirectHook: undefined
|
|
752
727
|
});
|
|
753
728
|
},
|
|
754
729
|
initializationError: undefined
|
|
@@ -805,6 +780,7 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
805
780
|
state: {
|
|
806
781
|
stateDescription: "logged in",
|
|
807
782
|
refreshTokenExpirationTime: currentTokens.refreshTokenExpirationTime,
|
|
783
|
+
serverDateNow: currentTokens.getServerDateNow(),
|
|
808
784
|
idleSessionLifetimeInSeconds
|
|
809
785
|
}
|
|
810
786
|
});
|
|
@@ -922,9 +898,6 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
922
898
|
await (0, ongoingLoginOrRefreshProcesses_1.waitForAllOtherOngoingLoginOrRefreshProcessesToComplete)({
|
|
923
899
|
prUnlock: new Promise(() => { })
|
|
924
900
|
});
|
|
925
|
-
globalContext.evtRequestToPersistTokens.post({
|
|
926
|
-
configIdOfInstancePostingTheRequest: configId
|
|
927
|
-
});
|
|
928
901
|
await loginOrGoToAuthServer({
|
|
929
902
|
action: "login",
|
|
930
903
|
redirectUrl: window.location.href,
|
|
@@ -932,7 +905,8 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
932
905
|
extraQueryParams_local: undefined,
|
|
933
906
|
transformUrlBeforeRedirect_local: undefined,
|
|
934
907
|
doNavigateBackToLastPublicUrlIfTheTheUserNavigateBack: false,
|
|
935
|
-
interaction: "directly redirect if active session show login otherwise"
|
|
908
|
+
interaction: "directly redirect if active session show login otherwise",
|
|
909
|
+
preRedirectHook: undefined
|
|
936
910
|
});
|
|
937
911
|
(0, assert_1.assert)(false, "136134");
|
|
938
912
|
};
|
|
@@ -1024,6 +998,7 @@ async function createOidc_nonMemoized(params, preProcessedParams) {
|
|
|
1024
998
|
state: {
|
|
1025
999
|
stateDescription: "logged in",
|
|
1026
1000
|
refreshTokenExpirationTime: currentTokens.refreshTokenExpirationTime,
|
|
1001
|
+
serverDateNow: currentTokens.getServerDateNow(),
|
|
1027
1002
|
idleSessionLifetimeInSeconds
|
|
1028
1003
|
}
|
|
1029
1004
|
});
|