mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
This commit is contained in:
parent
cfa08286de
commit
7e5364d400
@ -443,4 +443,16 @@ module.exports = {
|
||||
const loginResp = await getAuthProviderById(amoid).login(null, null, { conid });
|
||||
return loginResp;
|
||||
},
|
||||
|
||||
volatileDbloginFromAuth_meta: true,
|
||||
async volatileDbloginFromAuth({ conid }, req) {
|
||||
const connection = await this.getCore({ conid });
|
||||
const driver = requireEngineDriver(connection);
|
||||
const accessToken = await driver.getAccessTokenFromAuth(connection, req);
|
||||
if (accessToken) {
|
||||
const volatile = await this.saveVolatile({ conid, accessToken });
|
||||
return volatile;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
};
|
||||
|
@ -146,4 +146,5 @@ export const driverBase = {
|
||||
},
|
||||
showConnectionField: (field, values) => false,
|
||||
showConnectionTab: field => true,
|
||||
getAccessTokenFromAuth: async (connection, req) => null,
|
||||
};
|
||||
|
1
packages/types/engines.d.ts
vendored
1
packages/types/engines.d.ts
vendored
@ -151,6 +151,7 @@ export interface EngineDriver {
|
||||
stopProfiler(pool, profiler): Promise<void>;
|
||||
getRedirectAuthUrl(connection, options): Promise<string>;
|
||||
getAuthTokenFromCode(connection, options): Promise<string>;
|
||||
getAccessTokenFromAuth(connection, req): Promise<string | null>;
|
||||
|
||||
analyserClass?: any;
|
||||
dumperClass?: any;
|
||||
|
@ -79,13 +79,22 @@ function wantEventSource() {
|
||||
}
|
||||
}
|
||||
|
||||
function processApiResponse(route, args, resp) {
|
||||
async function processApiResponse(route, args, resp) {
|
||||
// if (apiLogging) {
|
||||
// console.log('<<< API RESPONSE', route, args, resp);
|
||||
// }
|
||||
|
||||
if (resp?.missingCredentials) {
|
||||
if (resp.detail.redirectToDbLogin) {
|
||||
const volatile = await apiCall('connections/volatile-dblogin-from-auth', { conid: resp.detail.conid });
|
||||
if (volatile) {
|
||||
setVolatileConnectionRemapping(resp.detail.conid, volatile._id);
|
||||
await callServerPing();
|
||||
dispatchCacheChange({ key: `server-status-changed` });
|
||||
batchDispatchCacheTriggers(x => x.conid == resp.detail.conid);
|
||||
return null;
|
||||
}
|
||||
|
||||
const state = `dbg-dblogin:${strmid}:${resp.detail.conid}`;
|
||||
localStorage.setItem('dbloginState', state);
|
||||
openWebLink(
|
||||
@ -145,7 +154,7 @@ export async function apiCall(route: string, args: {} = undefined) {
|
||||
const electron = getElectron();
|
||||
if (electron) {
|
||||
const resp = await electron.invoke(route.replace('/', '-'), args);
|
||||
return processApiResponse(route, args, resp);
|
||||
return await processApiResponse(route, args, resp);
|
||||
} else {
|
||||
const resp = await fetch(`${resolveApi()}/${route}`, {
|
||||
method: 'POST',
|
||||
@ -174,7 +183,7 @@ export async function apiCall(route: string, args: {} = undefined) {
|
||||
}
|
||||
|
||||
const json = await resp.json();
|
||||
return processApiResponse(route, args, json);
|
||||
return await processApiResponse(route, args, json);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,6 +144,9 @@ const driver = {
|
||||
getAuthTokenFromCode(connection, options) {
|
||||
return azureAuth.azureGetAuthTokenFromCode(options);
|
||||
},
|
||||
getAccessTokenFromAuth: (connection, req) => {
|
||||
return req?.user?.msentraToken;
|
||||
},
|
||||
};
|
||||
|
||||
driver.initialize = dbgateEnv => {
|
||||
|
Loading…
Reference in New Issue
Block a user