@oxyhq/core 5.4.3 → 6.0.0
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/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/HttpService.js +6 -3
- package/dist/cjs/OxyServices.base.js +7 -102
- package/dist/cjs/boot/coldBootV2.js +350 -0
- package/dist/cjs/boot/deviceBootReturn.js +152 -0
- package/dist/cjs/crypto/keyManager.js +95 -0
- package/dist/cjs/i18n/locales/en-US.json +13 -1
- package/dist/cjs/i18n/locales/es-ES.json +13 -1
- package/dist/cjs/i18n/locales/locales/en-US.json +13 -1
- package/dist/cjs/i18n/locales/locales/es-ES.json +13 -1
- package/dist/cjs/index.js +47 -43
- package/dist/cjs/mixins/OxyServices.accounts.js +6 -13
- package/dist/cjs/mixins/OxyServices.auth.js +66 -201
- package/dist/cjs/mixins/OxyServices.authorizedApps.js +38 -0
- package/dist/cjs/mixins/OxyServices.deviceBoot.js +119 -0
- package/dist/cjs/mixins/index.js +13 -17
- package/dist/cjs/session/SessionClient.js +44 -2
- package/dist/cjs/session/authStateStore.js +284 -0
- package/dist/cjs/session/createSessionClient.js +8 -2
- package/dist/cjs/session/refresh.js +264 -0
- package/dist/cjs/utils/accountUtils.js +1 -55
- package/dist/cjs/utils/authWebUrl.js +6 -15
- package/dist/cjs/utils/fapiAutoDetect.js +16 -64
- package/dist/cjs/utils/platform.js +19 -0
- package/dist/cjs/utils/ssoBounce.js +15 -340
- package/dist/cjs/utils/validationUtils.js +57 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/HttpService.js +6 -3
- package/dist/esm/OxyServices.base.js +7 -102
- package/dist/esm/boot/coldBootV2.js +344 -0
- package/dist/esm/boot/deviceBootReturn.js +146 -0
- package/dist/esm/crypto/keyManager.js +95 -0
- package/dist/esm/i18n/locales/en-US.json +13 -1
- package/dist/esm/i18n/locales/es-ES.json +13 -1
- package/dist/esm/i18n/locales/locales/en-US.json +13 -1
- package/dist/esm/i18n/locales/locales/es-ES.json +13 -1
- package/dist/esm/index.js +28 -18
- package/dist/esm/mixins/OxyServices.accounts.js +6 -13
- package/dist/esm/mixins/OxyServices.auth.js +66 -201
- package/dist/esm/mixins/OxyServices.authorizedApps.js +35 -0
- package/dist/esm/mixins/OxyServices.deviceBoot.js +116 -0
- package/dist/esm/mixins/index.js +13 -17
- package/dist/esm/session/SessionClient.js +44 -2
- package/dist/esm/session/authStateStore.js +278 -0
- package/dist/esm/session/createSessionClient.js +8 -2
- package/dist/esm/session/refresh.js +257 -0
- package/dist/esm/utils/accountUtils.js +0 -53
- package/dist/esm/utils/authWebUrl.js +6 -14
- package/dist/esm/utils/fapiAutoDetect.js +16 -63
- package/dist/esm/utils/platform.js +18 -0
- package/dist/esm/utils/ssoBounce.js +14 -324
- package/dist/esm/utils/validationUtils.js +56 -0
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/HttpService.d.ts +13 -0
- package/dist/types/OxyServices.base.d.ts +0 -52
- package/dist/types/OxyServices.d.ts +0 -25
- package/dist/types/boot/coldBootV2.d.ts +76 -0
- package/dist/types/boot/deviceBootReturn.d.ts +83 -0
- package/dist/types/crypto/keyManager.d.ts +21 -0
- package/dist/types/index.d.ts +16 -21
- package/dist/types/mixins/OxyServices.accounts.d.ts +0 -2
- package/dist/types/mixins/OxyServices.analytics.d.ts +0 -2
- package/dist/types/mixins/OxyServices.appData.d.ts +0 -2
- package/dist/types/mixins/OxyServices.assets.d.ts +0 -2
- package/dist/types/mixins/OxyServices.auth.d.ts +35 -77
- package/dist/types/mixins/{OxyServices.redirect.d.ts → OxyServices.authorizedApps.d.ts} +35 -33
- package/dist/types/mixins/OxyServices.civic.d.ts +0 -2
- package/dist/types/mixins/OxyServices.connectedApps.d.ts +0 -2
- package/dist/types/mixins/OxyServices.contacts.d.ts +0 -2
- package/dist/types/mixins/OxyServices.deviceBoot.d.ts +110 -0
- package/dist/types/mixins/OxyServices.devices.d.ts +0 -2
- package/dist/types/mixins/OxyServices.features.d.ts +0 -2
- package/dist/types/mixins/OxyServices.identity.d.ts +0 -2
- package/dist/types/mixins/OxyServices.language.d.ts +0 -2
- package/dist/types/mixins/OxyServices.links.d.ts +0 -2
- package/dist/types/mixins/OxyServices.location.d.ts +0 -2
- package/dist/types/mixins/OxyServices.nodes.d.ts +0 -2
- package/dist/types/mixins/OxyServices.payment.d.ts +0 -2
- package/dist/types/mixins/OxyServices.privacy.d.ts +0 -2
- package/dist/types/mixins/OxyServices.reputation.d.ts +0 -2
- package/dist/types/mixins/OxyServices.security.d.ts +0 -2
- package/dist/types/mixins/OxyServices.topics.d.ts +0 -2
- package/dist/types/mixins/OxyServices.user.d.ts +0 -2
- package/dist/types/mixins/OxyServices.utility.d.ts +0 -2
- package/dist/types/mixins/index.d.ts +6 -9
- package/dist/types/models/interfaces.d.ts +0 -67
- package/dist/types/session/SessionClient.d.ts +38 -1
- package/dist/types/session/authStateStore.d.ts +119 -0
- package/dist/types/session/createSessionClient.d.ts +8 -1
- package/dist/types/session/refresh.d.ts +93 -0
- package/dist/types/utils/accountUtils.d.ts +0 -14
- package/dist/types/utils/authWebUrl.d.ts +6 -12
- package/dist/types/utils/fapiAutoDetect.d.ts +15 -38
- package/dist/types/utils/platform.d.ts +14 -0
- package/dist/types/utils/ssoBounce.d.ts +14 -262
- package/dist/types/utils/validationUtils.d.ts +15 -0
- package/package.json +2 -2
- package/src/HttpService.ts +19 -3
- package/src/OxyServices.base.ts +7 -112
- package/src/OxyServices.ts +0 -38
- package/src/boot/__tests__/coldBootV2.test.ts +317 -0
- package/src/boot/__tests__/deviceBootReturn.test.ts +158 -0
- package/src/boot/coldBootV2.ts +426 -0
- package/src/boot/deviceBootReturn.ts +195 -0
- package/src/crypto/__tests__/sharedDeviceToken.test.ts +24 -0
- package/src/crypto/keyManager.ts +101 -0
- package/src/i18n/locales/en-US.json +13 -1
- package/src/i18n/locales/es-ES.json +13 -1
- package/src/index.ts +78 -64
- package/src/mixins/OxyServices.accounts.ts +6 -13
- package/src/mixins/OxyServices.auth.ts +78 -253
- package/src/mixins/OxyServices.authorizedApps.ts +75 -0
- package/src/mixins/OxyServices.deviceBoot.ts +146 -0
- package/src/mixins/__tests__/OxyServices.deviceBoot.test.ts +107 -0
- package/src/mixins/__tests__/accounts.test.ts +17 -44
- package/src/mixins/__tests__/authorizedApps.test.ts +63 -0
- package/src/mixins/__tests__/passwordSignIn.test.ts +91 -0
- package/src/mixins/index.ts +16 -22
- package/src/models/interfaces.ts +0 -79
- package/src/session/SessionClient.ts +69 -3
- package/src/session/__tests__/SessionClient.additive.test.ts +92 -0
- package/src/session/__tests__/SessionClient.rest.test.ts +25 -0
- package/src/session/__tests__/SessionClient.socketFactory.test.ts +79 -0
- package/src/session/__tests__/SessionClient.state.test.ts +18 -5
- package/src/session/__tests__/authStateStore.test.ts +209 -0
- package/src/session/__tests__/refresh.test.ts +256 -0
- package/src/session/authStateStore.ts +335 -0
- package/src/session/createSessionClient.ts +9 -1
- package/src/session/refresh.ts +334 -0
- package/src/utils/__tests__/authWebUrl.test.ts +5 -29
- package/src/utils/__tests__/fapiAutoDetect.test.ts +5 -126
- package/src/utils/__tests__/validationUtils.test.ts +30 -0
- package/src/utils/accountUtils.ts +0 -62
- package/src/utils/authWebUrl.ts +6 -15
- package/src/utils/fapiAutoDetect.ts +16 -60
- package/src/utils/platform.ts +21 -0
- package/src/utils/ssoBounce.ts +14 -371
- package/src/utils/validationUtils.ts +62 -0
- package/dist/cjs/AuthManager.js +0 -1110
- package/dist/cjs/AuthManagerTypes.js +0 -13
- package/dist/cjs/CrossDomainAuth.js +0 -206
- package/dist/cjs/mixins/OxyServices.fedcm.js +0 -823
- package/dist/cjs/mixins/OxyServices.redirect.js +0 -95
- package/dist/cjs/mixins/OxyServices.silent.js +0 -204
- package/dist/cjs/mixins/OxyServices.sso.js +0 -208
- package/dist/cjs/utils/ssoEstablish.js +0 -110
- package/dist/cjs/utils/ssoReturn.js +0 -267
- package/dist/esm/AuthManager.js +0 -1105
- package/dist/esm/AuthManagerTypes.js +0 -12
- package/dist/esm/CrossDomainAuth.js +0 -201
- package/dist/esm/mixins/OxyServices.fedcm.js +0 -821
- package/dist/esm/mixins/OxyServices.redirect.js +0 -92
- package/dist/esm/mixins/OxyServices.silent.js +0 -202
- package/dist/esm/mixins/OxyServices.sso.js +0 -204
- package/dist/esm/utils/ssoEstablish.js +0 -107
- package/dist/esm/utils/ssoReturn.js +0 -263
- package/dist/types/AuthManager.d.ts +0 -380
- package/dist/types/AuthManagerTypes.d.ts +0 -81
- package/dist/types/CrossDomainAuth.d.ts +0 -164
- package/dist/types/mixins/OxyServices.fedcm.d.ts +0 -331
- package/dist/types/mixins/OxyServices.silent.d.ts +0 -132
- package/dist/types/mixins/OxyServices.sso.d.ts +0 -138
- package/dist/types/utils/ssoEstablish.d.ts +0 -85
- package/dist/types/utils/ssoReturn.d.ts +0 -146
- package/src/AuthManager.ts +0 -1269
- package/src/AuthManagerTypes.ts +0 -86
- package/src/CrossDomainAuth.ts +0 -243
- package/src/__tests__/authManager.cookiePath.test.ts +0 -390
- package/src/__tests__/authManager.security.test.ts +0 -377
- package/src/__tests__/crossDomainAuth.test.ts +0 -116
- package/src/__tests__/establishDeviceRefreshSlot.test.ts +0 -221
- package/src/mixins/OxyServices.fedcm.ts +0 -1026
- package/src/mixins/OxyServices.redirect.ts +0 -122
- package/src/mixins/OxyServices.silent.ts +0 -272
- package/src/mixins/OxyServices.sso.ts +0 -261
- package/src/mixins/__tests__/constructorAuthWebUrl.test.ts +0 -85
- package/src/mixins/__tests__/fedcm.test.ts +0 -667
- package/src/mixins/__tests__/sessionBaseUrl.test.ts +0 -61
- package/src/mixins/__tests__/silent.test.ts +0 -102
- package/src/mixins/__tests__/sso.test.ts +0 -228
- package/src/utils/__tests__/consumeSsoReturn.test.ts +0 -816
- package/src/utils/__tests__/ssoBounce.test.ts +0 -219
- package/src/utils/__tests__/ssoEstablish.test.ts +0 -204
- package/src/utils/__tests__/ssoReturn.test.ts +0 -251
- package/src/utils/ssoEstablish.ts +0 -174
- package/src/utils/ssoReturn.ts +0 -372
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Parse the SSO return fragment delivered by the central IdP.
|
|
4
|
-
*
|
|
5
|
-
* After a top-level redirect bounce to `auth.oxy.so/sso` (prompt=none), the
|
|
6
|
-
* central IdP returns the Relying Party to its `redirect_uri` with the result
|
|
7
|
-
* encoded in the URL fragment (the `#…` part). The fragment is used — not a
|
|
8
|
-
* query string — so the opaque single-use code never reaches a server access
|
|
9
|
-
* log, a `Referer` header, or browser history in a recoverable form.
|
|
10
|
-
*
|
|
11
|
-
* Three outcomes are possible:
|
|
12
|
-
* - `#oxy_sso=ok&code=<opaque>&state=<state>` — the IdP had a session; the RP
|
|
13
|
-
* exchanges `code` (via `oxy.exchangeSsoCode`) for the real session. NO
|
|
14
|
-
* token/JWT ever appears in the URL — only the opaque code.
|
|
15
|
-
* - `#oxy_sso=none&state=<state>` — the IdP had no session (prompt=none, user
|
|
16
|
-
* not signed in centrally). The RP shows its own signed-out UI.
|
|
17
|
-
* - `#oxy_sso=error&state=<state>` — the bounce failed. The RP recovers.
|
|
18
|
-
*
|
|
19
|
-
* This parser is pure and defensive: it never throws, and `kind` is strictly
|
|
20
|
-
* one of `'ok' | 'none' | 'error'`. It returns `null` when the fragment is not
|
|
21
|
-
* an oxy_sso fragment at all (i.e. `oxy_sso` is absent or an unrecognised
|
|
22
|
-
* value), so the caller can ignore unrelated fragments without special-casing.
|
|
23
|
-
*/
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.parseSsoReturnFragment = parseSsoReturnFragment;
|
|
26
|
-
exports.consumeSsoReturn = consumeSsoReturn;
|
|
27
|
-
const ssoBounce_1 = require("./ssoBounce");
|
|
28
|
-
const VALID_KINDS = new Set(['ok', 'none', 'error']);
|
|
29
|
-
/**
|
|
30
|
-
* Parse an SSO return fragment.
|
|
31
|
-
*
|
|
32
|
-
* @param hash - The URL fragment, with or without the leading `#`
|
|
33
|
-
* (e.g. `location.hash`). May be `undefined`/empty.
|
|
34
|
-
* @returns The parsed result when `hash` is a recognised oxy_sso fragment,
|
|
35
|
-
* otherwise `null`. Never throws.
|
|
36
|
-
*/
|
|
37
|
-
function parseSsoReturnFragment(hash) {
|
|
38
|
-
if (typeof hash !== 'string' || hash.length === 0) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
// Strip a single leading '#'. A bare '#' (empty fragment) yields no params.
|
|
42
|
-
const raw = hash.startsWith('#') ? hash.slice(1) : hash;
|
|
43
|
-
if (raw.length === 0) {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
let params;
|
|
47
|
-
try {
|
|
48
|
-
params = new URLSearchParams(raw);
|
|
49
|
-
}
|
|
50
|
-
catch {
|
|
51
|
-
// URLSearchParams does not throw for malformed input in practice, but guard
|
|
52
|
-
// against any environment/polyfill that might so this stays total.
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
const kind = params.get('oxy_sso');
|
|
56
|
-
if (kind === null || !VALID_KINDS.has(kind)) {
|
|
57
|
-
// Not an oxy_sso fragment (absent or unrecognised value) — ignore it.
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
const result = { kind: kind };
|
|
61
|
-
const state = params.get('state');
|
|
62
|
-
if (state !== null && state.length > 0) {
|
|
63
|
-
result.state = state;
|
|
64
|
-
}
|
|
65
|
-
// The opaque code is only meaningful on success; ignore any stray `code` on
|
|
66
|
-
// none/error so callers never attempt an exchange for a non-ok outcome.
|
|
67
|
-
if (result.kind === 'ok') {
|
|
68
|
-
const code = params.get('code');
|
|
69
|
-
if (code !== null && code.length > 0) {
|
|
70
|
-
result.code = code;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Consume an SSO return: the commit-free, security-critical kernel of the
|
|
77
|
-
* cross-domain SSO `sso-return` cold-boot step.
|
|
78
|
-
*
|
|
79
|
-
* This performs the CSRF/fragment/exchange/dest-restore/loop-breaker sequence
|
|
80
|
-
* and RETURNS the exchanged session (or `null`). It deliberately does NOT
|
|
81
|
-
* commit any UI/auth state — each provider commits its own way AROUND this
|
|
82
|
-
* (e.g. `@oxyhq/services` `OxyContext` calls its `handleWebSSOSession`,
|
|
83
|
-
* `@oxyhq/auth` `WebOxyProvider` updates its React state). Hoisting the kernel
|
|
84
|
-
* here keeps the two providers byte-for-byte identical on the parts that matter
|
|
85
|
-
* for security (state validation, fragment stripping order, loop prevention).
|
|
86
|
-
*
|
|
87
|
-
* Security/loop invariants (preserved exactly from both former copies):
|
|
88
|
-
* - The fragment is stripped via `history.replaceState` FIRST — before the
|
|
89
|
-
* exchange — so the opaque code never lingers in the URL, browser history,
|
|
90
|
-
* or a `Referer` header even if a later step throws.
|
|
91
|
-
* - `state` must match (CSRF). A mismatch or a missing code sets the
|
|
92
|
-
* NO_SESSION flag so `sso-bounce` is disabled (no rebounce loop).
|
|
93
|
-
* - `none`/`error` outcomes set BOTH the NO_SESSION flag and the
|
|
94
|
-
* outcome-independent attempted-flag (the load2 half of the loop proof).
|
|
95
|
-
* - A throwing exchange is caught, reported via `onExchangeError`, and
|
|
96
|
-
* treated exactly like "no session" (never loops, never rethrows).
|
|
97
|
-
* - On EVERY consumed outcome (ok, none, error, state-mismatch, no-code,
|
|
98
|
-
* failed-exchange, no-sessionId) — not just ok — if the page landed on
|
|
99
|
-
* {@link SSO_CALLBACK_PATH}, the user is taken to a same-origin TARGET so
|
|
100
|
-
* they are never stranded on the internal callback path (which is an
|
|
101
|
-
* unregistered route in every consumer router → a hard 404). The target is
|
|
102
|
-
* the stored DEST when it parses as same-origin (an attacker-planted
|
|
103
|
-
* cross-origin / protocol-relative dest is rejected), ELSE the app root
|
|
104
|
-
* (`origin + '/'`). The DEST key is removed unconditionally.
|
|
105
|
-
* - For the `ok` outcome the target is applied via a SOFT
|
|
106
|
-
* `history.replaceState` + synthetic `popstate` so the freshly exchanged
|
|
107
|
-
* in-memory session the provider is about to commit is preserved (no
|
|
108
|
-
* reload). `popstate` is dispatched only on the `ok` same-origin restore.
|
|
109
|
-
* - For every NON-`ok` outcome there is no in-memory session to preserve, and
|
|
110
|
-
* the consumer router has ALREADY synchronously rendered its 404 for the
|
|
111
|
-
* unregistered callback route — a soft replaceState+popstate does not
|
|
112
|
-
* reliably make it re-resolve. So these outcomes perform a HARD
|
|
113
|
-
* full-document navigation to the target (`hardRedirect`), which is both
|
|
114
|
-
* safe (nothing to lose) and guaranteed to clear the 404 in every router.
|
|
115
|
-
*
|
|
116
|
-
* Total: this function NEVER throws. Off-web it is a no-op returning `null`.
|
|
117
|
-
*
|
|
118
|
-
* @param oxy - The exchange surface (`oxyServices.exchangeSsoCode`).
|
|
119
|
-
* @param deps - Injectable web seams; see {@link ConsumeSsoReturnDeps}.
|
|
120
|
-
* @returns The exchanged session on success, otherwise `null`.
|
|
121
|
-
*/
|
|
122
|
-
async function consumeSsoReturn(oxy, deps = {}) {
|
|
123
|
-
const isWeb = deps.isWeb ??
|
|
124
|
-
(() => typeof window !== 'undefined' &&
|
|
125
|
-
typeof window.sessionStorage !== 'undefined');
|
|
126
|
-
if (!isWeb()) {
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
const storage = deps.storage ?? window.sessionStorage;
|
|
130
|
-
const location = deps.location ?? window.location;
|
|
131
|
-
const history = deps.history ?? window.history;
|
|
132
|
-
const onExchangeError = deps.onExchangeError;
|
|
133
|
-
// Default: emit a synthetic `popstate` so URL-driven routers re-sync after a
|
|
134
|
-
// `history.replaceState` (which does NOT emit `popstate` on its own). Feature-
|
|
135
|
-
// detected end to end so it never throws in any environment.
|
|
136
|
-
const dispatchPopState = deps.dispatchPopState ??
|
|
137
|
-
(() => {
|
|
138
|
-
if (typeof window === 'undefined' || typeof window.dispatchEvent !== 'function') {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if (typeof PopStateEvent !== 'undefined') {
|
|
142
|
-
window.dispatchEvent(new PopStateEvent('popstate'));
|
|
143
|
-
}
|
|
144
|
-
else if (typeof Event !== 'undefined') {
|
|
145
|
-
window.dispatchEvent(new Event('popstate'));
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
// Default: a hard, full-document navigation used to leave the callback path
|
|
149
|
-
// on non-`ok` outcomes. Feature-detected end to end so it never throws in any
|
|
150
|
-
// environment (SSR / native / a stubbed location without `replace`).
|
|
151
|
-
const hardRedirect = deps.hardRedirect ??
|
|
152
|
-
((url) => {
|
|
153
|
-
if (typeof window !== 'undefined' &&
|
|
154
|
-
window.location &&
|
|
155
|
-
typeof window.location.replace === 'function') {
|
|
156
|
-
window.location.replace(url);
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
const ret = parseSsoReturnFragment(location.hash);
|
|
160
|
-
if (!ret) {
|
|
161
|
-
// Not an oxy_sso fragment — nothing to do (do NOT touch any flags).
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
const origin = location.origin;
|
|
165
|
-
const callbackBootstrapKey = (0, ssoBounce_1.ssoCallbackBootstrapKey)(origin);
|
|
166
|
-
const wasCallbackBootstrapped = storage.getItem(callbackBootstrapKey) === '1';
|
|
167
|
-
const expectedState = storage.getItem((0, ssoBounce_1.ssoStateKey)(origin));
|
|
168
|
-
const stateOk = !!ret.state && !!expectedState && ret.state === expectedState;
|
|
169
|
-
// Strip the fragment FIRST so the opaque code never lingers in the address
|
|
170
|
-
// bar, history, or a `Referer` — even if a later step throws.
|
|
171
|
-
history.replaceState(null, '', location.pathname + location.search);
|
|
172
|
-
storage.removeItem((0, ssoBounce_1.ssoStateKey)(origin));
|
|
173
|
-
// The in-flight bounce is now resolved — drop its guard so a later cold boot
|
|
174
|
-
// (e.g. after sign-out) can bounce again.
|
|
175
|
-
storage.removeItem((0, ssoBounce_1.ssoGuardKey)(origin));
|
|
176
|
-
const markNoSession = () => {
|
|
177
|
-
storage.setItem((0, ssoBounce_1.ssoNoSessionKey)(origin), '1');
|
|
178
|
-
// A return was consumed, so the probe definitively happened. Set the
|
|
179
|
-
// outcome-independent attempted-flag too so the bounce can never re-fire
|
|
180
|
-
// even if some consumer path skipped setting it pre-bounce.
|
|
181
|
-
storage.setItem((0, ssoBounce_1.ssoAttemptedKey)(origin), '1');
|
|
182
|
-
};
|
|
183
|
-
// Compute the same-origin TARGET to leave the callback path for. Returns the
|
|
184
|
-
// stored DEST when present AND it parses as same-origin (never honour a
|
|
185
|
-
// cross-origin / protocol-relative dest that could have been planted to
|
|
186
|
-
// redirect the user), ELSE the app root (`origin + '/'`) so the user is never
|
|
187
|
-
// stranded on the internal callback path even when no dest was stored. The
|
|
188
|
-
// DEST key is removed unconditionally. Returns the relative path+search+hash
|
|
189
|
-
// (so it can be fed to either `history.replaceState` or a `hardRedirect`),
|
|
190
|
-
// or `null` when the page is not on the callback path (nothing to leave).
|
|
191
|
-
const consumeCallbackTarget = () => {
|
|
192
|
-
storage.removeItem(callbackBootstrapKey);
|
|
193
|
-
if (location.pathname !== ssoBounce_1.SSO_CALLBACK_PATH && !wasCallbackBootstrapped) {
|
|
194
|
-
// Not on the callback path — still drop the dest key (consumed) but there
|
|
195
|
-
// is nothing to navigate away from.
|
|
196
|
-
storage.removeItem((0, ssoBounce_1.ssoDestKey)(origin));
|
|
197
|
-
return null;
|
|
198
|
-
}
|
|
199
|
-
const dest = storage.getItem((0, ssoBounce_1.ssoDestKey)(origin));
|
|
200
|
-
storage.removeItem((0, ssoBounce_1.ssoDestKey)(origin));
|
|
201
|
-
if (dest) {
|
|
202
|
-
try {
|
|
203
|
-
const destUrl = new URL(dest, origin);
|
|
204
|
-
if (destUrl.origin === origin) {
|
|
205
|
-
return destUrl.pathname + destUrl.search + destUrl.hash;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
catch {
|
|
209
|
-
// Malformed stored destination — fall through to the app-root fallback.
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
// No dest, a cross-origin/protocol-relative dest, or an unparseable dest:
|
|
213
|
-
// fall back to the app root so the router always leaves the 404.
|
|
214
|
-
return '/';
|
|
215
|
-
};
|
|
216
|
-
// Non-`ok` outcomes: there is no in-memory session to preserve, and the
|
|
217
|
-
// consumer router has already rendered its 404 for the unregistered callback
|
|
218
|
-
// route — a soft replaceState+popstate does not reliably make it re-resolve.
|
|
219
|
-
// Perform a HARD full-document navigation to the target (safe: nothing to
|
|
220
|
-
// lose; guaranteed: every router leaves the 404). Off the callback path this
|
|
221
|
-
// is a no-op (target is null).
|
|
222
|
-
const leaveCallbackHard = () => {
|
|
223
|
-
const target = consumeCallbackTarget();
|
|
224
|
-
if (target !== null) {
|
|
225
|
-
hardRedirect(origin + target);
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
if (ret.kind === 'none' || ret.kind === 'error') {
|
|
229
|
-
// The central IdP had no session (or the bounce failed). Record it so we do
|
|
230
|
-
// not bounce again this tab — the definitive loop breaker.
|
|
231
|
-
markNoSession();
|
|
232
|
-
leaveCallbackHard();
|
|
233
|
-
return null;
|
|
234
|
-
}
|
|
235
|
-
if (!stateOk || !ret.code) {
|
|
236
|
-
// Forged / replayed / stale fragment, or a malformed ok with no code. Treat
|
|
237
|
-
// exactly like "no session": never exchange, never loop.
|
|
238
|
-
markNoSession();
|
|
239
|
-
leaveCallbackHard();
|
|
240
|
-
return null;
|
|
241
|
-
}
|
|
242
|
-
let session;
|
|
243
|
-
try {
|
|
244
|
-
session = await oxy.exchangeSsoCode(ret.code, ret.state);
|
|
245
|
-
}
|
|
246
|
-
catch (error) {
|
|
247
|
-
onExchangeError?.(error);
|
|
248
|
-
markNoSession();
|
|
249
|
-
leaveCallbackHard();
|
|
250
|
-
return null;
|
|
251
|
-
}
|
|
252
|
-
if (!session?.sessionId) {
|
|
253
|
-
markNoSession();
|
|
254
|
-
leaveCallbackHard();
|
|
255
|
-
return null;
|
|
256
|
-
}
|
|
257
|
-
// `ok`: the provider is about to commit the freshly exchanged in-memory
|
|
258
|
-
// session — do NOT hard-redirect (a full navigation would discard it). Use a
|
|
259
|
-
// SOFT `history.replaceState` to the target + a synthetic `popstate` so
|
|
260
|
-
// URL-driven routers re-sync to the restored route without a reload.
|
|
261
|
-
const target = consumeCallbackTarget();
|
|
262
|
-
if (target !== null) {
|
|
263
|
-
history.replaceState(null, '', target);
|
|
264
|
-
dispatchPopState();
|
|
265
|
-
}
|
|
266
|
-
return session;
|
|
267
|
-
}
|