mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-17 23:45:59 +00:00
azure auth moved to auth proxy
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -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');
|
||||
|
||||
17
packages/api/src/utility/authProxy.js
Normal file
17
packages/api/src/utility/authProxy.js
Normal file
@@ -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,
|
||||
};
|
||||
@@ -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,
|
||||
};
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
14
yarn.lock
14
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"
|
||||
|
||||
Reference in New Issue
Block a user