mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 00:46:01 +00:00
auth db login workflow
This commit is contained in:
@@ -26,6 +26,10 @@ class AuthProviderBase {
|
||||
return login;
|
||||
}
|
||||
|
||||
isUserLoggedIn(req) {
|
||||
return !!req.user || !!req.auth;
|
||||
}
|
||||
|
||||
getCurrentPermissions(req) {
|
||||
const login = this.getCurrentLogin(req);
|
||||
const permissions = process.env[`LOGIN_PERMISSIONS_${login}`];
|
||||
|
||||
@@ -23,12 +23,14 @@ function unauthorizedResponse(req, res, text) {
|
||||
function authMiddleware(req, res, next) {
|
||||
const SKIP_AUTH_PATHS = [
|
||||
'/config/get',
|
||||
'/config/get-settings',
|
||||
'/auth/oauth-token',
|
||||
'/auth/login',
|
||||
'/stream',
|
||||
'storage/get-connections-for-login-page',
|
||||
'/connections/dblogin',
|
||||
'/connections/dblogin-auth',
|
||||
'/connections/dblogin-auth-token',
|
||||
];
|
||||
|
||||
// console.log('********************* getAuthProvider()', getAuthProvider());
|
||||
|
||||
@@ -33,6 +33,7 @@ module.exports = {
|
||||
const permissions = authProvider.getCurrentPermissions(req);
|
||||
const isLoginForm = authProvider.isLoginForm();
|
||||
const additionalConfigProps = authProvider.getAdditionalConfigProps();
|
||||
const isUserLoggedIn = authProvider.isUserLoggedIn(req);
|
||||
|
||||
const singleConid = authProvider.getSingleConnectionId(req);
|
||||
|
||||
@@ -44,6 +45,7 @@ module.exports = {
|
||||
runAsPortal: !!connections.portalConnections,
|
||||
singleDbConnection: connections.singleDbConnection,
|
||||
singleConnection: singleConnection,
|
||||
isUserLoggedIn,
|
||||
// hideAppEditor: !!process.env.HIDE_APP_EDITOR,
|
||||
allowShellConnection: platformInfo.allowShellConnection,
|
||||
allowShellScripting: platformInfo.allowShellScripting,
|
||||
|
||||
@@ -412,6 +412,22 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
dbloginAuthToken_meta: true,
|
||||
async dbloginAuthToken({ code, conid, 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 });
|
||||
const authProvider = getAuthProvider();
|
||||
const resp = await authProvider.login(null, null, { conid: volatile._id });
|
||||
return resp;
|
||||
} catch (err) {
|
||||
logger.error({ err }, 'Error getting DB token');
|
||||
return { error: err.message };
|
||||
}
|
||||
},
|
||||
|
||||
dbloginAuth_meta: true,
|
||||
async dbloginAuth({ conid, user, password }) {
|
||||
if (user || password) {
|
||||
|
||||
Reference in New Issue
Block a user