mirror of
https://github.com/dbgate/dbgate
synced 2024-11-09 21:26:30 +00:00
This commit is contained in:
parent
fb2e261a08
commit
97aa563fe7
@ -252,6 +252,7 @@ module.exports = {
|
||||
accessToken,
|
||||
passwordMode: undefined,
|
||||
unsaved: true,
|
||||
useRedirectDbLogin: false,
|
||||
};
|
||||
if (old.passwordMode == 'askUser') {
|
||||
res.user = user;
|
||||
@ -395,12 +396,18 @@ module.exports = {
|
||||
},
|
||||
|
||||
dbloginToken_meta: true,
|
||||
async dbloginToken({ code, conid, redirectUri }) {
|
||||
const connection = await this.getCore({ conid });
|
||||
const driver = requireEngineDriver(connection);
|
||||
const accessToken = await driver.getAuthTokenFromCode(connection, { code, redirectUri });
|
||||
const volatile = await this.saveVolatile({ conid, accessToken });
|
||||
// console.log('******************************** WE HAVE ACCESS TOKEN', accessToken);
|
||||
socket.emit('got-volatile-token', { savedConId: conid, volatileConId: volatile._id });
|
||||
async dbloginToken({ code, conid, strmid, redirectUri }) {
|
||||
try {
|
||||
const connection = await this.getCore({ conid });
|
||||
const driver = requireEngineDriver(connection);
|
||||
const accessToken = await driver.getAuthTokenFromCode(connection, { code, redirectUri });
|
||||
const volatile = await this.saveVolatile({ conid, accessToken });
|
||||
// console.log('******************************** WE HAVE ACCESS TOKEN', accessToken);
|
||||
socket.emit('got-volatile-token', { strmid, savedConId: conid, volatileConId: volatile._id });
|
||||
return { success: true };
|
||||
} catch (err) {
|
||||
logger.error({ err }, 'Error getting DB token');
|
||||
return { error: err.message };
|
||||
}
|
||||
},
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ async function handleRefresh() {
|
||||
const databases = await driver.listDatabases(systemConnection);
|
||||
setStatusName('ok');
|
||||
const databasesString = stableStringify(databases);
|
||||
console.log('************* DATABASES *************', databases);
|
||||
if (lastDatabases != databasesString) {
|
||||
process.send({ msgtype: 'databases', databases });
|
||||
lastDatabases = databasesString;
|
||||
@ -59,8 +60,11 @@ async function handleConnect(connection) {
|
||||
|
||||
const driver = requireEngineDriver(storedConnection);
|
||||
try {
|
||||
console.log('************* CONNECTING *************');
|
||||
systemConnection = await connectUtility(driver, storedConnection, 'app');
|
||||
console.log('************* VERSION *************');
|
||||
readVersion();
|
||||
console.log('************* REFRESH *************');
|
||||
handleRefresh();
|
||||
if (extractBoolSettingsValue(globalSettings, 'connection.autoRefresh', false)) {
|
||||
setInterval(
|
||||
|
@ -31,6 +31,9 @@ module.exports = {
|
||||
electronSender.send(message, data == null ? null : data);
|
||||
}
|
||||
for (const strmid in sseResponses) {
|
||||
if (data?.strmid && data?.strmid != strmid) {
|
||||
continue;
|
||||
}
|
||||
let skipThisStream = false;
|
||||
if (sseResponses[strmid].filter) {
|
||||
for (const key in sseResponses[strmid].filter) {
|
||||
@ -47,7 +50,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
sseResponses[strmid].response?.write(
|
||||
`event: ${message}\ndata: ${stableStringify(data == null ? null : data)}\n\n`
|
||||
`event: ${message}\ndata: ${stableStringify(data == null ? null : _.omit(data, ['strmid']))}\n\n`
|
||||
);
|
||||
}
|
||||
},
|
||||
|
@ -6,6 +6,9 @@
|
||||
|
||||
const config = useConfig();
|
||||
|
||||
const params = new URLSearchParams(location.search);
|
||||
const error = params.get('error');
|
||||
|
||||
onMount(() => {
|
||||
const removed = document.getElementById('starting_dbgate_zero');
|
||||
if (removed) removed.remove();
|
||||
@ -21,7 +24,11 @@
|
||||
<div class="box">
|
||||
<div class="heading">Configuration error</div>
|
||||
{#if !$config?.isLicenseValid}
|
||||
<ErrorInfo message={`Invalid license. Please contact sales@dbgate.eu for more details. ${$config?.licenseError}`} />
|
||||
<ErrorInfo
|
||||
message={`Invalid license. Please contact sales@dbgate.eu for more details. ${$config?.licenseError}`}
|
||||
/>
|
||||
{:else if error}
|
||||
<ErrorInfo message={error} />
|
||||
{:else}
|
||||
<ErrorInfo message="No error found, try to open app again" />
|
||||
<div class="m-2">
|
||||
|
@ -10,6 +10,7 @@
|
||||
export let passProps;
|
||||
|
||||
$: databases = useDatabaseList({ conid: data._id });
|
||||
console.log('USED DATABASE LIST', data._id);
|
||||
</script>
|
||||
|
||||
<AppObjectList
|
||||
|
@ -47,26 +47,22 @@ export function handleOauthCallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
console.log('****************** IS DB LOGIN TEST');
|
||||
if (isDbLoginCallback()) {
|
||||
console.log('****************** IS DB LOGIN TRUE');
|
||||
const conid = localStorage.getItem('dbloginState').split('@')[1];
|
||||
const [_prefix, strmid, conid] = localStorage.getItem('dbloginState').split(':');
|
||||
localStorage.removeItem('dbloginState');
|
||||
|
||||
apiCall('connections/dblogin-token', {
|
||||
code: sentCode,
|
||||
conid,
|
||||
strmid,
|
||||
redirectUri: location.origin + location.pathname,
|
||||
}).then(authResp => {
|
||||
const { accessToken, error, errorMessage } = authResp;
|
||||
|
||||
if (accessToken) {
|
||||
console.log('Settings access token from OAUTH');
|
||||
localStorage.setItem('accessToken', accessToken);
|
||||
internalRedirectTo('/');
|
||||
if (authResp.success) {
|
||||
window.close();
|
||||
} else if (authResp.error) {
|
||||
internalRedirectTo(`?page=error&error=${encodeURIComponent(authResp)}`);
|
||||
} else {
|
||||
console.log('Error when processing OAUTH callback', error || errorMessage);
|
||||
internalRedirectTo(`?page=not-logged&error=${error || errorMessage}`);
|
||||
internalRedirectTo(`?page=error`);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -10,9 +10,10 @@ import DatabaseLoginModal, { isDatabaseLoginVisible } from '../modals/DatabaseLo
|
||||
import _ from 'lodash';
|
||||
import uuidv1 from 'uuid/v1';
|
||||
import { openWebLink } from './exportFileTools';
|
||||
import { callServerPing } from './connectionsPinger';
|
||||
import { batchDispatchCacheTriggers, dispatchCacheChange } from './cache';
|
||||
|
||||
export const strmid = uuidv1();
|
||||
const privateApiState = Math.random().toString().substr(2);
|
||||
|
||||
let eventSource;
|
||||
let apiLogging = false;
|
||||
@ -66,7 +67,7 @@ function processApiResponse(route, args, resp) {
|
||||
|
||||
if (resp?.missingCredentials) {
|
||||
if (resp.detail.redirectToDbLogin) {
|
||||
const state = `dbg-dblogin:${privateApiState}@${resp.detail.conid}`;
|
||||
const state = `dbg-dblogin:${strmid}:${resp.detail.conid}`;
|
||||
localStorage.setItem('dbloginState', state);
|
||||
openWebLink(
|
||||
`connections/dblogin?conid=${resp.detail.conid}&state=${encodeURIComponent(state)}&redirectUri=${
|
||||
@ -224,8 +225,12 @@ export function getVolatileConnections() {
|
||||
}
|
||||
|
||||
export function installNewVolatileConnectionListener() {
|
||||
apiOn('got-volatile-token', ({ savedConId, volatileConId }) => {
|
||||
apiOn('got-volatile-token', async ({ savedConId, volatileConId }) => {
|
||||
console.log('************************** GOT VOLASTILE TOKEN', savedConId, volatileConId);
|
||||
setVolatileConnectionRemapping(savedConId, volatileConId);
|
||||
await callServerPing();
|
||||
dispatchCacheChange({ key: `server-status-changed` });
|
||||
batchDispatchCacheTriggers(x => x.conid == savedConId);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
import _ from 'lodash';
|
||||
import { openedConnections, currentDatabase, openedConnectionsWithTemporary, getCurrentConfig, getOpenedConnections } from '../stores';
|
||||
import { currentDatabase, openedConnectionsWithTemporary, getCurrentConfig, getOpenedConnections } from '../stores';
|
||||
import { apiCall, getVolatileConnections, strmid } from './api';
|
||||
import { getConnectionList } from './metadataLoaders';
|
||||
import hasPermission from '../utility/hasPermission';
|
||||
|
||||
// const doServerPing = async value => {
|
||||
|
@ -2,6 +2,7 @@ const _ = require('lodash');
|
||||
const stream = require('stream');
|
||||
const tedious = require('tedious');
|
||||
const makeUniqueColumnNames = require('./makeUniqueColumnNames');
|
||||
const { getAzureAuthOptions } = require('./azureAuth');
|
||||
|
||||
function extractTediousColumns(columns, addDriverNativeColumn = false) {
|
||||
const res = columns.map(col => {
|
||||
@ -22,10 +23,11 @@ function extractTediousColumns(columns, addDriverNativeColumn = false) {
|
||||
return res;
|
||||
}
|
||||
|
||||
async function tediousConnect({ server, port, user, password, database, ssl, trustServerCertificate, windowsDomain }) {
|
||||
async function tediousConnect(storedConnection) {
|
||||
const { server, port, user, password, database, ssl, trustServerCertificate, windowsDomain, authType } = storedConnection;
|
||||
return new Promise((resolve, reject) => {
|
||||
const connectionOptions = {
|
||||
encrypt: !!ssl,
|
||||
encrypt: !!ssl || authType == 'msentra',
|
||||
cryptoCredentialsDetails: ssl ? _.pick(ssl, ['ca', 'cert', 'key']) : undefined,
|
||||
trustServerCertificate: ssl ? (!ssl.ca && !ssl.cert && !ssl.key ? true : ssl.rejectUnauthorized) : undefined,
|
||||
enableArithAbort: true,
|
||||
@ -40,18 +42,21 @@ async function tediousConnect({ server, port, user, password, database, ssl, tru
|
||||
connectionOptions.database = database;
|
||||
}
|
||||
|
||||
const authentication =
|
||||
authType == 'msentra'
|
||||
? getAzureAuthOptions(storedConnection)
|
||||
: {
|
||||
type: windowsDomain ? 'ntlm' : 'default',
|
||||
options: {
|
||||
userName: user,
|
||||
password: password,
|
||||
...(windowsDomain ? { domain: windowsDomain } : {}),
|
||||
},
|
||||
};
|
||||
|
||||
const connection = new tedious.Connection({
|
||||
server,
|
||||
|
||||
authentication: {
|
||||
type: windowsDomain ? 'ntlm' : 'default',
|
||||
options: {
|
||||
userName: user,
|
||||
password: password,
|
||||
...(windowsDomain ? { domain: windowsDomain } : {}),
|
||||
},
|
||||
},
|
||||
|
||||
authentication,
|
||||
options: connectionOptions,
|
||||
});
|
||||
connection.on('connect', function (err) {
|
||||
|
Loading…
Reference in New Issue
Block a user