@oxyhq/core 1.11.22 → 1.11.24
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/README.md +2 -2
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/HttpService.js +52 -0
- package/dist/cjs/OxyServices.base.js +16 -0
- package/dist/cjs/mixins/OxyServices.fedcm.js +169 -73
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/HttpService.js +52 -0
- package/dist/esm/OxyServices.base.js +16 -0
- package/dist/esm/mixins/OxyServices.fedcm.js +169 -73
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/HttpService.d.ts +31 -0
- package/dist/types/OxyServices.base.d.ts +14 -0
- package/dist/types/OxyServices.d.ts +9 -0
- package/dist/types/mixins/OxyServices.analytics.d.ts +1 -0
- package/dist/types/mixins/OxyServices.appData.d.ts +1 -0
- package/dist/types/mixins/OxyServices.assets.d.ts +1 -0
- package/dist/types/mixins/OxyServices.auth.d.ts +1 -0
- package/dist/types/mixins/OxyServices.contacts.d.ts +1 -0
- package/dist/types/mixins/OxyServices.developer.d.ts +1 -0
- package/dist/types/mixins/OxyServices.devices.d.ts +1 -0
- package/dist/types/mixins/OxyServices.features.d.ts +6 -1
- package/dist/types/mixins/OxyServices.fedcm.d.ts +20 -1
- package/dist/types/mixins/OxyServices.karma.d.ts +1 -0
- package/dist/types/mixins/OxyServices.language.d.ts +1 -0
- package/dist/types/mixins/OxyServices.location.d.ts +1 -0
- package/dist/types/mixins/OxyServices.managedAccounts.d.ts +1 -0
- package/dist/types/mixins/OxyServices.payment.d.ts +1 -0
- package/dist/types/mixins/OxyServices.popup.d.ts +1 -0
- package/dist/types/mixins/OxyServices.privacy.d.ts +1 -0
- package/dist/types/mixins/OxyServices.redirect.d.ts +1 -0
- package/dist/types/mixins/OxyServices.security.d.ts +1 -0
- package/dist/types/mixins/OxyServices.topics.d.ts +1 -0
- package/dist/types/mixins/OxyServices.user.d.ts +1 -0
- package/dist/types/mixins/OxyServices.utility.d.ts +1 -0
- package/package.json +1 -1
- package/src/HttpService.ts +53 -0
- package/src/OxyServices.base.ts +17 -0
- package/src/OxyServices.ts +10 -0
- package/src/mixins/OxyServices.fedcm.ts +187 -78
- package/src/mixins/__tests__/fedcm.test.ts +231 -0
- package/src/mixins/__tests__/onTokensChanged.test.ts +130 -0
package/dist/cjs/HttpService.js
CHANGED
|
@@ -109,6 +109,16 @@ class HttpService {
|
|
|
109
109
|
this.tokenRefreshPromise = null;
|
|
110
110
|
this.tokenRefreshCooldownUntil = 0;
|
|
111
111
|
this._onTokenRefreshed = null;
|
|
112
|
+
/**
|
|
113
|
+
* Fan-out listeners notified on EVERY access-token change on this instance:
|
|
114
|
+
* explicit `setTokens`, `clearTokens`, a successful silent refresh, and the
|
|
115
|
+
* internal 401-driven clear. Unlike the single-slot `_onTokenRefreshed`
|
|
116
|
+
* (owned by AuthManager for the refresh path only), this is a Set so multiple
|
|
117
|
+
* independent observers can mirror token state without clobbering each other.
|
|
118
|
+
*
|
|
119
|
+
* Each listener receives the resulting access token, or `null` when cleared.
|
|
120
|
+
*/
|
|
121
|
+
this._tokenChangeListeners = new Set();
|
|
112
122
|
// Acting-as identity for managed accounts
|
|
113
123
|
this._actingAsUserId = null;
|
|
114
124
|
// Performance monitoring
|
|
@@ -312,6 +322,7 @@ class HttpService {
|
|
|
312
322
|
// Refresh failed or no token — clear tokens and stale CSRF
|
|
313
323
|
this.tokenStore.clearTokens();
|
|
314
324
|
this.tokenStore.clearCsrfToken();
|
|
325
|
+
this.notifyTokenChange();
|
|
315
326
|
}
|
|
316
327
|
// On 403 with CSRF error, clear cached token and retry once
|
|
317
328
|
if (response.status === 403 && !config._isCsrfRetry) {
|
|
@@ -691,6 +702,7 @@ class HttpService {
|
|
|
691
702
|
const { accessToken: newToken } = await response.json();
|
|
692
703
|
this.tokenStore.setTokens(newToken);
|
|
693
704
|
this._onTokenRefreshed?.(newToken);
|
|
705
|
+
this.notifyTokenChange();
|
|
694
706
|
this.logger.debug('Token refreshed');
|
|
695
707
|
return `Bearer ${newToken}`;
|
|
696
708
|
}
|
|
@@ -756,6 +768,7 @@ class HttpService {
|
|
|
756
768
|
// Token management
|
|
757
769
|
setTokens(accessToken, refreshToken = '') {
|
|
758
770
|
this.tokenStore.setTokens(accessToken, refreshToken);
|
|
771
|
+
this.notifyTokenChange();
|
|
759
772
|
}
|
|
760
773
|
set onTokenRefreshed(callback) {
|
|
761
774
|
this._onTokenRefreshed = callback;
|
|
@@ -763,6 +776,45 @@ class HttpService {
|
|
|
763
776
|
clearTokens() {
|
|
764
777
|
this.tokenStore.clearTokens();
|
|
765
778
|
this.tokenStore.clearCsrfToken();
|
|
779
|
+
this.notifyTokenChange();
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Subscribe to access-token changes on this instance.
|
|
783
|
+
*
|
|
784
|
+
* Fires on every mutation of the access token — `setTokens`, `clearTokens`,
|
|
785
|
+
* a successful silent refresh, and the internal 401-driven clear — passing
|
|
786
|
+
* the resulting token (or `null` when cleared). Returns an unsubscribe
|
|
787
|
+
* function; call it on teardown to avoid leaks.
|
|
788
|
+
*
|
|
789
|
+
* This is the single hook downstream code (e.g. @oxyhq/services' OxyProvider)
|
|
790
|
+
* uses to keep an external token sink — such as the shared `oxyClient`
|
|
791
|
+
* singleton — in lockstep with the active session, regardless of which code
|
|
792
|
+
* path mutated the token.
|
|
793
|
+
*/
|
|
794
|
+
addTokenChangeListener(listener) {
|
|
795
|
+
this._tokenChangeListeners.add(listener);
|
|
796
|
+
return () => {
|
|
797
|
+
this._tokenChangeListeners.delete(listener);
|
|
798
|
+
};
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* Notify all token-change listeners with the current access token.
|
|
802
|
+
* Listener exceptions are isolated so one bad subscriber cannot break token
|
|
803
|
+
* propagation to the others or to the calling auth flow.
|
|
804
|
+
* @internal
|
|
805
|
+
*/
|
|
806
|
+
notifyTokenChange() {
|
|
807
|
+
if (this._tokenChangeListeners.size === 0)
|
|
808
|
+
return;
|
|
809
|
+
const accessToken = this.tokenStore.getAccessToken();
|
|
810
|
+
for (const listener of this._tokenChangeListeners) {
|
|
811
|
+
try {
|
|
812
|
+
listener(accessToken);
|
|
813
|
+
}
|
|
814
|
+
catch (error) {
|
|
815
|
+
this.logger.error('Token change listener threw:', error);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
766
818
|
}
|
|
767
819
|
getAccessToken() {
|
|
768
820
|
return this.tokenStore.getAccessToken();
|
|
@@ -113,6 +113,22 @@ class OxyServicesBase {
|
|
|
113
113
|
this._cachedUserId = undefined;
|
|
114
114
|
this._cachedAccessToken = null;
|
|
115
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Subscribe to access-token changes on this client.
|
|
118
|
+
*
|
|
119
|
+
* The listener fires on every access-token mutation — explicit
|
|
120
|
+
* `setTokens`/`clearTokens`, a successful silent refresh, and the internal
|
|
121
|
+
* 401-driven clear — receiving the resulting token, or `null` when cleared.
|
|
122
|
+
* Returns an unsubscribe function.
|
|
123
|
+
*
|
|
124
|
+
* Primary use: keeping an external token sink (e.g. the shared `oxyClient`
|
|
125
|
+
* singleton) in lockstep with whichever `OxyServices` instance actually owns
|
|
126
|
+
* the session, so imperative consumers reading the singleton always observe
|
|
127
|
+
* the live token regardless of the code path that changed it.
|
|
128
|
+
*/
|
|
129
|
+
onTokensChanged(listener) {
|
|
130
|
+
return this.httpService.addTokenChangeListener(listener);
|
|
131
|
+
}
|
|
116
132
|
/**
|
|
117
133
|
* Get the current user ID from the access token.
|
|
118
134
|
* Caches the decoded value and invalidates when the token changes.
|
|
@@ -37,12 +37,44 @@ function isUnknownModeEnumError(error) {
|
|
|
37
37
|
((message.includes('active') || message.includes('passive')) &&
|
|
38
38
|
(message.includes('enum') || message.includes('not a valid'))));
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Detect a `navigator.credentials.get` rejection that is consistent with
|
|
42
|
+
* "the supplied loginHint matched no account at the IdP".
|
|
43
|
+
*
|
|
44
|
+
* When an RP passes a `loginHint` and the IdP returns accounts but NONE of them
|
|
45
|
+
* declare that hint in their `login_hints`, Chrome filters every account out,
|
|
46
|
+
* greys it in the chooser ("You can't sign in using this account"), logs
|
|
47
|
+
* "Accounts were received, but none matched the login hint…", and ultimately
|
|
48
|
+
* rejects the credential request — surfacing as a `NotAllowedError` /
|
|
49
|
+
* `AbortError` (the same shape as a user-cancelled or timed-out request). A
|
|
50
|
+
* stale hint left over from a previously-signed-in/test account therefore hard
|
|
51
|
+
* -blocks sign-in.
|
|
52
|
+
*
|
|
53
|
+
* We can only safely apply the clear-and-retry recovery when a `loginHint` was
|
|
54
|
+
* actually supplied; without one this is just a normal cancel/timeout and must
|
|
55
|
+
* NOT be retried. Callers gate on `hadLoginHint` before calling this.
|
|
56
|
+
*/
|
|
57
|
+
function isPossibleHintMismatchError(error) {
|
|
58
|
+
if (!(error instanceof Error))
|
|
59
|
+
return false;
|
|
60
|
+
// FedCM surfaces a filtered-out / no-eligible-account outcome as
|
|
61
|
+
// NotAllowedError (current Chrome) or AbortError (our own timeout abort while
|
|
62
|
+
// the chooser had no selectable account). Both are indistinguishable from a
|
|
63
|
+
// genuine user cancel at the API level, so the gate on "a hint was supplied"
|
|
64
|
+
// (in the caller) is what makes the retry safe and targeted.
|
|
65
|
+
return error.name === 'NotAllowedError' || error.name === 'AbortError';
|
|
66
|
+
}
|
|
40
67
|
const FEDCM_LOGIN_HINT_KEY = 'oxy_fedcm_login_hint';
|
|
41
68
|
// Global lock to prevent concurrent FedCM requests
|
|
42
69
|
// FedCM only allows one navigator.credentials.get request at a time
|
|
43
70
|
let fedCMRequestInProgress = false;
|
|
44
71
|
let fedCMRequestPromise = null;
|
|
45
72
|
let currentMediationMode = null;
|
|
73
|
+
// AbortController of the in-flight request, exposed at module scope so an
|
|
74
|
+
// arriving INTERACTIVE request can abort a slow/hung SILENT one instead of
|
|
75
|
+
// blocking on it (see requestIdentityCredential). Set when a request starts,
|
|
76
|
+
// cleared in that request's `finally`.
|
|
77
|
+
let fedCMActiveController = null;
|
|
46
78
|
/**
|
|
47
79
|
* Federated Credential Management (FedCM) Authentication Mixin
|
|
48
80
|
*
|
|
@@ -71,9 +103,12 @@ function OxyServicesFedCMMixin(Base) {
|
|
|
71
103
|
super(...args);
|
|
72
104
|
}
|
|
73
105
|
resolveFedcmConfigUrl() {
|
|
106
|
+
// `DEFAULT_CONFIG_URL` is a static on the composed class; read it off the
|
|
107
|
+
// most-derived constructor through a typed cast (not `any`).
|
|
108
|
+
const configCtor = this.constructor;
|
|
74
109
|
return this.config.authWebUrl
|
|
75
110
|
? `${this.config.authWebUrl}/fedcm.json`
|
|
76
|
-
:
|
|
111
|
+
: configCtor.DEFAULT_CONFIG_URL;
|
|
77
112
|
}
|
|
78
113
|
/**
|
|
79
114
|
* Check if FedCM is supported in the current browser
|
|
@@ -117,68 +152,105 @@ function OxyServicesFedCMMixin(Base) {
|
|
|
117
152
|
if (!this.isFedCMSupported()) {
|
|
118
153
|
throw new OxyServices_errors_1.OxyAuthenticationError('FedCM not supported in this browser. Please update your browser or use an alternative sign-in method.');
|
|
119
154
|
}
|
|
155
|
+
// Use provided loginHint, or fall back to stored last-used account ID.
|
|
156
|
+
const initialLoginHint = options.loginHint || this.getStoredLoginHint();
|
|
120
157
|
try {
|
|
121
|
-
|
|
122
|
-
// `/fedcm/exchange` can validate it. A caller-supplied nonce is
|
|
123
|
-
// respected as-is for advanced use cases.
|
|
124
|
-
const nonce = options.nonce || (await this.getFedcmNonce());
|
|
125
|
-
const clientId = this.getClientId();
|
|
126
|
-
// Use provided loginHint, or fall back to stored last-used account ID
|
|
127
|
-
const loginHint = options.loginHint || this.getStoredLoginHint();
|
|
128
|
-
debug.log('Interactive sign-in: Requesting credential for', clientId, loginHint ? `(hint: ${loginHint})` : '');
|
|
129
|
-
// Request credential from browser's native identity flow.
|
|
130
|
-
// mode: 'active' signals this is a user-gesture-initiated (button) flow.
|
|
131
|
-
// 'active' is the current W3C spec value; requestIdentityCredential
|
|
132
|
-
// transparently retries with the legacy 'button' value for Chrome 125–131.
|
|
133
|
-
const credential = await this.requestIdentityCredential({
|
|
134
|
-
configURL: this.resolveFedcmConfigUrl(),
|
|
135
|
-
clientId,
|
|
136
|
-
nonce,
|
|
137
|
-
context: options.context,
|
|
138
|
-
loginHint,
|
|
139
|
-
mode: 'active',
|
|
140
|
-
});
|
|
141
|
-
if (!credential || !credential.token) {
|
|
142
|
-
throw new OxyServices_errors_1.OxyAuthenticationError('No credential received from browser');
|
|
143
|
-
}
|
|
144
|
-
debug.log('Interactive sign-in: Got credential, exchanging for session');
|
|
145
|
-
// Exchange FedCM ID token for Oxy session
|
|
146
|
-
const session = await this.exchangeIdTokenForSession(credential.token);
|
|
147
|
-
// Store access token in HttpService. `accessToken`/`refreshToken` are
|
|
148
|
-
// declared optional on SessionLoginResponse; default the refresh token to
|
|
149
|
-
// an empty string when the exchange did not return one.
|
|
150
|
-
if (session?.accessToken) {
|
|
151
|
-
this.httpService.setTokens(session.accessToken, session.refreshToken ?? '');
|
|
152
|
-
}
|
|
153
|
-
// Store the user ID as loginHint for future FedCM requests
|
|
154
|
-
if (session?.user?.id) {
|
|
155
|
-
this.storeLoginHint(session.user.id);
|
|
156
|
-
}
|
|
157
|
-
debug.log('Interactive sign-in: Success!', { userId: session?.user?.id });
|
|
158
|
-
return session;
|
|
158
|
+
return await this.attemptInteractiveSignIn(options, initialLoginHint);
|
|
159
159
|
}
|
|
160
160
|
catch (error) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
//
|
|
164
|
-
//
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
161
|
+
// A STALE loginHint (e.g. left over from a previously-signed-in or test
|
|
162
|
+
// account) that matches no account at the IdP makes Chrome filter out
|
|
163
|
+
// every account and reject the request — indistinguishable from a user
|
|
164
|
+
// cancel. When that happens AND we supplied a hint, clear the bad hint
|
|
165
|
+
// and retry the credential request ONCE with no hint, which lets the
|
|
166
|
+
// chooser surface the genuinely available account(s). We only do this for
|
|
167
|
+
// a hint we pulled from storage (not a caller-supplied one), and only
|
|
168
|
+
// once, so a real cancel never loops.
|
|
169
|
+
const usedStoredHint = !!initialLoginHint && !options.loginHint;
|
|
170
|
+
if (usedStoredHint && isPossibleHintMismatchError(error)) {
|
|
171
|
+
debug.log('Interactive sign-in: stored loginHint matched no account; clearing it and retrying without a hint');
|
|
172
|
+
this.clearLoginHint();
|
|
173
|
+
return await this.attemptInteractiveSignIn(options, undefined);
|
|
174
174
|
}
|
|
175
|
-
|
|
176
|
-
debug.error('FedCM token retrieval error - this may be a browser or IdP configuration issue');
|
|
177
|
-
throw new OxyServices_errors_1.OxyAuthenticationError('Authentication failed. Please try again or use an alternative sign-in method.');
|
|
178
|
-
}
|
|
179
|
-
throw error;
|
|
175
|
+
throw this.normalizeInteractiveSignInError(error);
|
|
180
176
|
}
|
|
181
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Run a single interactive FedCM credential request + token exchange for the
|
|
180
|
+
* given (possibly undefined) loginHint. A successful exchange plants the
|
|
181
|
+
* access token and persists the user id as the future loginHint — the hint is
|
|
182
|
+
* therefore only ever stored after a GENUINELY successful sign-in, never
|
|
183
|
+
* speculatively.
|
|
184
|
+
*
|
|
185
|
+
* @private
|
|
186
|
+
*/
|
|
187
|
+
async attemptInteractiveSignIn(options, loginHint) {
|
|
188
|
+
// Prefer a server-minted, origin-bound nonce so the downstream
|
|
189
|
+
// `/fedcm/exchange` can validate it. A caller-supplied nonce is
|
|
190
|
+
// respected as-is for advanced use cases.
|
|
191
|
+
const nonce = options.nonce || (await this.getFedcmNonce());
|
|
192
|
+
const clientId = this.getClientId();
|
|
193
|
+
debug.log('Interactive sign-in: Requesting credential for', clientId, loginHint ? `(hint: ${loginHint})` : '');
|
|
194
|
+
// Request credential from browser's native identity flow.
|
|
195
|
+
// mode: 'active' signals this is a user-gesture-initiated (button) flow.
|
|
196
|
+
// 'active' is the current W3C spec value; requestIdentityCredential
|
|
197
|
+
// transparently retries with the legacy 'button' value for Chrome 125–131.
|
|
198
|
+
const credential = await this.requestIdentityCredential({
|
|
199
|
+
configURL: this.resolveFedcmConfigUrl(),
|
|
200
|
+
clientId,
|
|
201
|
+
nonce,
|
|
202
|
+
context: options.context,
|
|
203
|
+
loginHint,
|
|
204
|
+
mode: 'active',
|
|
205
|
+
});
|
|
206
|
+
if (!credential || !credential.token) {
|
|
207
|
+
throw new OxyServices_errors_1.OxyAuthenticationError('No credential received from browser');
|
|
208
|
+
}
|
|
209
|
+
debug.log('Interactive sign-in: Got credential, exchanging for session');
|
|
210
|
+
// Exchange FedCM ID token for Oxy session
|
|
211
|
+
const session = await this.exchangeIdTokenForSession(credential.token);
|
|
212
|
+
// Store access token in HttpService. `accessToken`/`refreshToken` are
|
|
213
|
+
// declared optional on SessionLoginResponse; default the refresh token to
|
|
214
|
+
// an empty string when the exchange did not return one.
|
|
215
|
+
if (session?.accessToken) {
|
|
216
|
+
this.httpService.setTokens(session.accessToken, session.refreshToken ?? '');
|
|
217
|
+
}
|
|
218
|
+
// Store the user ID as loginHint for future FedCM requests — only now, after
|
|
219
|
+
// a real successful exchange, so we never persist a hint that cannot resolve.
|
|
220
|
+
if (session?.user?.id) {
|
|
221
|
+
this.storeLoginHint(session.user.id);
|
|
222
|
+
}
|
|
223
|
+
debug.log('Interactive sign-in: Success!', { userId: session?.user?.id });
|
|
224
|
+
return session;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Map a raw FedCM/exchange failure to a user-facing {@link OxyAuthenticationError}
|
|
228
|
+
* (or pass it through). Extracted so the clear-and-retry path can reuse the
|
|
229
|
+
* exact same error normalisation as the first attempt.
|
|
230
|
+
*
|
|
231
|
+
* @private
|
|
232
|
+
*/
|
|
233
|
+
normalizeInteractiveSignInError(error) {
|
|
234
|
+
debug.log('Interactive sign-in failed:', error);
|
|
235
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
236
|
+
// FedCM aborts/network failures surface as DOMException/Error instances,
|
|
237
|
+
// both of which carry a `name`. Anything else has no meaningful name.
|
|
238
|
+
const errorName = error instanceof Error ? error.name : '';
|
|
239
|
+
if (errorName === 'AbortError') {
|
|
240
|
+
return new OxyServices_errors_1.OxyAuthenticationError('Sign-in was cancelled by user');
|
|
241
|
+
}
|
|
242
|
+
if (errorName === 'NetworkError') {
|
|
243
|
+
return new OxyServices_errors_1.OxyAuthenticationError('Network error during sign-in. Please check your connection.');
|
|
244
|
+
}
|
|
245
|
+
if (errorMessage.includes('multiple accounts')) {
|
|
246
|
+
return new OxyServices_errors_1.OxyAuthenticationError('Please sign out and sign in again to use FedCM with a single account');
|
|
247
|
+
}
|
|
248
|
+
if (errorMessage.includes('retrieving a token') || errorMessage.includes('Error retrieving')) {
|
|
249
|
+
debug.error('FedCM token retrieval error - this may be a browser or IdP configuration issue');
|
|
250
|
+
return new OxyServices_errors_1.OxyAuthenticationError('Authentication failed. Please try again or use an alternative sign-in method.');
|
|
251
|
+
}
|
|
252
|
+
return error;
|
|
253
|
+
}
|
|
182
254
|
/**
|
|
183
255
|
* Silent sign-in using FedCM
|
|
184
256
|
*
|
|
@@ -319,16 +391,20 @@ function OxyServicesFedCMMixin(Base) {
|
|
|
319
391
|
// If a request is already in progress...
|
|
320
392
|
if (fedCMRequestInProgress && fedCMRequestPromise) {
|
|
321
393
|
debug.log('Request already in progress, waiting...');
|
|
322
|
-
// If
|
|
323
|
-
//
|
|
394
|
+
// If the in-flight request is SILENT and this new one is INTERACTIVE,
|
|
395
|
+
// abort the silent and proceed immediately. The silent round-trip can be
|
|
396
|
+
// slow (it runs on page load and may stall in the browser), and a user who
|
|
397
|
+
// just clicked "Sign In" must never be made to wait on — or be blocked by —
|
|
398
|
+
// it. Awaiting the silent here is what previously let a hung silent
|
|
399
|
+
// request deadlock the sign-in button, so we deliberately do NOT await it:
|
|
400
|
+
// we abort it (its own `finally` resets the lock as it settles) and fall
|
|
401
|
+
// through to start the interactive request synchronously below.
|
|
324
402
|
if (currentMediationMode === 'silent' && isInteractive) {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
// Now fall through to make the interactive request
|
|
403
|
+
debug.log('Aborting in-flight silent request to make way for interactive request');
|
|
404
|
+
fedCMActiveController?.abort();
|
|
405
|
+
// Fall through. The interactive request synchronously overwrites the
|
|
406
|
+
// lock globals (below); the aborted silent's `finally` uses identity
|
|
407
|
+
// guards so it cannot later clobber this interactive request's state.
|
|
332
408
|
}
|
|
333
409
|
else {
|
|
334
410
|
// Same type of request - wait for the existing one
|
|
@@ -343,10 +419,14 @@ function OxyServicesFedCMMixin(Base) {
|
|
|
343
419
|
fedCMRequestInProgress = true;
|
|
344
420
|
currentMediationMode = requestedMediation;
|
|
345
421
|
const controller = new AbortController();
|
|
346
|
-
|
|
422
|
+
fedCMActiveController = controller;
|
|
423
|
+
// Use shorter timeout for silent mediation since it should be quick.
|
|
424
|
+
// The timeout constants are static on the composed class; read them off the
|
|
425
|
+
// most-derived constructor through a typed cast (not `any`).
|
|
426
|
+
const timeoutCtor = this.constructor;
|
|
347
427
|
const timeoutMs = requestedMediation === 'silent'
|
|
348
|
-
?
|
|
349
|
-
:
|
|
428
|
+
? timeoutCtor.FEDCM_SILENT_TIMEOUT
|
|
429
|
+
: timeoutCtor.FEDCM_TIMEOUT;
|
|
350
430
|
const timeout = setTimeout(() => {
|
|
351
431
|
debug.log('Request timed out after', timeoutMs, 'ms (mediation:', requestedMediation + ')');
|
|
352
432
|
controller.abort();
|
|
@@ -423,9 +503,20 @@ function OxyServicesFedCMMixin(Base) {
|
|
|
423
503
|
}
|
|
424
504
|
finally {
|
|
425
505
|
clearTimeout(timeout);
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
506
|
+
// Only reset the shared lock if it still belongs to THIS request. When an
|
|
507
|
+
// interactive request aborts a slow silent one, the silent settles (and
|
|
508
|
+
// runs this `finally`) AFTER the interactive has already taken over the
|
|
509
|
+
// lock and installed its own controller/promise. Guarding on identity
|
|
510
|
+
// (`fedCMActiveController === controller`) ensures the settling silent
|
|
511
|
+
// cannot null out the interactive request's in-progress state. The
|
|
512
|
+
// request that still owns the lock clears it; the superseded one is a
|
|
513
|
+
// no-op here.
|
|
514
|
+
if (fedCMActiveController === controller) {
|
|
515
|
+
fedCMRequestInProgress = false;
|
|
516
|
+
fedCMRequestPromise = null;
|
|
517
|
+
currentMediationMode = null;
|
|
518
|
+
fedCMActiveController = null;
|
|
519
|
+
}
|
|
429
520
|
}
|
|
430
521
|
})();
|
|
431
522
|
return fedCMRequestPromise;
|
|
@@ -614,7 +705,12 @@ function OxyServicesFedCMMixin(Base) {
|
|
|
614
705
|
_a.DEFAULT_CONFIG_URL = 'https://auth.oxy.so/fedcm.json',
|
|
615
706
|
_a.FEDCM_TIMEOUT = 15000 // 15 seconds for interactive
|
|
616
707
|
,
|
|
617
|
-
|
|
708
|
+
// Silent mediation runs on page load (e.g. re-signing-in a user whose stored
|
|
709
|
+
// session was cleared after a cold-boot token fetch 401'd). The real silent
|
|
710
|
+
// round-trip — mint nonce → navigator.credentials.get → /fedcm/exchange — was
|
|
711
|
+
// measured to take more than 3s for live users, so a 3s budget timed out and
|
|
712
|
+
// left them signed out on reload. 10s gives ample margin while staying bounded.
|
|
713
|
+
_a.FEDCM_SILENT_TIMEOUT = 10000 // 10 seconds for silent mediation
|
|
618
714
|
,
|
|
619
715
|
_a;
|
|
620
716
|
}
|