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