msentra auth
Some checks failed
Run tests / test-runner (push) Has been cancelled

This commit is contained in:
Jan Prochazka 2024-08-08 11:45:21 +02:00
parent cfa08286de
commit 7e5364d400
5 changed files with 29 additions and 3 deletions

View File

@ -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;
},
};

View File

@ -146,4 +146,5 @@ export const driverBase = {
},
showConnectionField: (field, values) => false,
showConnectionTab: field => true,
getAccessTokenFromAuth: async (connection, req) => null,
};

View File

@ -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;

View File

@ -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);
}
}

View File

@ -144,6 +144,9 @@ const driver = {
getAuthTokenFromCode(connection, options) {
return azureAuth.azureGetAuthTokenFromCode(options);
},
getAccessTokenFromAuth: (connection, req) => {
return req?.user?.msentraToken;
},
};
driver.initialize = dbgateEnv => {