diff --git a/packages/api/package.json b/packages/api/package.json index 5f31f4545..f9f11f2f1 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -17,7 +17,6 @@ "dbgate" ], "dependencies": { - "@azure/msal-node": "^2.12.0", "activedirectory2": "^2.1.0", "async-lock": "^1.2.4", "axios": "^0.21.1", diff --git a/packages/api/src/controllers/connections.js b/packages/api/src/controllers/connections.js index 9c262213b..1dd0d6f59 100644 --- a/packages/api/src/controllers/connections.js +++ b/packages/api/src/controllers/connections.js @@ -399,11 +399,11 @@ module.exports = { }, dbloginToken_meta: true, - async dbloginToken({ code, conid, strmid, redirectUri }) { + async dbloginToken({ code, conid, strmid, redirectUri, sid }) { try { const connection = await this.getCore({ conid }); const driver = requireEngineDriver(connection); - const accessToken = await driver.getAuthTokenFromCode(connection, { code, redirectUri }); + const accessToken = await driver.getAuthTokenFromCode(connection, { sid, 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 }); @@ -415,11 +415,11 @@ module.exports = { }, dbloginAuthToken_meta: true, - async dbloginAuthToken({ amoid, code, conid, redirectUri }) { + async dbloginAuthToken({ amoid, code, conid, redirectUri, sid }) { try { const connection = await this.getCore({ conid }); const driver = requireEngineDriver(connection); - const accessToken = await driver.getAuthTokenFromCode(connection, { code, redirectUri }); + const accessToken = await driver.getAuthTokenFromCode(connection, { code, redirectUri, sid }); const volatile = await this.saveVolatile({ conid, accessToken }); const authProvider = getAuthProviderById(amoid); const resp = await authProvider.login(null, null, { conid: volatile._id }); diff --git a/packages/api/src/shell/requirePlugin.js b/packages/api/src/shell/requirePlugin.js index b112cafe3..4bb00c997 100644 --- a/packages/api/src/shell/requirePlugin.js +++ b/packages/api/src/shell/requirePlugin.js @@ -3,7 +3,7 @@ const fs = require('fs'); const { pluginsdir, packagedPluginsDir, getPluginBackendPath } = require('../utility/directories'); const nativeModules = require('../nativeModules'); const platformInfo = require('../utility/platformInfo'); -const azureAuth = require('../utility/azureAuth'); +const authProxy = require('../utility/authProxy'); const { getLogger } = require('dbgate-tools'); const logger = getLogger('requirePlugin'); @@ -13,7 +13,7 @@ const dbgateEnv = { dbgateApi: null, nativeModules, platformInfo, - azureAuth, + authProxy, }; function requirePlugin(packageName, requiredPlugin = null) { if (!packageName) throw new Error('Missing packageName in plugin'); diff --git a/packages/api/src/utility/authProxy.js b/packages/api/src/utility/authProxy.js new file mode 100644 index 000000000..e3043de0b --- /dev/null +++ b/packages/api/src/utility/authProxy.js @@ -0,0 +1,17 @@ +function isAuthProxySupported() { + return false; +} + +async function authProxyGetRedirectUrl(options) { + return null; +} + +async function authProxyGetTokenFromCode(options) { + return null; +} + +module.exports = { + isAuthProxySupported, + authProxyGetRedirectUrl, + authProxyGetTokenFromCode, +}; diff --git a/packages/api/src/utility/azureAuth.js b/packages/api/src/utility/azureAuth.js deleted file mode 100644 index f98cd4a73..000000000 --- a/packages/api/src/utility/azureAuth.js +++ /dev/null @@ -1,17 +0,0 @@ -function isAzureAuthSupported() { - return false; -} - -async function azureGetRedirectAuthUrl(options) { - return null; -} - -async function azureGetAuthTokenFromCode(options) { - return null; -} - -module.exports = { - isAzureAuthSupported, - azureGetRedirectAuthUrl, - azureGetAuthTokenFromCode, -}; diff --git a/packages/web/src/clientAuth.ts b/packages/web/src/clientAuth.ts index 98aae2ff6..dd088ae72 100644 --- a/packages/web/src/clientAuth.ts +++ b/packages/web/src/clientAuth.ts @@ -39,6 +39,7 @@ export function isDbLoginAuthCallback() { export function handleOauthCallback() { const params = new URLSearchParams(location.search); const sentCode = params.get('code'); + const sid = params.get('sid'); if (isOauthCallback()) { const [_prefix, strmid, amoid] = sessionStorage.getItem('oauthState').split(':'); @@ -72,6 +73,7 @@ export function handleOauthCallback() { code: sentCode, conid, strmid, + sid, redirectUri: location.origin + location.pathname, }).then(authResp => { if (authResp.success) { @@ -95,6 +97,7 @@ export function handleOauthCallback() { conid, redirectUri: location.origin + location.pathname, amoid, + sid, }).then(authResp => { if (authResp.accessToken) { localStorage.setItem('accessToken', authResp.accessToken); diff --git a/plugins/dbgate-plugin-mssql/src/backend/driver.js b/plugins/dbgate-plugin-mssql/src/backend/driver.js index 3aa38f8a7..0f2ed5237 100644 --- a/plugins/dbgate-plugin-mssql/src/backend/driver.js +++ b/plugins/dbgate-plugin-mssql/src/backend/driver.js @@ -12,7 +12,7 @@ const { nativeConnect, nativeQueryCore, nativeReadQuery, nativeStream } = native let requireMsnodesqlv8; let platformInfo; -let azureAuth; +let authProxy; const versionQuery = ` SELECT @@ -58,7 +58,7 @@ const driver = { const res = []; if (requireMsnodesqlv8) res.push(...windowsAuthTypes); - if (azureAuth.isAzureAuthSupported()) { + if (authProxy.isAuthProxySupported()) { res.push( { title: 'NodeJs portable driver (tedious) - recomended', @@ -139,10 +139,13 @@ const driver = { }, getRedirectAuthUrl(connection, options) { if (connection.authType != 'msentra') return null; - return azureAuth.azureGetRedirectAuthUrl(options); + return authProxy.authProxyGetRedirectUrl({ + ...options, + type: 'msentra', + }); }, getAuthTokenFromCode(connection, options) { - return azureAuth.azureGetAuthTokenFromCode(options); + return authProxy.authProxyGetTokenFromCode(options); }, getAccessTokenFromAuth: (connection, req) => { return req?.user?.msentraToken; diff --git a/yarn.lock b/yarn.lock index 9ff5025b9..817e109d5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -164,20 +164,6 @@ resolved "https://registry.yarnpkg.com/@azure/msal-common/-/msal-common-14.10.0.tgz#215449726717b53d549953db77562cad6cb8421c" integrity sha512-Zk6DPDz7e1wPgLoLgAp0349Yay9RvcjPM5We/ehuenDNsz/t9QEFI7tRoHpp/e47I4p20XE3FiDlhKwAo3utDA== -"@azure/msal-common@14.14.0": - version "14.14.0" - resolved "https://registry.yarnpkg.com/@azure/msal-common/-/msal-common-14.14.0.tgz#31a015070d5864ebcf9ebb988fcbc5c5536f22d1" - integrity sha512-OxcOk9H1/1fktHh6//VCORgSNJc2dCQObTm6JNmL824Z6iZSO6eFo/Bttxe0hETn9B+cr7gDouTQtsRq3YPuSQ== - -"@azure/msal-node@^2.12.0": - version "2.12.0" - resolved "https://registry.yarnpkg.com/@azure/msal-node/-/msal-node-2.12.0.tgz#57ee6b6011a320046d72dc0828fec46278f2ab2c" - integrity sha512-jmk5Im5KujRA2AcyCb0awA3buV8niSrwXZs+NBJWIvxOz76RvNlusGIqi43A0h45BPUy93Qb+CPdpJn82NFTIg== - dependencies: - "@azure/msal-common" "14.14.0" - jsonwebtoken "^9.0.0" - uuid "^8.3.0" - "@azure/msal-node@^2.5.1": version "2.8.0" resolved "https://registry.yarnpkg.com/@azure/msal-node/-/msal-node-2.8.0.tgz#ef6e4a76bcd0851f7b1240d94b00fe1f9a52d559"