cloud login WIP

This commit is contained in:
Jan Prochazka
2025-05-15 16:01:51 +02:00
parent f826b9eb6e
commit 4dc2627da2
6 changed files with 69 additions and 1 deletions

View File

@@ -13,6 +13,7 @@ const {
} = require('../auth/authProvider');
const storage = require('./storage');
const { decryptPasswordString } = require('../utility/crypting');
const { createDbGateIdentitySession, getIdentitySigninUrl } = require('../utility/cloudIntf');
const logger = getLogger('auth');
@@ -135,5 +136,13 @@ module.exports = {
return getAuthProviderById(amoid).redirect(params);
},
createCloudLoginSession_meta: true,
async createCloudLoginSession({ client }) {
const sid = await createDbGateIdentitySession(client);
return {
url: getIdentitySigninUrl(sid),
};
},
authMiddleware,
};

View File

@@ -36,6 +36,14 @@ async function callRefactorSqlQueryApi(query, task, structure, dialect) {
return null;
}
function getExternalParamsWithLicense() {
return {
headers: {
'Content-Type': 'application/json',
},
};
}
module.exports = {
isAuthProxySupported,
authProxyGetRedirectUrl,
@@ -47,4 +55,5 @@ module.exports = {
callTextToSqlApi,
callCompleteOnCursorApi,
callRefactorSqlQueryApi,
getExternalParamsWithLicense,
};

View File

@@ -0,0 +1,34 @@
const axios = require('axios');
const { getExternalParamsWithLicense } = require('./authProxy');
const DBGATE_IDENTITY_URL = process.env.LOCAL_DBGATE_IDENTITY
? 'http://localhost:3001'
: process.env.DEVWEB || process.env.DEVMODE
? 'https://identity.dbgate.udolni.net'
: 'https://identity.dbgate.io';
const DBGATE_CLOUD_URL = process.env.LOCAL_DBGATE_CLOUD
? 'http://localhost:3109'
: process.env.DEVWEB || process.env.DEVMODE
? 'https://cloud.dbgate.udolni.net'
: 'https://cloud.dbgate.io';
async function createDbGateIdentitySession(client) {
const resp = await axios.default.post(
`${DBGATE_IDENTITY_URL}/api/create-session`,
{
client,
},
getExternalParamsWithLicense()
);
return resp.data.sid;
}
function getIdentitySigninUrl(sid) {
return `${DBGATE_IDENTITY_URL}/signin/${sid}`;
}
module.exports = {
createDbGateIdentitySession,
getIdentitySigninUrl,
};