mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 00:16:24 +00:00
oauth disabling API
This commit is contained in:
@@ -24,12 +24,8 @@
|
|||||||
|
|
||||||
let loadedApi = false;
|
let loadedApi = false;
|
||||||
let loadedPlugins = false;
|
let loadedPlugins = false;
|
||||||
const isOauthCallback = handleOauthCallback();
|
|
||||||
|
|
||||||
async function loadApi() {
|
async function loadApi() {
|
||||||
if (isOauthCallback) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// if (shouldWaitForElectronInitialize()) {
|
// if (shouldWaitForElectronInitialize()) {
|
||||||
// setTimeout(loadApi, 100);
|
// setTimeout(loadApi, 100);
|
||||||
// return;
|
// return;
|
||||||
@@ -80,7 +76,7 @@
|
|||||||
|
|
||||||
<ErrorHandler />
|
<ErrorHandler />
|
||||||
|
|
||||||
{#if loadedApi && !isOauthCallback}
|
{#if loadedApi}
|
||||||
<DataGridRowHeightMeter />
|
<DataGridRowHeightMeter />
|
||||||
<CommandListener />
|
<CommandListener />
|
||||||
<PluginsProvider />
|
<PluginsProvider />
|
||||||
|
|||||||
@@ -1,38 +1,38 @@
|
|||||||
import { apiCall } from './utility/api';
|
import { apiCall, disableApi } from './utility/api';
|
||||||
import { getConfig } from './utility/metadataLoaders';
|
import { getConfig } from './utility/metadataLoaders';
|
||||||
|
|
||||||
export function handleOauthCallback() {
|
export function isOauthCallback() {
|
||||||
const params = new URLSearchParams(location.search);
|
const params = new URLSearchParams(location.search);
|
||||||
const sentCode = params.get('code');
|
const sentCode = params.get('code');
|
||||||
const sentState = params.get('state');
|
const sentState = params.get('state');
|
||||||
|
|
||||||
if (
|
return (
|
||||||
sentCode &&
|
sentCode && sentState && sentState.startsWith('dbg-oauth:') && sentState == sessionStorage.getItem('oauthState')
|
||||||
sentState &&
|
);
|
||||||
sentState.startsWith('dbg-oauth:') &&
|
}
|
||||||
sentState == sessionStorage.getItem('oauthState')
|
|
||||||
) {
|
export function handleOauthCallback() {
|
||||||
|
const params = new URLSearchParams(location.search);
|
||||||
|
const sentCode = params.get('code');
|
||||||
|
|
||||||
|
if (isOauthCallback()) {
|
||||||
sessionStorage.removeItem('oauthState');
|
sessionStorage.removeItem('oauthState');
|
||||||
apiCall('auth/oauth-token', {
|
apiCall('auth/oauth-token', {
|
||||||
code: sentCode,
|
code: sentCode,
|
||||||
redirectUri: location.origin,
|
redirectUri: location.origin,
|
||||||
}).then(authResp => {
|
}).then(authResp => {
|
||||||
const { accessToken } = authResp;
|
const { accessToken } = authResp;
|
||||||
console.log('Got new access token:', accessToken);
|
|
||||||
localStorage.setItem('accessToken', accessToken);
|
localStorage.setItem('accessToken', accessToken);
|
||||||
location.replace('/');
|
location.replace('/');
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('handleOauthCallback TRUE');
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('handleOauthCallback FALSE');
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function handleAuthOnStartup(config) {
|
export async function handleAuthOnStartup(config) {
|
||||||
console.log('********************* handleAuthOnStartup');
|
|
||||||
if (config.oauth) {
|
if (config.oauth) {
|
||||||
if (localStorage.getItem('accessToken')) {
|
if (localStorage.getItem('accessToken')) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -5,12 +5,16 @@ import './commands/stdCommands';
|
|||||||
import localStorageGarbageCollector from './utility/localStorageGarbageCollector';
|
import localStorageGarbageCollector from './utility/localStorageGarbageCollector';
|
||||||
import { handleOauthCallback } from './clientAuth';
|
import { handleOauthCallback } from './clientAuth';
|
||||||
|
|
||||||
|
const isOauthCallback = handleOauthCallback();
|
||||||
|
|
||||||
localStorageGarbageCollector();
|
localStorageGarbageCollector();
|
||||||
|
|
||||||
const app = new App({
|
const app = isOauthCallback
|
||||||
target: document.body,
|
? null
|
||||||
props: {},
|
: new App({
|
||||||
});
|
target: document.body,
|
||||||
|
props: {},
|
||||||
|
});
|
||||||
|
|
||||||
// const app = null;
|
// const app = null;
|
||||||
|
|
||||||
|
|||||||
@@ -4,16 +4,17 @@ import { writable } from 'svelte/store';
|
|||||||
import getElectron from './getElectron';
|
import getElectron from './getElectron';
|
||||||
// import socket from './socket';
|
// import socket from './socket';
|
||||||
import { showSnackbarError } from '../utility/snackbar';
|
import { showSnackbarError } from '../utility/snackbar';
|
||||||
import { redirectToLogin } from '../clientAuth';
|
import { isOauthCallback, redirectToLogin } from '../clientAuth';
|
||||||
|
|
||||||
let eventSource;
|
let eventSource;
|
||||||
let apiLogging = false;
|
let apiLogging = false;
|
||||||
// let cacheCleanerRegistered;
|
// let cacheCleanerRegistered;
|
||||||
let apiDisabled = false;
|
let apiDisabled = false;
|
||||||
|
const disabledOnOauth = isOauthCallback();
|
||||||
|
|
||||||
// export function disableApi() {
|
export function disableApi() {
|
||||||
// apiDisabled = true;
|
apiDisabled = true;
|
||||||
// }
|
}
|
||||||
|
|
||||||
function wantEventSource() {
|
function wantEventSource() {
|
||||||
if (!eventSource) {
|
if (!eventSource) {
|
||||||
@@ -45,6 +46,10 @@ export async function apiCall(route: string, args: {} = undefined) {
|
|||||||
console.log('API disabled!!', route);
|
console.log('API disabled!!', route);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (disabledOnOauth && route != 'auth/oauth-token') {
|
||||||
|
console.log('API disabled because oauth callback!!', route);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const electron = getElectron();
|
const electron = getElectron();
|
||||||
if (electron) {
|
if (electron) {
|
||||||
@@ -62,7 +67,7 @@ export async function apiCall(route: string, args: {} = undefined) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (resp.status == 401 && !apiDisabled) {
|
if (resp.status == 401 && !apiDisabled) {
|
||||||
apiDisabled = true;
|
disableApi();
|
||||||
console.log('Disabling API', route);
|
console.log('Disabling API', route);
|
||||||
// unauthorized
|
// unauthorized
|
||||||
redirectToLogin();
|
redirectToLogin();
|
||||||
|
|||||||
Reference in New Issue
Block a user