mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 12:26:01 +00:00
more robust oauth
This commit is contained in:
@@ -21,9 +21,16 @@ export function handleOauthCallback() {
|
||||
code: sentCode,
|
||||
redirectUri: location.origin + location.pathname,
|
||||
}).then(authResp => {
|
||||
const { accessToken } = authResp;
|
||||
localStorage.setItem('accessToken', accessToken);
|
||||
internalRedirectTo('/');
|
||||
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;
|
||||
|
||||
@@ -36,6 +36,7 @@ import runCommand from './runCommand';
|
||||
import { openWebLink } from '../utility/exportFileTools';
|
||||
import { getSettings } from '../utility/metadataLoaders';
|
||||
import { isMac } from '../utility/common';
|
||||
import { internalRedirectTo } from '../clientAuth';
|
||||
|
||||
// function themeCommand(theme: ThemeDefinition) {
|
||||
// return {
|
||||
@@ -549,7 +550,20 @@ registerCommand({
|
||||
name: 'Logout',
|
||||
testEnabled: () => getCurrentConfig()?.login != null,
|
||||
onClick: () => {
|
||||
window.location.href = 'config/logout';
|
||||
const config = getCurrentConfig();
|
||||
if (config.oauth) {
|
||||
localStorage.removeItem('accessToken');
|
||||
if (config.oauthLogout) {
|
||||
window.location.href = config.oauthLogout;
|
||||
} else {
|
||||
internalRedirectTo('/?page=not-logged');
|
||||
}
|
||||
} else if (config.isLoginForm) {
|
||||
localStorage.removeItem('accessToken');
|
||||
internalRedirectTo('/?page=not-logged');
|
||||
} else {
|
||||
window.location.href = 'config/logout';
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -71,10 +71,15 @@ export async function apiCall(route: string, args: {} = undefined) {
|
||||
});
|
||||
|
||||
if (resp.status == 401 && !apiDisabled) {
|
||||
const params = new URLSearchParams(location.search);
|
||||
|
||||
disableApi();
|
||||
console.log('Disabling API', route);
|
||||
// unauthorized
|
||||
redirectToLogin();
|
||||
if (params.get('page') != 'login' && params.get('page') != 'not-logged') {
|
||||
// unauthorized
|
||||
redirectToLogin();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const json = await resp.json();
|
||||
|
||||
Reference in New Issue
Block a user