@oxyhq/core 5.2.1 → 5.4.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/CrossDomainAuth.js +32 -42
- package/dist/cjs/index.js +24 -2
- package/dist/cjs/mixins/OxyServices.sso.js +36 -0
- package/dist/cjs/mixins/OxyServices.user.js +50 -0
- package/dist/cjs/server/index.js +13 -1
- package/dist/cjs/session/SessionClient.js +152 -0
- package/dist/cjs/session/createSessionClient.js +26 -0
- package/dist/cjs/session/projectSessionState.js +75 -0
- package/dist/cjs/session/sessionClientHost.js +30 -0
- package/dist/cjs/session/socketLoader.js +55 -0
- package/dist/cjs/utils/ssoBounce.js +9 -9
- package/dist/cjs/utils/ssoEstablish.js +110 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/CrossDomainAuth.js +32 -42
- package/dist/esm/index.js +14 -0
- package/dist/esm/mixins/OxyServices.sso.js +36 -0
- package/dist/esm/mixins/OxyServices.user.js +50 -0
- package/dist/esm/server/index.js +10 -0
- package/dist/esm/session/SessionClient.js +148 -0
- package/dist/esm/session/createSessionClient.js +23 -0
- package/dist/esm/session/projectSessionState.js +69 -0
- package/dist/esm/session/sessionClientHost.js +27 -0
- package/dist/esm/session/socketLoader.js +19 -0
- package/dist/esm/utils/ssoBounce.js +9 -9
- package/dist/esm/utils/ssoEstablish.js +107 -0
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/CrossDomainAuth.d.ts +33 -13
- package/dist/types/index.d.ts +7 -0
- package/dist/types/mixins/OxyServices.sso.d.ts +24 -0
- package/dist/types/mixins/OxyServices.user.d.ts +30 -0
- package/dist/types/server/index.d.ts +2 -0
- package/dist/types/session/SessionClient.d.ts +55 -0
- package/dist/types/session/createSessionClient.d.ts +23 -0
- package/dist/types/session/projectSessionState.d.ts +43 -0
- package/dist/types/session/sessionClientHost.d.ts +18 -0
- package/dist/types/session/socketLoader.d.ts +9 -0
- package/dist/types/utils/ssoBounce.d.ts +9 -9
- package/dist/types/utils/ssoEstablish.d.ts +85 -0
- package/package.json +1 -1
- package/src/CrossDomainAuth.ts +33 -44
- package/src/__tests__/crossDomainAuth.test.ts +33 -16
- package/src/index.ts +24 -0
- package/src/mixins/OxyServices.sso.ts +55 -0
- package/src/mixins/OxyServices.user.ts +54 -0
- package/src/mixins/__tests__/sso.test.ts +41 -0
- package/src/server/index.ts +12 -0
- package/src/session/SessionClient.ts +187 -0
- package/src/session/__tests__/SessionClient.diagnostics.test.ts +90 -0
- package/src/session/__tests__/SessionClient.httpIntegration.test.ts +65 -0
- package/src/session/__tests__/SessionClient.rest.test.ts +80 -0
- package/src/session/__tests__/SessionClient.socket.test.ts +133 -0
- package/src/session/__tests__/SessionClient.state.test.ts +64 -0
- package/src/session/__tests__/sessionIntegration.test.ts +202 -0
- package/src/session/createSessionClient.ts +31 -0
- package/src/session/projectSessionState.ts +83 -0
- package/src/session/sessionClientHost.ts +32 -0
- package/src/session/socketLoader.ts +28 -0
- package/src/utils/__tests__/ssoEstablish.test.ts +204 -0
- package/src/utils/ssoBounce.ts +9 -9
- package/src/utils/ssoEstablish.ts +174 -0
|
@@ -142,18 +142,18 @@ function ssoPriorSessionKey(origin) {
|
|
|
142
142
|
* per-tab `sessionStorage` the loop-breaker keys use — it must survive a reload.
|
|
143
143
|
*
|
|
144
144
|
* It exists purely to suppress AUTOMATIC silent restore after a deliberate
|
|
145
|
-
* sign-out: a still-live IdP session (the central `fedcm_session`
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
145
|
+
* sign-out: a still-live IdP session (the central `fedcm_session`) would
|
|
146
|
+
* otherwise let the per-apex `/auth/silent` iframe re-mint a session on the
|
|
147
|
+
* very next cold boot, so a user who pressed "Sign out" gets silently signed
|
|
148
|
+
* back in on reload. With this flag set, that silent cold-boot step is
|
|
149
|
+
* skipped while the Gmail-style returning-account fast-path is otherwise
|
|
150
|
+
* preserved.
|
|
151
151
|
*
|
|
152
152
|
* Lifecycle (mirrors the existing gate machinery — set on a definitive event,
|
|
153
153
|
* cleared on its inverse):
|
|
154
154
|
* - SET on EXPLICIT full sign-out (alongside clearing the prior-session hint
|
|
155
155
|
* and the SSO bounce state).
|
|
156
|
-
* - CLEARED on ANY deliberate sign-in (password,
|
|
156
|
+
* - CLEARED on ANY deliberate sign-in (password, account switch, device
|
|
157
157
|
* claim) so a real sign-in fully re-enables silent restore — there is no
|
|
158
158
|
* "stuck signed out" state.
|
|
159
159
|
*
|
|
@@ -297,8 +297,8 @@ function guardActive(storage, origin, now = Date.now()) {
|
|
|
297
297
|
* Whether AUTOMATIC silent restore is SUPPRESSED for this origin because the
|
|
298
298
|
* user deliberately signed out (the durable {@link ssoSignedOutKey} flag).
|
|
299
299
|
*
|
|
300
|
-
* When `true`, the silent cold-boot
|
|
301
|
-
* still-live IdP session WITHOUT user intent —
|
|
300
|
+
* When `true`, the silent cold-boot step that can re-mint a session from a
|
|
301
|
+
* still-live IdP session WITHOUT user intent — the per-apex
|
|
302
302
|
* `/auth/silent` iframe — MUST be skipped, so a user who pressed "Sign out" is
|
|
303
303
|
* not silently signed back in on the next reload. Interactive sign-in clears the
|
|
304
304
|
* flag, so this never blocks a deliberate re-sign-in.
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Post-claim durable-session establish hop (web device-flow / "Sign in with
|
|
4
|
+
* Oxy" QR).
|
|
5
|
+
*
|
|
6
|
+
* A WEB device-flow claim (`claimSessionByToken`) plants only IN-MEMORY tokens:
|
|
7
|
+
* unlike a redirect/FedCM/silent sign-in, it never causes the IdP to plant a
|
|
8
|
+
* `fedcm_session` cookie. So a reload has nothing to restore from — the
|
|
9
|
+
* silent-iframe and `/sso` paths find no IdP session and the session is lost.
|
|
10
|
+
*
|
|
11
|
+
* This primitive closes that gap. AFTER the claim has committed and the session
|
|
12
|
+
* has been durably persisted, it performs ONE top-level establish hop through
|
|
13
|
+
* the RP's own per-apex IdP host (`auth.<rp-apex>`), reusing the EXISTING
|
|
14
|
+
* `/sso/establish` endpoint: the server mints a short-lived, host+audience-bound
|
|
15
|
+
* establish-token and returns a fully-formed establish URL; navigating to it
|
|
16
|
+
* plants the durable first-party `fedcm_session` cookie and bounces back to the
|
|
17
|
+
* RP callback with an opaque code the standard `sso-return` cold-boot step
|
|
18
|
+
* exchanges.
|
|
19
|
+
*
|
|
20
|
+
* It reuses the SAME per-origin `sessionStorage` bounce contract
|
|
21
|
+
* (`ssoStateKey` / `ssoGuardKey` / `ssoDestKey`) that {@link buildSsoBounceUrl}
|
|
22
|
+
* primes for the terminal `/sso` bounce, so the post-bounce `sso-return` step
|
|
23
|
+
* (`consumeSsoReturn`) validates the CSRF `state`, exchanges the code, and
|
|
24
|
+
* restores the user's real destination with no extra wiring.
|
|
25
|
+
*
|
|
26
|
+
* Contract:
|
|
27
|
+
* - WEB only — off-web / native it is a no-op returning `false`.
|
|
28
|
+
* - NEVER fires while sitting on the central IdP origin (that would loop the
|
|
29
|
+
* IdP against itself).
|
|
30
|
+
* - Bounce state is persisted ONLY after the establish-URL request succeeds, so
|
|
31
|
+
* a failed request leaves no stale state behind.
|
|
32
|
+
* - SINGLE attempt: the caller invokes this exactly once per successful claim.
|
|
33
|
+
* On ANY failure it does NOT navigate and returns `false`, leaving the
|
|
34
|
+
* committed in-memory session exactly as-is (the user is no worse off than
|
|
35
|
+
* before this hop existed).
|
|
36
|
+
* - Total: never throws. Failures are reported via {@link deps.onError} only.
|
|
37
|
+
*/
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.establishIdpSessionAfterClaim = establishIdpSessionAfterClaim;
|
|
40
|
+
const ssoBounce_1 = require("./ssoBounce");
|
|
41
|
+
const OxyServices_sso_1 = require("../mixins/OxyServices.sso");
|
|
42
|
+
/**
|
|
43
|
+
* Perform the post-claim establish hop. Returns `true` when a navigation to the
|
|
44
|
+
* establish URL was initiated (the document is being torn down and replaced by
|
|
45
|
+
* the IdP), `false` on every no-op / failure path.
|
|
46
|
+
*
|
|
47
|
+
* @param client - The exchange surface (`oxyServices.requestSsoEstablishUrl`).
|
|
48
|
+
* @param deps - Injectable web seams; see {@link EstablishAfterClaimDeps}.
|
|
49
|
+
*/
|
|
50
|
+
async function establishIdpSessionAfterClaim(client, deps = {}) {
|
|
51
|
+
const isWeb = deps.isWeb ??
|
|
52
|
+
(() => typeof window !== 'undefined' &&
|
|
53
|
+
typeof window.sessionStorage !== 'undefined');
|
|
54
|
+
if (!isWeb()) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
const storage = deps.storage ?? window.sessionStorage;
|
|
58
|
+
const location = deps.location ?? window.location;
|
|
59
|
+
const navigate = deps.navigate ?? ssoBounce_1.ssoNavigate;
|
|
60
|
+
const generateState = deps.generateState ?? OxyServices_sso_1.generateSsoState;
|
|
61
|
+
const now = deps.now ?? (() => Date.now());
|
|
62
|
+
const origin = location.origin;
|
|
63
|
+
// Never establish while sitting on the central IdP itself — that would bounce
|
|
64
|
+
// the IdP against itself. (The device-flow claim can only happen on an RP.)
|
|
65
|
+
if ((0, ssoBounce_1.isCentralIdPOrigin)(origin)) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const state = generateState();
|
|
69
|
+
let establishUrl;
|
|
70
|
+
try {
|
|
71
|
+
const result = await client.requestSsoEstablishUrl(origin, state);
|
|
72
|
+
if (!result ||
|
|
73
|
+
typeof result.establishUrl !== 'string' ||
|
|
74
|
+
result.establishUrl.length === 0) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
establishUrl = result.establishUrl;
|
|
78
|
+
// Defense-in-depth before a TOP-LEVEL navigation: the establish URL is
|
|
79
|
+
// server-formed, but never follow anything that is not a well-formed https
|
|
80
|
+
// `/sso/establish` on an `auth.` host. A malformed or unexpected URL aborts
|
|
81
|
+
// silently (no navigation, no state persisted) — same total/no-throw
|
|
82
|
+
// contract — rather than navigating the document somewhere unintended.
|
|
83
|
+
let parsedEstablishUrl;
|
|
84
|
+
try {
|
|
85
|
+
parsedEstablishUrl = new URL(establishUrl);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
if (parsedEstablishUrl.protocol !== 'https:' ||
|
|
91
|
+
parsedEstablishUrl.pathname !== '/sso/establish' ||
|
|
92
|
+
!parsedEstablishUrl.hostname.toLowerCase().startsWith('auth.')) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
// Persist the bounce state ONLY now that the request has succeeded and the
|
|
96
|
+
// URL is validated — so a failed/rejected request never leaves stale state
|
|
97
|
+
// behind. This is the exact contract the terminal `/sso` bounce primes via
|
|
98
|
+
// `buildSsoBounceUrl`, so the post-bounce `sso-return` step (`consumeSsoReturn`)
|
|
99
|
+
// validates `state`, exchanges the returned code, and restores the dest.
|
|
100
|
+
storage.setItem((0, ssoBounce_1.ssoStateKey)(origin), state);
|
|
101
|
+
storage.setItem((0, ssoBounce_1.ssoGuardKey)(origin), String(now()));
|
|
102
|
+
storage.setItem((0, ssoBounce_1.ssoDestKey)(origin), location.href);
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
deps.onError?.(error);
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
navigate(establishUrl);
|
|
109
|
+
return true;
|
|
110
|
+
}
|