@lvce-editor/auth-worker 3.13.2 → 3.15.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 +29 -18
- package/package.json +1 -1
package/dist/authWorkerMain.js
CHANGED
|
@@ -1134,21 +1134,6 @@ const initializeOpenerWorker = async () => {
|
|
|
1134
1134
|
set(rpc);
|
|
1135
1135
|
};
|
|
1136
1136
|
|
|
1137
|
-
const millisecondsPerSecond = 1000;
|
|
1138
|
-
const getAccessTokenExpiresAt = (expiresIn, now = Date.now()) => {
|
|
1139
|
-
if (typeof expiresIn !== 'number' || !Number.isFinite(expiresIn) || expiresIn <= 0) {
|
|
1140
|
-
return undefined;
|
|
1141
|
-
}
|
|
1142
|
-
return now + expiresIn * millisecondsPerSecond;
|
|
1143
|
-
};
|
|
1144
|
-
const isAccessTokenValid = (accessToken, expiresAt, now = Date.now()) => {
|
|
1145
|
-
if (!accessToken || !expiresAt) {
|
|
1146
|
-
return false;
|
|
1147
|
-
}
|
|
1148
|
-
const expiresAtNumber = Number(expiresAt);
|
|
1149
|
-
return Number.isFinite(expiresAtNumber) && expiresAtNumber > now;
|
|
1150
|
-
};
|
|
1151
|
-
|
|
1152
1137
|
const state$3 = {
|
|
1153
1138
|
backendUrl: ''
|
|
1154
1139
|
};
|
|
@@ -1169,6 +1154,26 @@ const setAuthPlatform = value => {
|
|
|
1169
1154
|
state$2.platform = value;
|
|
1170
1155
|
};
|
|
1171
1156
|
|
|
1157
|
+
const configure = options => {
|
|
1158
|
+
setAuthBackendUrl(options.backendUrl);
|
|
1159
|
+
setAuthPlatform(options.platform);
|
|
1160
|
+
};
|
|
1161
|
+
|
|
1162
|
+
const millisecondsPerSecond = 1000;
|
|
1163
|
+
const getAccessTokenExpiresAt = (expiresIn, now = Date.now()) => {
|
|
1164
|
+
if (typeof expiresIn !== 'number' || !Number.isFinite(expiresIn) || expiresIn <= 0) {
|
|
1165
|
+
return undefined;
|
|
1166
|
+
}
|
|
1167
|
+
return now + expiresIn * millisecondsPerSecond;
|
|
1168
|
+
};
|
|
1169
|
+
const isAccessTokenValid = (accessToken, expiresAt, now = Date.now()) => {
|
|
1170
|
+
if (!accessToken || !expiresAt) {
|
|
1171
|
+
return false;
|
|
1172
|
+
}
|
|
1173
|
+
const expiresAtNumber = Number(expiresAt);
|
|
1174
|
+
return Number.isFinite(expiresAtNumber) && expiresAtNumber > now;
|
|
1175
|
+
};
|
|
1176
|
+
|
|
1172
1177
|
const authStorageId = 'lvce-editor.auth';
|
|
1173
1178
|
const deleteSecret = async key => {
|
|
1174
1179
|
await deleteSecret$1(authStorageId, key);
|
|
@@ -2186,12 +2191,15 @@ const refreshOidcTokens = async (backendUrl, clientId, refreshToken, requestToke
|
|
|
2186
2191
|
|
|
2187
2192
|
const getAccessToken = async (options = {}, refreshTokens = refreshOidcTokens, now = Date.now()) => {
|
|
2188
2193
|
const [accessToken, accessTokenExpiresAt] = await Promise.all([getPersistentAuthValue('accessToken'), getPersistentAuthValue('accessTokenExpiresAt')]);
|
|
2189
|
-
if (options.refresh
|
|
2194
|
+
if (!options.refresh || options.refresh === 'if-needed' && isAccessTokenValid(accessToken, accessTokenExpiresAt, now)) {
|
|
2190
2195
|
return accessToken;
|
|
2191
2196
|
}
|
|
2192
2197
|
const [clientId, refreshToken] = await Promise.all([getStoredOidcClientId(), getPersistentAuthValue('refreshToken')]);
|
|
2193
2198
|
const backendUrl = getAuthBackendUrl();
|
|
2194
2199
|
if (!backendUrl || !clientId || !refreshToken) {
|
|
2200
|
+
if (options.refresh === 'always') {
|
|
2201
|
+
return '';
|
|
2202
|
+
}
|
|
2195
2203
|
const expiresAt = Number(accessTokenExpiresAt);
|
|
2196
2204
|
return accessTokenExpiresAt && Number.isFinite(expiresAt) && expiresAt <= now ? '' : accessToken;
|
|
2197
2205
|
}
|
|
@@ -2477,8 +2485,10 @@ const getPlatform = options => {
|
|
|
2477
2485
|
};
|
|
2478
2486
|
const initialize = async options => {
|
|
2479
2487
|
const backendUrl = getBackendUrl(options);
|
|
2480
|
-
|
|
2481
|
-
|
|
2488
|
+
configure({
|
|
2489
|
+
backendUrl,
|
|
2490
|
+
platform: getPlatform(options)
|
|
2491
|
+
});
|
|
2482
2492
|
try {
|
|
2483
2493
|
if (backendUrl) {
|
|
2484
2494
|
const completedBrowserLogin = await completeBrowserOidcLogin(backendUrl);
|
|
@@ -3178,6 +3188,7 @@ const logout = async state => {
|
|
|
3178
3188
|
|
|
3179
3189
|
const commandMap = {
|
|
3180
3190
|
'Auth.clearMocks': clear,
|
|
3191
|
+
'Auth.configure': configure,
|
|
3181
3192
|
'Auth.consumeNextLoginResponse': consumeNextLoginResponse,
|
|
3182
3193
|
'Auth.consumeNextRefreshResponse': consumeNextRefreshResponse,
|
|
3183
3194
|
'Auth.getAccessToken': getAccessToken,
|