diff --git a/app/cloud/server/functions/connectWorkspace.js b/app/cloud/server/functions/connectWorkspace.js index 5ec79dbdb7e5..7f62a8b8b9c2 100644 --- a/app/cloud/server/functions/connectWorkspace.js +++ b/app/cloud/server/functions/connectWorkspace.js @@ -51,6 +51,7 @@ export function connectWorkspace(token) { Settings.updateValueById('Cloud_Workspace_Client_Id', data.client_id); Settings.updateValueById('Cloud_Workspace_Client_Secret', data.client_secret); Settings.updateValueById('Cloud_Workspace_Client_Secret_Expires_At', data.client_secret_expires_at); + Settings.updateValueById('Cloud_Workspace_PublicKey', data.publicKey); Settings.updateValueById('Cloud_Workspace_Registration_Client_Uri', data.registration_client_uri); // Now that we have the client id and secret, let's get the access token diff --git a/app/cloud/server/functions/getWorkspaceKey.js b/app/cloud/server/functions/getWorkspaceKey.js new file mode 100644 index 000000000000..912163ee02e5 --- /dev/null +++ b/app/cloud/server/functions/getWorkspaceKey.js @@ -0,0 +1,18 @@ +import { retrieveRegistrationStatus } from './retrieveRegistrationStatus'; +import { settings } from '../../../settings'; + +export function getWorkspaceKey() { + const { connectToCloud, workspaceRegistered } = retrieveRegistrationStatus(); + + if (!connectToCloud || !workspaceRegistered) { + return false; + } + + const publicKey = settings.get('Cloud_Workspace_PublicKey'); + + if (!publicKey) { + return false; + } + + return publicKey; +} diff --git a/app/cloud/server/functions/syncWorkspace.js b/app/cloud/server/functions/syncWorkspace.js index 93f1cddbc134..57f9645f8357 100644 --- a/app/cloud/server/functions/syncWorkspace.js +++ b/app/cloud/server/functions/syncWorkspace.js @@ -5,6 +5,7 @@ import { retrieveRegistrationStatus } from './retrieveRegistrationStatus'; import { getWorkspaceAccessToken } from './getWorkspaceAccessToken'; import { getWorkspaceLicense } from './getWorkspaceLicense'; import { statistics } from '../../../statistics'; +import { Settings } from '../../../models'; import { settings } from '../../../settings'; export function syncWorkspace(reconnectCheck = false) { @@ -31,6 +32,7 @@ export function syncWorkspace(reconnectCheck = false) { const workspaceUrl = settings.get('Cloud_Workspace_Registration_Client_Uri'); + let result; try { const headers = {}; const token = getWorkspaceAccessToken(true); @@ -41,7 +43,7 @@ export function syncWorkspace(reconnectCheck = false) { return false; } - HTTP.post(`${ workspaceUrl }/client`, { + result = HTTP.post(`${ workspaceUrl }/client`, { data: info, headers, }); @@ -57,5 +59,11 @@ export function syncWorkspace(reconnectCheck = false) { return false; } + const { data } = result; + + if (data.publicKey) { + Settings.updateValueById('Cloud_Workspace_PublicKey', data.publicKey); + } + return true; } diff --git a/app/cloud/server/functions/unregisterWorkspace.js b/app/cloud/server/functions/unregisterWorkspace.js index a1102b1505d0..761932b0a34f 100644 --- a/app/cloud/server/functions/unregisterWorkspace.js +++ b/app/cloud/server/functions/unregisterWorkspace.js @@ -13,6 +13,7 @@ export function unregisterWorkspace() { Settings.updateValueById('Cloud_Workspace_Client_Id', null); Settings.updateValueById('Cloud_Workspace_Client_Secret', null); Settings.updateValueById('Cloud_Workspace_Client_Secret_Expires_At', null); + Settings.updateValueById('Cloud_Workspace_PublicKey', null); Settings.updateValueById('Cloud_Workspace_Registration_Client_Uri', null); return true; diff --git a/app/cloud/server/index.js b/app/cloud/server/index.js index 4a2e16941c00..3045794d7f5b 100644 --- a/app/cloud/server/index.js +++ b/app/cloud/server/index.js @@ -2,6 +2,7 @@ import './methods'; import { getWorkspaceAccessToken } from './functions/getWorkspaceAccessToken'; import { getWorkspaceLicense } from './functions/getWorkspaceLicense'; import { getUserCloudAccessToken } from './functions/getUserCloudAccessToken'; +import { getWorkspaceKey } from './functions/getWorkspaceKey'; import { Permissions } from '../../models'; if (Permissions) { @@ -11,4 +12,4 @@ if (Permissions) { // Ensure the client/workspace access token is valid getWorkspaceAccessToken(); -export { getWorkspaceAccessToken, getWorkspaceLicense, getUserCloudAccessToken }; +export { getWorkspaceAccessToken, getWorkspaceLicense, getWorkspaceKey, getUserCloudAccessToken }; diff --git a/app/lib/server/startup/settings.js b/app/lib/server/startup/settings.js index 9d83ead14338..adf0e1893a22 100644 --- a/app/lib/server/startup/settings.js +++ b/app/lib/server/startup/settings.js @@ -2664,6 +2664,17 @@ settings.addGroup('Setup_Wizard', function() { secret: true, }); + this.add('Cloud_Workspace_PublicKey', '', { + type: 'string', + hidden: true, + readonly: true, + enableQuery: { + _id: 'Register_Server', + value: true, + }, + secret: true, + }); + this.add('Cloud_Workspace_License', '', { type: 'string', hidden: true,