mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 23:45:59 +00:00
SYNC: dbgate cloud redirect workflow
This commit is contained in:
committed by
Diflow
parent
bd88b8411e
commit
eba16cc15d
@@ -514,8 +514,8 @@ describe('Data browser data', () => {
|
||||
cy.themeshot('query-result-chart');
|
||||
});
|
||||
|
||||
// it.only('Private cloud', () => {
|
||||
// cy.testid('WidgetIconPanel_cloudAccount').click();
|
||||
// cy.contains('Sign in with Google').click();
|
||||
// });
|
||||
it.only('Private cloud', () => {
|
||||
cy.testid('WidgetIconPanel_cloudAccount').click();
|
||||
cy.contains('Sign in with Google').click();
|
||||
});
|
||||
});
|
||||
|
||||
1
e2e-tests/env/browse-data/.env
vendored
1
e2e-tests/env/browse-data/.env
vendored
@@ -1,5 +1,6 @@
|
||||
CONNECTIONS=mysql,postgres,mongo,redis
|
||||
ALLOW_DBGATE_PRIVATE_CLOUD=1
|
||||
REDIRECT_TO_DBGATE_CLOUD_LOGIN=1
|
||||
|
||||
LABEL_mysql=MySql-connection
|
||||
SERVER_mysql=localhost
|
||||
|
||||
@@ -2,9 +2,10 @@ DEVMODE=1
|
||||
SHELL_SCRIPTING=1
|
||||
ALLOW_DBGATE_PRIVATE_CLOUD=1
|
||||
DEVWEB=1
|
||||
# REDIRECT_TO_DBGATE_CLOUD_LOGIN=1
|
||||
# PROD_DBGATE_CLOUD=1
|
||||
# PROD_DBGATE_IDENTITY=1
|
||||
LOCAL_DBGATE_CLOUD=1
|
||||
# LOCAL_DBGATE_CLOUD=1
|
||||
# LOCAL_DBGATE_IDENTITY=1
|
||||
|
||||
# CLOUD_UPGRADE_FILE=c:\test\upg\upgrade.zip
|
||||
|
||||
@@ -13,7 +13,7 @@ const {
|
||||
} = require('../auth/authProvider');
|
||||
const storage = require('./storage');
|
||||
const { decryptPasswordString } = require('../utility/crypting');
|
||||
const { createDbGateIdentitySession, startCloudTokenChecking } = require('../utility/cloudIntf');
|
||||
const { createDbGateIdentitySession, startCloudTokenChecking, readCloudTokenHolder } = require('../utility/cloudIntf');
|
||||
const socket = require('../utility/socket');
|
||||
|
||||
const logger = getLogger('auth');
|
||||
@@ -138,8 +138,8 @@ module.exports = {
|
||||
},
|
||||
|
||||
createCloudLoginSession_meta: true,
|
||||
async createCloudLoginSession({ client }) {
|
||||
const res = await createDbGateIdentitySession(client);
|
||||
async createCloudLoginSession({ client, redirectUri }) {
|
||||
const res = await createDbGateIdentitySession(client, redirectUri);
|
||||
startCloudTokenChecking(res.sid, tokenHolder => {
|
||||
socket.emit('got-cloud-token', tokenHolder);
|
||||
socket.emitChanged('cloud-content-changed');
|
||||
@@ -148,5 +148,11 @@ module.exports = {
|
||||
return res;
|
||||
},
|
||||
|
||||
cloudLoginRedirected_meta: true,
|
||||
async cloudLoginRedirected({ sid }) {
|
||||
const tokenHolder = await readCloudTokenHolder(sid);
|
||||
return tokenHolder;
|
||||
},
|
||||
|
||||
authMiddleware,
|
||||
};
|
||||
|
||||
@@ -118,6 +118,7 @@ module.exports = {
|
||||
supportCloudAutoUpgrade: !!process.env.CLOUD_UPGRADE_FILE,
|
||||
allowPrivateCloud: platformInfo.isElectron || !!process.env.ALLOW_DBGATE_PRIVATE_CLOUD,
|
||||
...currentVersion,
|
||||
redirectToDbGateCloudLogin: !!process.env.REDIRECT_TO_DBGATE_CLOUD_LOGIN,
|
||||
};
|
||||
|
||||
return configResult;
|
||||
|
||||
@@ -34,11 +34,12 @@ const DBGATE_CLOUD_URL = process.env.LOCAL_DBGATE_CLOUD
|
||||
? 'https://cloud.dbgate.udolni.net'
|
||||
: 'https://cloud.dbgate.io';
|
||||
|
||||
async function createDbGateIdentitySession(client) {
|
||||
async function createDbGateIdentitySession(client, redirectUri) {
|
||||
const resp = await axios.default.post(
|
||||
`${DBGATE_IDENTITY_URL}/api/create-session`,
|
||||
{
|
||||
client,
|
||||
redirectUri,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
@@ -70,7 +71,7 @@ function startCloudTokenChecking(sid, callback) {
|
||||
});
|
||||
// console.log('CHECK RESP:', resp.data);
|
||||
|
||||
if (resp.data.email) {
|
||||
if (resp.data?.email) {
|
||||
clearInterval(interval);
|
||||
callback(resp.data);
|
||||
}
|
||||
@@ -80,6 +81,18 @@ function startCloudTokenChecking(sid, callback) {
|
||||
}, 500);
|
||||
}
|
||||
|
||||
async function readCloudTokenHolder(sid) {
|
||||
const resp = await axios.default.get(`${DBGATE_IDENTITY_URL}/api/get-token/${sid}`, {
|
||||
headers: {
|
||||
...getLicenseHttpHeaders(),
|
||||
},
|
||||
});
|
||||
if (resp.data?.email) {
|
||||
return resp.data;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function loadCloudFiles() {
|
||||
try {
|
||||
const fileContent = await fs.readFile(path.join(datadir(), 'cloud-files.jsonl'), 'utf-8');
|
||||
@@ -396,4 +409,5 @@ module.exports = {
|
||||
loadCachedCloudConnection,
|
||||
putCloudContent,
|
||||
removeCloudCachedConnection,
|
||||
readCloudTokenHolder,
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@ import { getConfig } from './utility/metadataLoaders';
|
||||
import { isAdminPage } from './utility/pageDefs';
|
||||
import getElectron from './utility/getElectron';
|
||||
import { isProApp } from './utility/proTools';
|
||||
import { cloudSigninTokenHolder, selectedWidget } from './stores';
|
||||
|
||||
export function isOauthCallback() {
|
||||
const params = new URLSearchParams(location.search);
|
||||
@@ -114,6 +115,12 @@ export function handleOauthCallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
const cloudSid = params.get('dbgate-cloud-sid');
|
||||
if (cloudSid) {
|
||||
sessionStorage.setItem('dbgate-cloud-sid', cloudSid);
|
||||
internalRedirectTo(`/`);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -187,6 +194,18 @@ export async function handleAuthOnStartup(config) {
|
||||
}
|
||||
}
|
||||
|
||||
async function checkDbGateCloudLogin() {
|
||||
const sid = sessionStorage.getItem('dbgate-cloud-sid');
|
||||
if (sid) {
|
||||
const tokenHolder = await apiCall('auth/cloud-login-redirected', { sid });
|
||||
if (tokenHolder) {
|
||||
sessionStorage.removeItem('dbgate-cloud-sid');
|
||||
cloudSigninTokenHolder.set(tokenHolder);
|
||||
selectedWidget.set('cloud-private');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (page == 'error') return;
|
||||
if (checkConfigError()) return;
|
||||
|
||||
@@ -199,6 +218,7 @@ export async function handleAuthOnStartup(config) {
|
||||
if (page == 'license' || page == 'admin-license') return;
|
||||
if (checkTrialDaysLeft()) return;
|
||||
if (checkInvalidLicense()) return;
|
||||
checkDbGateCloudLogin();
|
||||
|
||||
// if (config.configurationError) {
|
||||
// internalRedirectTo(`/error.html`);
|
||||
|
||||
@@ -289,8 +289,8 @@ export function installNewVolatileConnectionListener() {
|
||||
}
|
||||
|
||||
export function installNewCloudTokenListener() {
|
||||
// console.log('HOLDER', tokenHolder);
|
||||
apiOn('got-cloud-token', async tokenHolder => {
|
||||
// console.log('HOLDER', tokenHolder);
|
||||
cloudSigninTokenHolder.set(tokenHolder);
|
||||
selectedWidget.set('cloud-private');
|
||||
});
|
||||
|
||||
@@ -135,8 +135,16 @@
|
||||
}
|
||||
|
||||
async function handleOpenCloudLogin() {
|
||||
const { url, sid } = await apiCall('auth/create-cloud-login-session', { client: getElectron() ? 'app' : 'web' });
|
||||
openWebLink(url, true);
|
||||
const useRedirect = getCurrentConfig()?.redirectToDbGateCloudLogin;
|
||||
const { url, sid } = await apiCall('auth/create-cloud-login-session', {
|
||||
client: getElectron() ? 'app' : 'web',
|
||||
redirectUri: useRedirect ? location.origin + location.pathname : undefined,
|
||||
});
|
||||
if (useRedirect) {
|
||||
location.href = url;
|
||||
} else {
|
||||
openWebLink(url, true);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user