@lvce-editor/auth-worker 3.18.0 → 3.19.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/authWorkerMain.js +82 -52
- package/package.json +1 -1
package/dist/authWorkerMain.js
CHANGED
|
@@ -1140,28 +1140,6 @@ const sendMessagePortToOpenerWorker$1 = async (port, rpcId) => {
|
|
|
1140
1140
|
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToOpenerWorker', port, command, rpcId);
|
|
1141
1141
|
};
|
|
1142
1142
|
|
|
1143
|
-
const sendMessagePortToAuthProcess = async port => {
|
|
1144
|
-
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, 'HandleMessagePortForAuthProcess.handleMessagePortForAuthProcess');
|
|
1145
|
-
};
|
|
1146
|
-
const initializeAuthProcess = async () => {
|
|
1147
|
-
const rpc = await create$2({
|
|
1148
|
-
commandMap: {},
|
|
1149
|
-
send: sendMessagePortToAuthProcess
|
|
1150
|
-
});
|
|
1151
|
-
set$2(rpc);
|
|
1152
|
-
};
|
|
1153
|
-
|
|
1154
|
-
const sendMessagePortToMainProcess = async port => {
|
|
1155
|
-
await invokeAndTransfer('SendMessagePortToMainProcess.sendMessagePortToMainProcess', port, 'HandleElectronMessagePort.handleElectronMessagePort', 0);
|
|
1156
|
-
};
|
|
1157
|
-
const initializeMainProcess = async () => {
|
|
1158
|
-
const rpc = await create$2({
|
|
1159
|
-
commandMap: {},
|
|
1160
|
-
send: sendMessagePortToMainProcess
|
|
1161
|
-
});
|
|
1162
|
-
set$1(rpc);
|
|
1163
|
-
};
|
|
1164
|
-
|
|
1165
1143
|
const sendMessagePortToOpenerWorker = async port => {
|
|
1166
1144
|
await sendMessagePortToOpenerWorker$1(port, 0);
|
|
1167
1145
|
};
|
|
@@ -1275,7 +1253,8 @@ const setAuthBackendUrl = backendUrl => {
|
|
|
1275
1253
|
};
|
|
1276
1254
|
|
|
1277
1255
|
const state$3 = {
|
|
1278
|
-
platform: Web
|
|
1256
|
+
platform: Web,
|
|
1257
|
+
useNativeAuth: false
|
|
1279
1258
|
};
|
|
1280
1259
|
const getAuthPlatform = () => {
|
|
1281
1260
|
return state$3.platform;
|
|
@@ -1284,6 +1263,12 @@ const setAuthPlatform = value => {
|
|
|
1284
1263
|
state$3.platform = value;
|
|
1285
1264
|
};
|
|
1286
1265
|
|
|
1266
|
+
// Native shells can use loopback OAuth without Electron's process or secret storage.
|
|
1267
|
+
const setUseNativeAuth = value => {
|
|
1268
|
+
state$3.useNativeAuth = value;
|
|
1269
|
+
};
|
|
1270
|
+
const getUseNativeAuth = () => state$3.useNativeAuth;
|
|
1271
|
+
|
|
1287
1272
|
let USER_AGENT;
|
|
1288
1273
|
if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
|
|
1289
1274
|
const NAME = 'oauth4webapi';
|
|
@@ -3140,7 +3125,16 @@ const getElectronAuthorizationCode = async uid => {
|
|
|
3140
3125
|
const waitForElectronBackendLogin = async (backendUrl, uid, redirectUri, codeVerifier, timeoutMs = 30_000, pollIntervalMs = 1000, getAuthorizationCode = getElectronAuthorizationCode, exchangeAuthorizationCode = exchangeElectronAuthorizationCode, getUserName = getOidcUserName) => {
|
|
3141
3126
|
const deadline = Date.now() + timeoutMs;
|
|
3142
3127
|
while (Date.now() < deadline) {
|
|
3143
|
-
|
|
3128
|
+
let timer;
|
|
3129
|
+
const timeout = new Promise(resolve => {
|
|
3130
|
+
timer = setTimeout(resolve, Math.max(0, deadline - Date.now()));
|
|
3131
|
+
});
|
|
3132
|
+
let authorizationCode;
|
|
3133
|
+
try {
|
|
3134
|
+
authorizationCode = await Promise.race([getAuthorizationCode(uid), timeout]);
|
|
3135
|
+
} finally {
|
|
3136
|
+
clearTimeout(timer);
|
|
3137
|
+
}
|
|
3144
3138
|
if (hasAuthorizationCode(authorizationCode)) {
|
|
3145
3139
|
const tokenResponse = await exchangeAuthorizationCode(backendUrl, authorizationCode, redirectUri, codeVerifier);
|
|
3146
3140
|
const authAccessTokenExpiresAt = getAccessTokenExpiresAt(tokenResponse.expiresIn);
|
|
@@ -3181,37 +3175,45 @@ const getMockLoginResult = async (signingInState, persistResult) => {
|
|
|
3181
3175
|
return persistResult(getLoggedInState(signingInState, response));
|
|
3182
3176
|
};
|
|
3183
3177
|
const getInteractiveLoginResult = async (backendUrl, platform, signingInState, persistResult, selectAccount) => {
|
|
3184
|
-
const
|
|
3185
|
-
const
|
|
3186
|
-
const
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
redirectUri,
|
|
3191
|
-
state
|
|
3192
|
-
} = await getBackendLoginRequest(backendUrl, platform, uid);
|
|
3193
|
-
if (platform !== Electron) {
|
|
3194
|
-
const returnUrl = await getCurrentHref();
|
|
3195
|
-
await savePendingOidcAuthState({
|
|
3178
|
+
const nativeAuth = getUseNativeAuth();
|
|
3179
|
+
const transportPlatform = nativeAuth ? Electron : platform;
|
|
3180
|
+
const authUseRedirect = getAuthUseRedirect(transportPlatform);
|
|
3181
|
+
const uid = nativeAuth ? globalThis.crypto.randomUUID() : 0;
|
|
3182
|
+
try {
|
|
3183
|
+
const {
|
|
3196
3184
|
clientId,
|
|
3197
3185
|
codeVerifier,
|
|
3186
|
+
loginUrl,
|
|
3198
3187
|
redirectUri,
|
|
3199
|
-
returnUrl,
|
|
3200
3188
|
state
|
|
3189
|
+
} = await getBackendLoginRequest(backendUrl, transportPlatform, uid);
|
|
3190
|
+
if (transportPlatform !== Electron) {
|
|
3191
|
+
const returnUrl = await getCurrentHref();
|
|
3192
|
+
await savePendingOidcAuthState({
|
|
3193
|
+
clientId,
|
|
3194
|
+
codeVerifier,
|
|
3195
|
+
redirectUri,
|
|
3196
|
+
returnUrl,
|
|
3197
|
+
state
|
|
3198
|
+
});
|
|
3199
|
+
}
|
|
3200
|
+
await invoke$1('Open.openUrl', selectAccount ? getAccountLoginUrl(backendUrl, loginUrl) : loginUrl, platform, authUseRedirect);
|
|
3201
|
+
if (transportPlatform !== Electron && authUseRedirect) {
|
|
3202
|
+
return signingInState;
|
|
3203
|
+
}
|
|
3204
|
+
const authState = transportPlatform === Electron ? await waitForElectronBackendLogin(backendUrl, uid, redirectUri, codeVerifier) : await waitForBackendLogin(backendUrl);
|
|
3205
|
+
if (transportPlatform !== Electron) {
|
|
3206
|
+
await clearPendingOidcAuthState();
|
|
3207
|
+
}
|
|
3208
|
+
return persistResult({
|
|
3209
|
+
...authState,
|
|
3210
|
+
authClientId: clientId
|
|
3201
3211
|
});
|
|
3212
|
+
} finally {
|
|
3213
|
+
if (nativeAuth) {
|
|
3214
|
+
await invoke$3('OAuthServer.dispose', String(uid));
|
|
3215
|
+
}
|
|
3202
3216
|
}
|
|
3203
|
-
await invoke$1('Open.openUrl', selectAccount ? getAccountLoginUrl(backendUrl, loginUrl) : loginUrl, platform, authUseRedirect);
|
|
3204
|
-
if (platform !== Electron && authUseRedirect) {
|
|
3205
|
-
return signingInState;
|
|
3206
|
-
}
|
|
3207
|
-
const authState = platform === Electron ? await waitForElectronBackendLogin(backendUrl, uid, redirectUri, codeVerifier) : await waitForBackendLogin(backendUrl);
|
|
3208
|
-
if (platform !== Electron) {
|
|
3209
|
-
await clearPendingOidcAuthState();
|
|
3210
|
-
}
|
|
3211
|
-
return persistResult({
|
|
3212
|
-
...authState,
|
|
3213
|
-
authClientId: clientId
|
|
3214
|
-
});
|
|
3215
3217
|
};
|
|
3216
3218
|
const handleClickLogin = async (options, persistResult = persistLoginResult) => {
|
|
3217
3219
|
const {
|
|
@@ -3234,7 +3236,7 @@ const handleClickLogin = async (options, persistResult = persistLoginResult) =>
|
|
|
3234
3236
|
if (mockLoginResult) {
|
|
3235
3237
|
return mockLoginResult;
|
|
3236
3238
|
}
|
|
3237
|
-
return getInteractiveLoginResult(backendUrl, platform, signingInState, persistResult, options.selectAccount === true);
|
|
3239
|
+
return await getInteractiveLoginResult(backendUrl, platform, signingInState, persistResult, options.selectAccount === true);
|
|
3238
3240
|
} catch (error) {
|
|
3239
3241
|
await clearPendingOidcAuthState();
|
|
3240
3242
|
const errorMessage = error instanceof Error && error.message ? error.message : 'Backend authentication failed.';
|
|
@@ -3521,9 +3523,37 @@ const syncBackendAuth = async backendUrl => initialize({
|
|
|
3521
3523
|
backendUrl
|
|
3522
3524
|
});
|
|
3523
3525
|
|
|
3524
|
-
const
|
|
3526
|
+
const sendMessagePortToAuthProcess = async port => {
|
|
3527
|
+
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, 'HandleMessagePortForAuthProcess.handleMessagePortForAuthProcess');
|
|
3528
|
+
};
|
|
3529
|
+
const initializeAuthProcess = async () => {
|
|
3530
|
+
const rpc = await create$2({
|
|
3531
|
+
commandMap: {},
|
|
3532
|
+
send: sendMessagePortToAuthProcess
|
|
3533
|
+
});
|
|
3534
|
+
set$2(rpc);
|
|
3535
|
+
};
|
|
3536
|
+
|
|
3537
|
+
const sendMessagePortToMainProcess = async port => {
|
|
3538
|
+
await invokeAndTransfer('SendMessagePortToMainProcess.sendMessagePortToMainProcess', port, 'HandleElectronMessagePort.handleElectronMessagePort', 0);
|
|
3539
|
+
};
|
|
3540
|
+
const initializeMainProcess = async () => {
|
|
3541
|
+
const rpc = await create$2({
|
|
3542
|
+
commandMap: {},
|
|
3543
|
+
send: sendMessagePortToMainProcess
|
|
3544
|
+
});
|
|
3545
|
+
set$1(rpc);
|
|
3546
|
+
};
|
|
3547
|
+
|
|
3548
|
+
const configure = async options => {
|
|
3525
3549
|
setAuthBackendUrl(options.backendUrl);
|
|
3526
3550
|
setAuthPlatform(options.platform);
|
|
3551
|
+
setUseNativeAuth(options.useNativeAuth === true);
|
|
3552
|
+
if (options.platform === Electron) {
|
|
3553
|
+
await Promise.all([initializeAuthProcess(), initializeMainProcess()]);
|
|
3554
|
+
} else if (options.useNativeAuth) {
|
|
3555
|
+
await initializeAuthProcess();
|
|
3556
|
+
}
|
|
3527
3557
|
};
|
|
3528
3558
|
|
|
3529
3559
|
const handleMessagePort = async (port, rpcId) => {
|
|
@@ -3567,7 +3597,7 @@ const initializeRendererWorker = async () => {
|
|
|
3567
3597
|
};
|
|
3568
3598
|
|
|
3569
3599
|
const listen = async () => {
|
|
3570
|
-
await Promise.all([initializeRendererWorker(), initializeOpenerWorker()
|
|
3600
|
+
await Promise.all([initializeRendererWorker(), initializeOpenerWorker()]);
|
|
3571
3601
|
};
|
|
3572
3602
|
|
|
3573
3603
|
const main = async () => {
|