azure auth

This commit is contained in:
Jan Prochazka
2024-08-05 12:56:43 +02:00
parent fb2e261a08
commit 97aa563fe7
9 changed files with 64 additions and 37 deletions

View File

@@ -6,6 +6,9 @@
const config = useConfig();
const params = new URLSearchParams(location.search);
const error = params.get('error');
onMount(() => {
const removed = document.getElementById('starting_dbgate_zero');
if (removed) removed.remove();
@@ -21,7 +24,11 @@
<div class="box">
<div class="heading">Configuration error</div>
{#if !$config?.isLicenseValid}
<ErrorInfo message={`Invalid license. Please contact sales@dbgate.eu for more details. ${$config?.licenseError}`} />
<ErrorInfo
message={`Invalid license. Please contact sales@dbgate.eu for more details. ${$config?.licenseError}`}
/>
{:else if error}
<ErrorInfo message={error} />
{:else}
<ErrorInfo message="No error found, try to open app again" />
<div class="m-2">

View File

@@ -10,6 +10,7 @@
export let passProps;
$: databases = useDatabaseList({ conid: data._id });
console.log('USED DATABASE LIST', data._id);
</script>
<AppObjectList

View File

@@ -47,26 +47,22 @@ 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];
const [_prefix, strmid, conid] = localStorage.getItem('dbloginState').split(':');
localStorage.removeItem('dbloginState');
apiCall('connections/dblogin-token', {
code: sentCode,
conid,
strmid,
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('/');
if (authResp.success) {
window.close();
} else if (authResp.error) {
internalRedirectTo(`?page=error&error=${encodeURIComponent(authResp)}`);
} else {
console.log('Error when processing OAUTH callback', error || errorMessage);
internalRedirectTo(`?page=not-logged&error=${error || errorMessage}`);
internalRedirectTo(`?page=error`);
}
});

View File

@@ -10,9 +10,10 @@ import DatabaseLoginModal, { isDatabaseLoginVisible } from '../modals/DatabaseLo
import _ from 'lodash';
import uuidv1 from 'uuid/v1';
import { openWebLink } from './exportFileTools';
import { callServerPing } from './connectionsPinger';
import { batchDispatchCacheTriggers, dispatchCacheChange } from './cache';
export const strmid = uuidv1();
const privateApiState = Math.random().toString().substr(2);
let eventSource;
let apiLogging = false;
@@ -66,7 +67,7 @@ function processApiResponse(route, args, resp) {
if (resp?.missingCredentials) {
if (resp.detail.redirectToDbLogin) {
const state = `dbg-dblogin:${privateApiState}@${resp.detail.conid}`;
const state = `dbg-dblogin:${strmid}:${resp.detail.conid}`;
localStorage.setItem('dbloginState', state);
openWebLink(
`connections/dblogin?conid=${resp.detail.conid}&state=${encodeURIComponent(state)}&redirectUri=${
@@ -224,8 +225,12 @@ export function getVolatileConnections() {
}
export function installNewVolatileConnectionListener() {
apiOn('got-volatile-token', ({ savedConId, volatileConId }) => {
apiOn('got-volatile-token', async ({ savedConId, volatileConId }) => {
console.log('************************** GOT VOLASTILE TOKEN', savedConId, volatileConId);
setVolatileConnectionRemapping(savedConId, volatileConId);
await callServerPing();
dispatchCacheChange({ key: `server-status-changed` });
batchDispatchCacheTriggers(x => x.conid == savedConId);
});
}

View File

@@ -1,7 +1,6 @@
import _ from 'lodash';
import { openedConnections, currentDatabase, openedConnectionsWithTemporary, getCurrentConfig, getOpenedConnections } from '../stores';
import { currentDatabase, openedConnectionsWithTemporary, getCurrentConfig, getOpenedConnections } from '../stores';
import { apiCall, getVolatileConnections, strmid } from './api';
import { getConnectionList } from './metadataLoaders';
import hasPermission from '../utility/hasPermission';
// const doServerPing = async value => {