@lvce-editor/auth-worker 3.19.0 → 3.21.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/README.md CHANGED
@@ -1,3 +1,7 @@
1
1
  # Auth Worker
2
2
 
3
3
  WebWorker for the Auth functionality in Lvce Editor.
4
+
5
+ ## Cloudflare account connections
6
+
7
+ `Auth.getCloudflareConnectionsUrl` returns `/cloudflare` on the configured authentication backend. `Auth.getCloudflareStatus`, `Auth.getCloudflareZones`, and `Auth.approveCloudflareMachine(id, code, zoneId)` use the current LVCE access token. Cloudflare OAuth credentials stay in backend-2. Signed-out requests fail locally. The backend needs a separately registered Cloudflare OAuth client; see [deployment setup](https://github.com/lvce-editor/backend-2/blob/main/docs/cloudflare.md).
@@ -3055,7 +3055,7 @@ const getEffectiveRedirectUri = async (platform, uid, redirectUri) => {
3055
3055
 
3056
3056
  const nativeOidcClientId = 'lvce-editor-native';
3057
3057
  const webOidcClientId = 'lvce-editor-web';
3058
- const oidcScope = 'openid offline_access profile email';
3058
+ const oidcScope = 'openid offline_access profile email user remote';
3059
3059
  const getOidcClientId = platform => {
3060
3060
  return platform === Electron ? nativeOidcClientId : webOidcClientId;
3061
3061
  };
@@ -3523,6 +3523,42 @@ const syncBackendAuth = async backendUrl => initialize({
3523
3523
  backendUrl
3524
3524
  });
3525
3525
 
3526
+ const identifier = /^[a-f0-9]{32}$/;
3527
+ const confirmationCode = /^[A-F0-9]{8}$/;
3528
+ const getCloudflareConnectionsUrl = () => new URL('/cloudflare', getAuthBackendUrl()).href;
3529
+ const request = async (pathname, method = 'GET', body) => {
3530
+ const backendUrl = getAuthBackendUrl();
3531
+ const accessToken = await getAccessToken({
3532
+ refresh: 'if-needed'
3533
+ });
3534
+ if (backendUrl !== getAuthBackendUrl()) throw new Error('Account backend changed. Retry Cloudflare setup.');
3535
+ if (!accessToken) throw new Error('Sign in to LVCE to manage Cloudflare connections.');
3536
+ const response = await fetch(new URL(pathname, backendUrl), {
3537
+ headers: {
3538
+ Accept: 'application/json',
3539
+ Authorization: `Bearer ${accessToken}`,
3540
+ 'Content-Type': 'application/json'
3541
+ },
3542
+ method,
3543
+ redirect: 'error',
3544
+ signal: AbortSignal.timeout(30_000),
3545
+ ...(body !== undefined && {
3546
+ body: JSON.stringify(body)
3547
+ })
3548
+ });
3549
+ if (!response.ok) throw new Error(`Cloudflare connection request failed (${response.status}). Open account connections to check authorization and domains.`);
3550
+ return response.json();
3551
+ };
3552
+ const getCloudflareStatus = () => request('/cloudflare/status');
3553
+ const getCloudflareZones = () => request('/cloudflare/zones');
3554
+ const approveCloudflareMachine = (id, code, zoneId) => {
3555
+ if (!identifier.test(id) || !identifier.test(zoneId) || !confirmationCode.test(code)) throw new Error('Invalid Cloudflare setup code or domain.');
3556
+ return request(`/cloudflare/setup/${id}/approve`, 'POST', {
3557
+ code,
3558
+ zoneId
3559
+ });
3560
+ };
3561
+
3526
3562
  const sendMessagePortToAuthProcess = async port => {
3527
3563
  await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, 'HandleMessagePortForAuthProcess.handleMessagePortForAuthProcess');
3528
3564
  };
@@ -3568,6 +3604,7 @@ const handleMessagePort = async (port, rpcId) => {
3568
3604
  };
3569
3605
 
3570
3606
  const commandMap = {
3607
+ 'Auth.approveCloudflareMachine': approveCloudflareMachine,
3571
3608
  'Auth.clearMocks': clear,
3572
3609
  'Auth.configure': configure,
3573
3610
  'Auth.consumeNextLoginResponse': consumeNextLoginResponse,
@@ -3575,6 +3612,10 @@ const commandMap = {
3575
3612
  'Auth.disconnectConnectedAccount': disconnectConnectedAccount,
3576
3613
  'Auth.getAccessToken': getAccessToken,
3577
3614
  'Auth.getAccounts': getAccounts,
3615
+ 'Auth.getBackendUrl': getAuthBackendUrl,
3616
+ 'Auth.getCloudflareConnectionsUrl': getCloudflareConnectionsUrl,
3617
+ 'Auth.getCloudflareStatus': getCloudflareStatus,
3618
+ 'Auth.getCloudflareZones': getCloudflareZones,
3578
3619
  'Auth.getConnectedAccounts': getConnectedAccounts,
3579
3620
  'Auth.hasPendingMockLoginResponse': hasPendingMockLoginResponse,
3580
3621
  'Auth.hasPendingMockRefreshResponse': hasPendingMockRefreshResponse,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/auth-worker",
3
- "version": "3.19.0",
3
+ "version": "3.21.0",
4
4
  "description": "Auth Worker",
5
5
  "repository": {
6
6
  "type": "git",