@oxyhq/core 5.5.0 → 7.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 +7 -4
- 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 +54 -45
- package/dist/cjs/mixins/OxyServices.accounts.js +13 -26
- package/dist/cjs/mixins/OxyServices.auth.js +66 -201
- package/dist/cjs/mixins/OxyServices.deviceBoot.js +119 -0
- package/dist/cjs/mixins/index.js +8 -17
- package/dist/cjs/server/index.js +2 -2
- package/dist/cjs/session/SessionClient.js +40 -1
- package/dist/cjs/session/authStateStore.js +284 -0
- package/dist/cjs/session/refresh.js +264 -0
- package/dist/cjs/shared/utils/debugUtils.js +3 -3
- package/dist/cjs/utils/accountUtils.js +1 -55
- package/dist/cjs/utils/authWebUrl.js +10 -39
- package/dist/cjs/utils/coldBoot.js +10 -8
- package/dist/cjs/utils/platform.js +19 -0
- package/dist/cjs/utils/registrableApex.js +49 -0
- package/dist/cjs/utils/ssoBounce.js +15 -362
- package/dist/cjs/utils/validationUtils.js +57 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/HttpService.js +7 -4
- 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 +34 -17
- package/dist/esm/mixins/OxyServices.accounts.js +13 -26
- package/dist/esm/mixins/OxyServices.auth.js +66 -201
- package/dist/esm/mixins/OxyServices.deviceBoot.js +116 -0
- package/dist/esm/mixins/index.js +8 -17
- package/dist/esm/server/index.js +1 -1
- package/dist/esm/session/SessionClient.js +40 -1
- package/dist/esm/session/authStateStore.js +278 -0
- package/dist/esm/session/refresh.js +257 -0
- package/dist/esm/shared/utils/debugUtils.js +3 -3
- package/dist/esm/utils/accountUtils.js +0 -53
- package/dist/esm/utils/authWebUrl.js +9 -37
- package/dist/esm/utils/coldBoot.js +10 -8
- package/dist/esm/utils/platform.js +18 -0
- package/dist/esm/utils/registrableApex.js +46 -0
- package/dist/esm/utils/ssoBounce.js +14 -345
- package/dist/esm/utils/validationUtils.js +56 -0
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/HttpService.d.ts +14 -1
- 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 +14 -21
- package/dist/types/mixins/OxyServices.accounts.d.ts +24 -29
- 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.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 +5 -9
- package/dist/types/models/interfaces.d.ts +0 -67
- package/dist/types/models/session.d.ts +4 -5
- package/dist/types/server/index.d.ts +1 -1
- package/dist/types/session/SessionClient.d.ts +26 -1
- package/dist/types/session/authStateStore.d.ts +119 -0
- package/dist/types/session/refresh.d.ts +93 -0
- package/dist/types/shared/utils/debugUtils.d.ts +3 -3
- package/dist/types/utils/accountUtils.d.ts +2 -17
- package/dist/types/utils/authWebUrl.d.ts +9 -35
- package/dist/types/utils/coldBoot.d.ts +17 -14
- package/dist/types/utils/platform.d.ts +14 -0
- package/dist/types/utils/registrableApex.d.ts +31 -0
- package/dist/types/utils/ssoBounce.d.ts +14 -280
- package/dist/types/utils/validationUtils.d.ts +15 -0
- package/package.json +2 -2
- package/src/HttpService.ts +20 -4
- 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 +75 -65
- package/src/mixins/OxyServices.accounts.ts +27 -39
- package/src/mixins/OxyServices.auth.ts +78 -253
- 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__/passwordSignIn.test.ts +91 -0
- package/src/mixins/index.ts +10 -23
- package/src/models/interfaces.ts +0 -79
- package/src/models/session.ts +4 -5
- package/src/server/index.ts +1 -1
- package/src/session/SessionClient.ts +53 -2
- 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.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/refresh.ts +334 -0
- package/src/shared/utils/debugUtils.ts +3 -3
- package/src/utils/__tests__/authWebUrl.test.ts +5 -40
- package/src/utils/__tests__/registrableApex.test.ts +62 -0
- package/src/utils/__tests__/validationUtils.test.ts +30 -0
- package/src/utils/accountUtils.ts +2 -65
- package/src/utils/authWebUrl.ts +9 -39
- package/src/utils/coldBoot.ts +17 -14
- package/src/utils/platform.ts +21 -0
- package/src/utils/registrableApex.ts +45 -0
- package/src/utils/ssoBounce.ts +14 -393
- 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/fapiAutoDetect.js +0 -99
- package/dist/cjs/utils/ssoEstablish.js +0 -110
- package/dist/cjs/utils/ssoReturn.js +0 -275
- 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/fapiAutoDetect.js +0 -95
- package/dist/esm/utils/ssoEstablish.js +0 -107
- package/dist/esm/utils/ssoReturn.js +0 -271
- 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.redirect.d.ts +0 -92
- package/dist/types/mixins/OxyServices.silent.d.ts +0 -132
- package/dist/types/mixins/OxyServices.sso.d.ts +0 -138
- package/dist/types/utils/fapiAutoDetect.d.ts +0 -56
- package/dist/types/utils/ssoEstablish.d.ts +0 -85
- package/dist/types/utils/ssoReturn.d.ts +0 -156
- 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__/fapiAutoDetect.test.ts +0 -183
- 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 -276
- package/src/utils/fapiAutoDetect.ts +0 -91
- package/src/utils/ssoEstablish.ts +0 -174
- package/src/utils/ssoReturn.ts +0 -389
package/src/AuthManagerTypes.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AuthManager — public types for the multi-account cookie path.
|
|
3
|
-
*
|
|
4
|
-
* Lives in its own module (rather than the 670-line `models/interfaces.ts`)
|
|
5
|
-
* so consumers can `import type` exactly the multi-account surface without
|
|
6
|
-
* pulling in the full interfaces graph, and so `AuthManager.ts` stays
|
|
7
|
-
* decoupled from the wire shapes — these types re-state the wire as the
|
|
8
|
-
* AuthManager's in-memory representation.
|
|
9
|
-
*
|
|
10
|
-
* @module core/AuthManagerTypes
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import type { RefreshAllAccountUser } from './models/interfaces';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* One device-local account known to `AuthManager` in the cookie path.
|
|
17
|
-
*
|
|
18
|
-
* Built from a `POST /auth/refresh-all` entry, OR from a single
|
|
19
|
-
* `POST /auth/refresh?authuser=N` rotation after a switch, OR from a
|
|
20
|
-
* `handleAuthSuccess` call after a fresh login. The `accessToken` is held in
|
|
21
|
-
* memory only — the refresh token never enters JS (it lives in the httpOnly
|
|
22
|
-
* `oxy_rt_${authuser}` cookie).
|
|
23
|
-
*/
|
|
24
|
-
export interface AuthManagerAccount {
|
|
25
|
-
/** Device-local cookie slot index (0..N-1). */
|
|
26
|
-
authuser: number;
|
|
27
|
-
/** Server-side session id this slot is bound to. */
|
|
28
|
-
sessionId: string;
|
|
29
|
-
/**
|
|
30
|
-
* Projected user shape from the wire (username/avatar/color/email).
|
|
31
|
-
*
|
|
32
|
-
* `null` when a refresh-via-cookie planted a fresh access token for a slot
|
|
33
|
-
* that the AuthManager has no prior in-memory user metadata for. Callers (or
|
|
34
|
-
* the AuthManager itself) are expected to hydrate the user shape via
|
|
35
|
-
* `getCurrentUser()` after the token is planted; the chooser UI must render
|
|
36
|
-
* the public-key fallback handle until the hydration completes.
|
|
37
|
-
*/
|
|
38
|
-
user: RefreshAllAccountUser | null;
|
|
39
|
-
/** Currently-valid access token for this slot (in-memory only). */
|
|
40
|
-
accessToken: string;
|
|
41
|
-
/** ISO-8601 expiry of the access token. */
|
|
42
|
-
expiresAt: string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Outcome of `AuthManager.restoreFromCookies()`.
|
|
47
|
-
*
|
|
48
|
-
* `accounts` is sorted by `authuser` ascending (matching the server's
|
|
49
|
-
* canonical ordering). `activeAuthuser` is whichever slot the AuthManager
|
|
50
|
-
* picked as active — usually the persisted `oxy_active_authuser` if it
|
|
51
|
-
* matched a returned slot, otherwise the lowest returned `authuser`, or
|
|
52
|
-
* `null` if no accounts were restored.
|
|
53
|
-
*/
|
|
54
|
-
export interface RestoreFromCookiesResult {
|
|
55
|
-
accounts: AuthManagerAccount[];
|
|
56
|
-
activeAuthuser: number | null;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Options for `AuthManager.restoreFromCookies()` / `AuthManager.initialize()`.
|
|
61
|
-
*/
|
|
62
|
-
export interface RestoreFromCookiesOptions {
|
|
63
|
-
/**
|
|
64
|
-
* Abort the underlying `POST /auth/refresh-all` after this many milliseconds
|
|
65
|
-
* and treat it as "no signed-in accounts" instead of hanging. Forwarded
|
|
66
|
-
* verbatim to `OxyServices.refreshAllSessions({ timeout })`.
|
|
67
|
-
*
|
|
68
|
-
* Intended for the cold-boot cookie-restore step on a cross-domain RP, where
|
|
69
|
-
* the `Domain=oxy.so` refresh cookie never reaches `api.<apex>` and the
|
|
70
|
-
* request can stall with no useful answer. Omit (the default) to wait
|
|
71
|
-
* indefinitely — the warm cross-tab cascade path passes nothing, preserving
|
|
72
|
-
* its existing behaviour.
|
|
73
|
-
*/
|
|
74
|
-
timeout?: number;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Outcome of `AuthManager.switchAuthuser()`.
|
|
79
|
-
*
|
|
80
|
-
* Mirrors the wire `RefreshCookieResponse`.
|
|
81
|
-
*/
|
|
82
|
-
export interface SwitchAuthuserResult {
|
|
83
|
-
accessToken: string;
|
|
84
|
-
expiresAt: string;
|
|
85
|
-
authuser: number;
|
|
86
|
-
}
|
package/src/CrossDomainAuth.ts
DELETED
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cross-Domain Authentication Helper
|
|
3
|
-
*
|
|
4
|
-
* Provides a simplified API for cross-domain SSO authentication. The
|
|
5
|
-
* automatic sign-in path uses a full-page redirect through the central IdP
|
|
6
|
-
* (`auth.oxy.so`) — a tokenless, universal mechanism that works in every
|
|
7
|
-
* browser.
|
|
8
|
-
*
|
|
9
|
-
* FedCM (`signInWithFedCM`) is intentionally NOT part of the automatic
|
|
10
|
-
* (`'auto'`) path: it is a Chrome-only browser API, and a misconfigured or
|
|
11
|
-
* unreachable FedCM endpoint fails fast and silently, which — combined with a
|
|
12
|
-
* caller's auth-guard effect re-invoking `signIn()` whenever the user is still
|
|
13
|
-
* unauthenticated — produced a real production incident (an accelerating
|
|
14
|
-
* `autoSignIn` → FedCM-fails → redirect retry loop). `signInWithFedCM` remains
|
|
15
|
-
* available for callers that want to opt into it EXPLICITLY
|
|
16
|
-
* (`signIn({ method: 'fedcm' })`).
|
|
17
|
-
*
|
|
18
|
-
* Usage:
|
|
19
|
-
* ```typescript
|
|
20
|
-
* import { CrossDomainAuth } from '@oxyhq/core';
|
|
21
|
-
*
|
|
22
|
-
* const auth = new CrossDomainAuth(oxyServices);
|
|
23
|
-
*
|
|
24
|
-
* // Automatic method selection (always redirect)
|
|
25
|
-
* const session = await auth.signIn();
|
|
26
|
-
*
|
|
27
|
-
* // Or use a specific method
|
|
28
|
-
* auth.signInWithRedirect();
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
import type { OxyServices } from './OxyServices';
|
|
33
|
-
import type { SessionLoginResponse } from './models/session';
|
|
34
|
-
import { logger } from './utils/loggerUtils';
|
|
35
|
-
|
|
36
|
-
export interface CrossDomainAuthOptions {
|
|
37
|
-
/**
|
|
38
|
-
* Preferred authentication method
|
|
39
|
-
* - 'auto': Automatically select best method (default)
|
|
40
|
-
* - 'fedcm': Use FedCM (browser-native)
|
|
41
|
-
* - 'redirect': Use full-page redirect
|
|
42
|
-
*/
|
|
43
|
-
method?: 'auto' | 'fedcm' | 'redirect';
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Custom redirect URI (for redirect method)
|
|
47
|
-
*/
|
|
48
|
-
redirectUri?: string;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Whether to open signup page instead of login
|
|
52
|
-
*/
|
|
53
|
-
isSignup?: boolean;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Callback when auth method is selected
|
|
57
|
-
*/
|
|
58
|
-
onMethodSelected?: (method: 'fedcm' | 'redirect') => void;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export class CrossDomainAuth {
|
|
62
|
-
constructor(private oxyServices: OxyServices) {}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Sign in with automatic method selection.
|
|
66
|
-
*
|
|
67
|
-
* Auto mode always uses the full-page redirect (see the class doc comment
|
|
68
|
-
* for why FedCM was removed from this path). Pass `{ method: 'fedcm' }` to
|
|
69
|
-
* opt into FedCM explicitly.
|
|
70
|
-
*
|
|
71
|
-
* @param options - Authentication options
|
|
72
|
-
* @returns Session with user data and access token
|
|
73
|
-
*/
|
|
74
|
-
async signIn(options: CrossDomainAuthOptions = {}): Promise<SessionLoginResponse | null> {
|
|
75
|
-
const method = options.method || 'auto';
|
|
76
|
-
|
|
77
|
-
if (method === 'fedcm') {
|
|
78
|
-
return this.signInWithFedCM(options);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (method === 'redirect') {
|
|
82
|
-
this.signInWithRedirect(options);
|
|
83
|
-
return null; // Redirect doesn't return immediately
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Auto mode: try methods in order of preference.
|
|
87
|
-
return this.autoSignIn(options);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Automatic sign-in.
|
|
92
|
-
*
|
|
93
|
-
* Goes straight to the full-page redirect — the sole automatic method.
|
|
94
|
-
* FedCM is deliberately NOT attempted here (see the class doc comment):
|
|
95
|
-
* it is Chrome-only, and its fast/silent failure mode combined with a
|
|
96
|
-
* caller's auth-guard effect re-invoking `signIn()` produced a real
|
|
97
|
-
* production sign-in loop. Use `signIn({ method: 'fedcm' })` to opt in
|
|
98
|
-
* explicitly.
|
|
99
|
-
*
|
|
100
|
-
* @private
|
|
101
|
-
*/
|
|
102
|
-
private async autoSignIn(options: CrossDomainAuthOptions): Promise<SessionLoginResponse | null> {
|
|
103
|
-
options.onMethodSelected?.('redirect');
|
|
104
|
-
this.signInWithRedirect(options);
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Sign in using FedCM (Federated Credential Management)
|
|
110
|
-
*
|
|
111
|
-
* Best method - browser-native, Google-like experience
|
|
112
|
-
*/
|
|
113
|
-
async signInWithFedCM(options: CrossDomainAuthOptions = {}): Promise<SessionLoginResponse> {
|
|
114
|
-
return this.oxyServices.signInWithFedCM({
|
|
115
|
-
context: options.isSignup ? 'signup' : 'signin',
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Sign in using full-page redirect
|
|
121
|
-
*
|
|
122
|
-
* Fallback method - works everywhere but loses app state
|
|
123
|
-
*/
|
|
124
|
-
signInWithRedirect(options: CrossDomainAuthOptions = {}): void {
|
|
125
|
-
this.oxyServices.signInWithRedirect({
|
|
126
|
-
redirectUri: options.redirectUri,
|
|
127
|
-
mode: options.isSignup ? 'signup' : 'login',
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Handle redirect callback
|
|
133
|
-
*
|
|
134
|
-
* Call this on app startup to check if we're returning from auth redirect
|
|
135
|
-
*/
|
|
136
|
-
handleRedirectCallback(): SessionLoginResponse | null {
|
|
137
|
-
return this.oxyServices.handleAuthCallback();
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Silent sign-in (check for existing session)
|
|
142
|
-
*
|
|
143
|
-
* Tries to automatically sign in without user interaction, via the
|
|
144
|
-
* iframe-based silent auth against the per-apex `/auth/silent` IdP host.
|
|
145
|
-
* FedCM is deliberately NOT attempted here (see the class doc comment).
|
|
146
|
-
*
|
|
147
|
-
* @returns Session if user is already signed in, null otherwise
|
|
148
|
-
*/
|
|
149
|
-
async silentSignIn(): Promise<SessionLoginResponse | null> {
|
|
150
|
-
try {
|
|
151
|
-
return await this.oxyServices.silentSignIn();
|
|
152
|
-
} catch (error) {
|
|
153
|
-
logger.debug('iframe silent sign-in did not resolve', { component: 'CrossDomainAuth', method: 'silentSignIn' }, error);
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Restore session from storage.
|
|
160
|
-
*
|
|
161
|
-
* Access tokens are no longer persisted in browser storage; providers restore
|
|
162
|
-
* through refresh cookies / SSO code exchange instead.
|
|
163
|
-
*/
|
|
164
|
-
restoreSession(): boolean {
|
|
165
|
-
return false;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Check if FedCM is supported in current browser
|
|
170
|
-
*/
|
|
171
|
-
isFedCMSupported(): boolean {
|
|
172
|
-
// FedCM support is exposed both as a static and an instance method on
|
|
173
|
-
// OxyServices; the instance method is reliable across mixin composition.
|
|
174
|
-
return this.oxyServices.isFedCMSupported?.() || false;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Get recommended authentication method for current environment
|
|
179
|
-
*
|
|
180
|
-
* Redirect is the sole recommended automatic method — it works in every
|
|
181
|
-
* browser, unlike FedCM (Chrome-only). Callers that want FedCM must opt in
|
|
182
|
-
* explicitly via `signIn({ method: 'fedcm' })`.
|
|
183
|
-
*
|
|
184
|
-
* @returns Recommended method name and reason
|
|
185
|
-
*/
|
|
186
|
-
getRecommendedMethod(): { method: 'redirect'; reason: string } {
|
|
187
|
-
if (typeof window !== 'undefined') {
|
|
188
|
-
return {
|
|
189
|
-
method: 'redirect',
|
|
190
|
-
reason: 'Browser environment - redirect SSO works without token callback URLs',
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return {
|
|
195
|
-
method: 'redirect',
|
|
196
|
-
reason: 'Fallback method - works in all environments',
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Initialize cross-domain auth on app startup
|
|
202
|
-
*
|
|
203
|
-
* This handles:
|
|
204
|
-
* 1. Redirect callback (if returning from auth.oxy.so)
|
|
205
|
-
* 2. Silent sign-in (check for existing SSO session)
|
|
206
|
-
*
|
|
207
|
-
* @returns Session if user is authenticated, null otherwise
|
|
208
|
-
*/
|
|
209
|
-
async initialize(): Promise<SessionLoginResponse | null> {
|
|
210
|
-
// 1. Check if this is a redirect callback
|
|
211
|
-
const callbackSession = this.handleRedirectCallback();
|
|
212
|
-
if (callbackSession) {
|
|
213
|
-
return callbackSession;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// 2. Try silent sign-in (check for SSO session at auth.oxy.so)
|
|
217
|
-
return await this.silentSignIn();
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Helper function to create CrossDomainAuth instance
|
|
223
|
-
*
|
|
224
|
-
* @example
|
|
225
|
-
* ```typescript
|
|
226
|
-
* import { createCrossDomainAuth } from '@oxyhq/core';
|
|
227
|
-
*
|
|
228
|
-
* const oxyServices = new OxyServices({ baseURL: 'https://api.oxy.so' });
|
|
229
|
-
* const auth = createCrossDomainAuth(oxyServices);
|
|
230
|
-
*
|
|
231
|
-
* // On app startup
|
|
232
|
-
* const session = await auth.initialize();
|
|
233
|
-
* if (session) {
|
|
234
|
-
* console.log('User is signed in:', session.user);
|
|
235
|
-
* }
|
|
236
|
-
*
|
|
237
|
-
* // Sign in button click
|
|
238
|
-
* const session = await auth.signIn();
|
|
239
|
-
* ```
|
|
240
|
-
*/
|
|
241
|
-
export function createCrossDomainAuth(oxyServices: OxyServices): CrossDomainAuth {
|
|
242
|
-
return new CrossDomainAuth(oxyServices);
|
|
243
|
-
}
|