mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 06:26:00 +00:00
azure auth - access token obtained
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
import getElectron from './utility/getElectron';
|
||||
import AppStartInfo from './widgets/AppStartInfo.svelte';
|
||||
import SettingsListener from './utility/SettingsListener.svelte';
|
||||
import { handleAuthOnStartup, handleOauthCallback } from './clientAuth';
|
||||
import { handleAuthOnStartup } from './clientAuth';
|
||||
|
||||
export let isAdminPage = false;
|
||||
|
||||
|
||||
@@ -12,6 +12,16 @@ export function isOauthCallback() {
|
||||
);
|
||||
}
|
||||
|
||||
export function isDbLoginCallback() {
|
||||
const params = new URLSearchParams(location.search);
|
||||
const sentCode = params.get('code');
|
||||
const sentState = params.get('state');
|
||||
|
||||
return (
|
||||
sentCode && sentState && sentState.startsWith('dbg-dblogin:') && sentState == localStorage.getItem('dbloginState')
|
||||
);
|
||||
}
|
||||
|
||||
export function handleOauthCallback() {
|
||||
const params = new URLSearchParams(location.search);
|
||||
const sentCode = params.get('code');
|
||||
@@ -37,6 +47,32 @@ export function handleOauthCallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
console.log('****************** IS DB LOGIN TEST');
|
||||
if (isDbLoginCallback()) {
|
||||
console.log('****************** IS DB LOGIN TRUE');
|
||||
const conid = localStorage.getItem('dbloginState').split('@')[1];
|
||||
localStorage.removeItem('dbloginState');
|
||||
|
||||
apiCall('connections/dblogin-token', {
|
||||
code: sentCode,
|
||||
conid,
|
||||
redirectUri: location.origin + location.pathname,
|
||||
}).then(authResp => {
|
||||
const { accessToken, error, errorMessage } = authResp;
|
||||
|
||||
if (accessToken) {
|
||||
console.log('Settings access token from OAUTH');
|
||||
localStorage.setItem('accessToken', accessToken);
|
||||
internalRedirectTo('/');
|
||||
} else {
|
||||
console.log('Error when processing OAUTH callback', error || errorMessage);
|
||||
internalRedirectTo(`?page=not-logged&error=${error || errorMessage}`);
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import uuidv1 from 'uuid/v1';
|
||||
import { openWebLink } from './exportFileTools';
|
||||
|
||||
export const strmid = uuidv1();
|
||||
const privateApiState = Math.random().toString().substr(2);
|
||||
|
||||
let eventSource;
|
||||
let apiLogging = false;
|
||||
@@ -65,7 +66,13 @@ function processApiResponse(route, args, resp) {
|
||||
|
||||
if (resp?.missingCredentials) {
|
||||
if (resp.detail.redirectToDbLogin) {
|
||||
openWebLink(`connections/dblogin?conid=${resp.detail.conid}`);
|
||||
const state = `dbg-dblogin:${privateApiState}@${resp.detail.conid}`;
|
||||
localStorage.setItem('dbloginState', state);
|
||||
openWebLink(
|
||||
`connections/dblogin?conid=${resp.detail.conid}&state=${encodeURIComponent(state)}&redirectUri=${
|
||||
location.origin + location.pathname
|
||||
}`
|
||||
);
|
||||
} else if (!isDatabaseLoginVisible()) {
|
||||
showModal(DatabaseLoginModal, resp.detail);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user