@lvce-editor/auth-worker 3.6.0 → 3.7.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 +110 -22
- package/package.json +1 -1
package/dist/authWorkerMain.js
CHANGED
|
@@ -1009,7 +1009,7 @@ const createMockRpc = ({
|
|
|
1009
1009
|
};
|
|
1010
1010
|
|
|
1011
1011
|
const rpcs = Object.create(null);
|
|
1012
|
-
const set$
|
|
1012
|
+
const set$3 = (id, rpc) => {
|
|
1013
1013
|
rpcs[id] = rpc;
|
|
1014
1014
|
};
|
|
1015
1015
|
const get = id => {
|
|
@@ -1042,7 +1042,7 @@ const create = rpcId => {
|
|
|
1042
1042
|
const mockRpc = createMockRpc({
|
|
1043
1043
|
commandMap
|
|
1044
1044
|
});
|
|
1045
|
-
set$
|
|
1045
|
+
set$3(rpcId, mockRpc);
|
|
1046
1046
|
// @ts-ignore
|
|
1047
1047
|
mockRpc[Symbol.dispose] = () => {
|
|
1048
1048
|
remove(rpcId);
|
|
@@ -1051,33 +1051,44 @@ const create = rpcId => {
|
|
|
1051
1051
|
return mockRpc;
|
|
1052
1052
|
},
|
|
1053
1053
|
set(rpc) {
|
|
1054
|
-
set$
|
|
1054
|
+
set$3(rpcId, rpc);
|
|
1055
1055
|
}
|
|
1056
1056
|
};
|
|
1057
1057
|
};
|
|
1058
1058
|
|
|
1059
1059
|
const {
|
|
1060
|
-
invoke: invoke$
|
|
1061
|
-
set: set$
|
|
1060
|
+
invoke: invoke$3,
|
|
1061
|
+
set: set$2
|
|
1062
1062
|
} = create(6040);
|
|
1063
1063
|
|
|
1064
|
+
const Web = 1;
|
|
1064
1065
|
const Electron = 2;
|
|
1065
1066
|
|
|
1066
1067
|
const OpenerWorker = 4561;
|
|
1067
1068
|
const RendererWorker = 1;
|
|
1069
|
+
const SharedProcess = 1492;
|
|
1068
1070
|
|
|
1069
1071
|
const {
|
|
1070
|
-
invoke: invoke$
|
|
1071
|
-
set
|
|
1072
|
+
invoke: invoke$2,
|
|
1073
|
+
set: set$1
|
|
1072
1074
|
} = create(OpenerWorker);
|
|
1073
1075
|
|
|
1074
1076
|
const {
|
|
1075
|
-
invoke,
|
|
1077
|
+
invoke: invoke$1,
|
|
1076
1078
|
invokeAndTransfer} = create(RendererWorker);
|
|
1077
1079
|
const sendMessagePortToOpenerWorker$1 = async (port, rpcId) => {
|
|
1078
1080
|
const command = 'HandleMessagePort.handleMessagePort';
|
|
1079
1081
|
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToOpenerWorker', port, command, rpcId);
|
|
1080
1082
|
};
|
|
1083
|
+
const sendMessagePortToSharedProcess$1 = async port => {
|
|
1084
|
+
const command = 'HandleElectronMessagePort.handleElectronMessagePort';
|
|
1085
|
+
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, command, 0);
|
|
1086
|
+
};
|
|
1087
|
+
|
|
1088
|
+
const {
|
|
1089
|
+
invoke,
|
|
1090
|
+
set
|
|
1091
|
+
} = create(SharedProcess);
|
|
1081
1092
|
|
|
1082
1093
|
const sendMessagePortToAuthProcess = async port => {
|
|
1083
1094
|
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, 'HandleMessagePortForAuthProcess.handleMessagePortForAuthProcess');
|
|
@@ -1087,7 +1098,7 @@ const initializeAuthProcess = async () => {
|
|
|
1087
1098
|
commandMap: {},
|
|
1088
1099
|
send: sendMessagePortToAuthProcess
|
|
1089
1100
|
});
|
|
1090
|
-
set$
|
|
1101
|
+
set$2(rpc);
|
|
1091
1102
|
};
|
|
1092
1103
|
|
|
1093
1104
|
const sendMessagePortToOpenerWorker = async port => {
|
|
@@ -1098,7 +1109,7 @@ const initializeOpenerWorker = async () => {
|
|
|
1098
1109
|
commandMap: {},
|
|
1099
1110
|
send: sendMessagePortToOpenerWorker
|
|
1100
1111
|
});
|
|
1101
|
-
set(rpc);
|
|
1112
|
+
set$1(rpc);
|
|
1102
1113
|
};
|
|
1103
1114
|
|
|
1104
1115
|
const millisecondsPerSecond = 1000;
|
|
@@ -1116,19 +1127,42 @@ const isAccessTokenValid = (accessToken, expiresAt, now = Date.now()) => {
|
|
|
1116
1127
|
return Number.isFinite(expiresAtNumber) && expiresAtNumber > now;
|
|
1117
1128
|
};
|
|
1118
1129
|
|
|
1119
|
-
const state$
|
|
1130
|
+
const state$3 = {
|
|
1120
1131
|
backendUrl: ''
|
|
1121
1132
|
};
|
|
1122
1133
|
const getAuthBackendUrl = () => {
|
|
1123
|
-
return state$
|
|
1134
|
+
return state$3.backendUrl;
|
|
1124
1135
|
};
|
|
1125
1136
|
const setAuthBackendUrl = backendUrl => {
|
|
1126
|
-
state$
|
|
1137
|
+
state$3.backendUrl = backendUrl;
|
|
1138
|
+
};
|
|
1139
|
+
|
|
1140
|
+
const state$2 = {
|
|
1141
|
+
platform: Web
|
|
1142
|
+
};
|
|
1143
|
+
const getAuthPlatform = () => {
|
|
1144
|
+
return state$2.platform;
|
|
1145
|
+
};
|
|
1146
|
+
const setAuthPlatform = value => {
|
|
1147
|
+
state$2.platform = value;
|
|
1148
|
+
};
|
|
1149
|
+
|
|
1150
|
+
const authStorageId = 'lvce-editor.auth';
|
|
1151
|
+
const deleteSecret = async key => {
|
|
1152
|
+
await invoke('SecretStorage.delete', authStorageId, key);
|
|
1153
|
+
};
|
|
1154
|
+
const getSecret = async key => {
|
|
1155
|
+
const value = await invoke('SecretStorage.get', authStorageId, key);
|
|
1156
|
+
return typeof value === 'string' ? value : '';
|
|
1157
|
+
};
|
|
1158
|
+
const storeSecret = async (key, value) => {
|
|
1159
|
+
await invoke('SecretStorage.store', authStorageId, key, value);
|
|
1127
1160
|
};
|
|
1128
1161
|
|
|
1129
1162
|
const databaseName = 'auth-worker';
|
|
1130
1163
|
const objectStoreName = 'auth';
|
|
1131
1164
|
const memoryStorage = new Map();
|
|
1165
|
+
const secretKeys = new Set(['accessToken', 'refreshToken']);
|
|
1132
1166
|
const state$1 = {
|
|
1133
1167
|
databasePromise: undefined
|
|
1134
1168
|
};
|
|
@@ -1183,7 +1217,7 @@ const getDatabase = async () => {
|
|
|
1183
1217
|
}
|
|
1184
1218
|
return state$1.databasePromise;
|
|
1185
1219
|
};
|
|
1186
|
-
const
|
|
1220
|
+
const getIndexedDbValue = async key => {
|
|
1187
1221
|
const database = await getDatabase();
|
|
1188
1222
|
if (!database) {
|
|
1189
1223
|
return memoryStorage.get(key) ?? '';
|
|
@@ -1193,7 +1227,7 @@ const getPersistentAuthValue = async key => {
|
|
|
1193
1227
|
const value = await requestToPromise(objectStore.get(key));
|
|
1194
1228
|
return typeof value === 'string' ? value : '';
|
|
1195
1229
|
};
|
|
1196
|
-
const
|
|
1230
|
+
const setIndexedDbValue = async (key, value) => {
|
|
1197
1231
|
memoryStorage.set(key, value);
|
|
1198
1232
|
const database = await getDatabase();
|
|
1199
1233
|
if (!database) {
|
|
@@ -1204,7 +1238,7 @@ const setPersistentAuthValue = async (key, value) => {
|
|
|
1204
1238
|
objectStore.put(value, key);
|
|
1205
1239
|
await transactionToPromise(transaction);
|
|
1206
1240
|
};
|
|
1207
|
-
const
|
|
1241
|
+
const clearIndexedDbValue = async key => {
|
|
1208
1242
|
memoryStorage.delete(key);
|
|
1209
1243
|
const database = await getDatabase();
|
|
1210
1244
|
if (!database) {
|
|
@@ -1215,6 +1249,44 @@ const clearPersistentAuthValue = async key => {
|
|
|
1215
1249
|
objectStore.delete(key);
|
|
1216
1250
|
await transactionToPromise(transaction);
|
|
1217
1251
|
};
|
|
1252
|
+
const shouldUseSecretStorage = key => {
|
|
1253
|
+
return getAuthPlatform() === Electron && secretKeys.has(key);
|
|
1254
|
+
};
|
|
1255
|
+
const getPersistentAuthValue = async key => {
|
|
1256
|
+
if (!shouldUseSecretStorage(key)) {
|
|
1257
|
+
return getIndexedDbValue(key);
|
|
1258
|
+
}
|
|
1259
|
+
const secret = await getSecret(key);
|
|
1260
|
+
if (secret) {
|
|
1261
|
+
return secret;
|
|
1262
|
+
}
|
|
1263
|
+
const legacyValue = await getIndexedDbValue(key);
|
|
1264
|
+
if (!legacyValue) {
|
|
1265
|
+
return '';
|
|
1266
|
+
}
|
|
1267
|
+
await storeSecret(key, legacyValue);
|
|
1268
|
+
await clearIndexedDbValue(key);
|
|
1269
|
+
return legacyValue;
|
|
1270
|
+
};
|
|
1271
|
+
const setPersistentAuthValue = async (key, value) => {
|
|
1272
|
+
if (!shouldUseSecretStorage(key)) {
|
|
1273
|
+
await setIndexedDbValue(key, value);
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1276
|
+
if (value) {
|
|
1277
|
+
await storeSecret(key, value);
|
|
1278
|
+
} else {
|
|
1279
|
+
await deleteSecret(key);
|
|
1280
|
+
}
|
|
1281
|
+
await clearIndexedDbValue(key);
|
|
1282
|
+
};
|
|
1283
|
+
const clearPersistentAuthValue = async key => {
|
|
1284
|
+
if (shouldUseSecretStorage(key)) {
|
|
1285
|
+
await Promise.all([deleteSecret(key), clearIndexedDbValue(key)]);
|
|
1286
|
+
return;
|
|
1287
|
+
}
|
|
1288
|
+
await clearIndexedDbValue(key);
|
|
1289
|
+
};
|
|
1218
1290
|
|
|
1219
1291
|
const callbackUrlKey = 'oidcCallbackUrl';
|
|
1220
1292
|
const clientIdKey = 'oidcClientId';
|
|
@@ -2114,7 +2186,7 @@ const handleMessagePort = async (port, rpcId) => {
|
|
|
2114
2186
|
messagePort: port
|
|
2115
2187
|
});
|
|
2116
2188
|
if (rpcId) {
|
|
2117
|
-
set$
|
|
2189
|
+
set$3(rpcId, rpc);
|
|
2118
2190
|
}
|
|
2119
2191
|
};
|
|
2120
2192
|
|
|
@@ -2148,7 +2220,7 @@ const exchangeAuthorizationCode = async (backendUrl, clientId, code, redirectUri
|
|
|
2148
2220
|
|
|
2149
2221
|
const getCurrentHref = async () => {
|
|
2150
2222
|
try {
|
|
2151
|
-
return await invoke('Layout.getHref');
|
|
2223
|
+
return await invoke$1('Layout.getHref');
|
|
2152
2224
|
} catch {
|
|
2153
2225
|
// ignore
|
|
2154
2226
|
}
|
|
@@ -2378,9 +2450,13 @@ const getBackendUrl = options => {
|
|
|
2378
2450
|
}
|
|
2379
2451
|
return options.backendUrl || '';
|
|
2380
2452
|
};
|
|
2453
|
+
const getPlatform = options => {
|
|
2454
|
+
return typeof options === 'number' ? options : options.platform ?? Web;
|
|
2455
|
+
};
|
|
2381
2456
|
const initialize = async options => {
|
|
2382
2457
|
const backendUrl = getBackendUrl(options);
|
|
2383
2458
|
setAuthBackendUrl(backendUrl);
|
|
2459
|
+
setAuthPlatform(getPlatform(options));
|
|
2384
2460
|
try {
|
|
2385
2461
|
if (backendUrl) {
|
|
2386
2462
|
const completedBrowserLogin = await completeBrowserOidcLogin(backendUrl);
|
|
@@ -2854,7 +2930,7 @@ const errorHtml = `<!doctype html>
|
|
|
2854
2930
|
</html>`;
|
|
2855
2931
|
|
|
2856
2932
|
const getElectronRedirectUri = async uid => {
|
|
2857
|
-
const localOauthServerPort = await invoke$
|
|
2933
|
+
const localOauthServerPort = await invoke$3('OAuthServer.create', String(uid), successHtml, errorHtml);
|
|
2858
2934
|
return `http://localhost:${localOauthServerPort}/callback`;
|
|
2859
2935
|
};
|
|
2860
2936
|
|
|
@@ -2957,7 +3033,7 @@ const hasAuthorizationCode = value => {
|
|
|
2957
3033
|
return typeof value === 'string' && value.length > 0;
|
|
2958
3034
|
};
|
|
2959
3035
|
const getElectronAuthorizationCode = async uid => {
|
|
2960
|
-
return invoke$
|
|
3036
|
+
return invoke$3('OAuthServer.getCode', String(uid));
|
|
2961
3037
|
};
|
|
2962
3038
|
const waitForElectronBackendLogin = async (backendUrl, uid, redirectUri, codeVerifier, timeoutMs = 30_000, pollIntervalMs = 1000, getAuthorizationCode = getElectronAuthorizationCode, exchangeAuthorizationCode = exchangeElectronAuthorizationCode) => {
|
|
2963
3039
|
const deadline = Date.now() + timeoutMs;
|
|
@@ -3018,7 +3094,7 @@ const getInteractiveLoginResult = async (backendUrl, platform, signingInState) =
|
|
|
3018
3094
|
state
|
|
3019
3095
|
});
|
|
3020
3096
|
}
|
|
3021
|
-
await invoke$
|
|
3097
|
+
await invoke$2('Open.openUrl', loginUrl, platform, authUseRedirect);
|
|
3022
3098
|
if (platform !== Electron && authUseRedirect) {
|
|
3023
3099
|
return signingInState;
|
|
3024
3100
|
}
|
|
@@ -3036,6 +3112,7 @@ const handleClickLogin = async options => {
|
|
|
3036
3112
|
backendUrl,
|
|
3037
3113
|
platform
|
|
3038
3114
|
} = options;
|
|
3115
|
+
setAuthPlatform(platform);
|
|
3039
3116
|
if (!backendUrl) {
|
|
3040
3117
|
return {
|
|
3041
3118
|
authErrorMessage: 'Backend URL is missing.',
|
|
@@ -3098,8 +3175,19 @@ const initializeRendererWorker = async () => {
|
|
|
3098
3175
|
});
|
|
3099
3176
|
};
|
|
3100
3177
|
|
|
3178
|
+
const sendMessagePortToSharedProcess = async port => {
|
|
3179
|
+
await sendMessagePortToSharedProcess$1(port);
|
|
3180
|
+
};
|
|
3181
|
+
const initializeSharedProcess = async () => {
|
|
3182
|
+
const rpc = await create$2({
|
|
3183
|
+
commandMap: {},
|
|
3184
|
+
send: sendMessagePortToSharedProcess
|
|
3185
|
+
});
|
|
3186
|
+
set(rpc);
|
|
3187
|
+
};
|
|
3188
|
+
|
|
3101
3189
|
const listen = async () => {
|
|
3102
|
-
await Promise.all([initializeRendererWorker(), initializeOpenerWorker(), initializeAuthProcess()]);
|
|
3190
|
+
await Promise.all([initializeRendererWorker(), initializeOpenerWorker(), initializeAuthProcess(), initializeSharedProcess()]);
|
|
3103
3191
|
};
|
|
3104
3192
|
|
|
3105
3193
|
const main = async () => {
|