mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 08:43:57 +00:00
multiauth refactor
This commit is contained in:
@@ -24,9 +24,9 @@
|
||||
</div>
|
||||
<div class="box">
|
||||
<div class="heading">Configuration error</div>
|
||||
{#if $config?.isLicenseValid == false}
|
||||
{#if $config?.checkedLicense?.status == 'error'}
|
||||
<ErrorInfo
|
||||
message={`Invalid license. Please contact sales@dbgate.eu for more details. ${$config?.licenseError}`}
|
||||
message={`Invalid license. Please contact sales@dbgate.eu for more details. ${$config?.checkedLicense?.error}`}
|
||||
/>
|
||||
{:else if error}
|
||||
<ErrorInfo message={error} />
|
||||
|
||||
@@ -209,6 +209,22 @@
|
||||
return;
|
||||
}
|
||||
internalRedirectTo(`/?page=not-logged`);
|
||||
} else if (workflowType == 'redirect') {
|
||||
const state = `dbg-oauth:${strmid}:${$values.amoid}`;
|
||||
|
||||
sessionStorage.setItem('oauthState', state);
|
||||
console.log('Redirecting to OAUTH provider');
|
||||
|
||||
const resp = await apiCall('auth/redirect', {
|
||||
amoid: $values.amoid,
|
||||
state,
|
||||
redirectUri: location.origin + location.pathname,
|
||||
});
|
||||
|
||||
const { uri } = resp;
|
||||
if (uri) {
|
||||
location.replace(uri);
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { apiCall, enableApi } from './utility/api';
|
||||
import { apiCall, enableApi, getAuthCategory } from './utility/api';
|
||||
import { getConfig } from './utility/metadataLoaders';
|
||||
import { isAdminPage } from './utility/pageDefs';
|
||||
|
||||
@@ -40,9 +40,12 @@ export function handleOauthCallback() {
|
||||
const sentCode = params.get('code');
|
||||
|
||||
if (isOauthCallback()) {
|
||||
const [_prefix, strmid, amoid] = sessionStorage.getItem('oauthState').split(':');
|
||||
|
||||
sessionStorage.removeItem('oauthState');
|
||||
apiCall('auth/oauth-token', {
|
||||
code: sentCode,
|
||||
amoid,
|
||||
redirectUri: location.origin + location.pathname,
|
||||
}).then(authResp => {
|
||||
const { accessToken, error, errorMessage } = authResp;
|
||||
@@ -113,7 +116,7 @@ export async function handleAuthOnStartup(config, isAdminPage = false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (config.isAdminLoginForm && isAdminPage) {
|
||||
if (getAuthCategory(config) == 'admin') {
|
||||
if (localStorage.getItem('adminAccessToken')) {
|
||||
return;
|
||||
}
|
||||
@@ -122,10 +125,10 @@ export async function handleAuthOnStartup(config, isAdminPage = false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (config.oauth) {
|
||||
console.log('OAUTH callback URL:', location.origin + location.pathname);
|
||||
}
|
||||
if (config.oauth || config.isLoginForm) {
|
||||
// if (config.oauth) {
|
||||
// console.log('OAUTH callback URL:', location.origin + location.pathname);
|
||||
// }
|
||||
if (getAuthCategory(config) == 'token') {
|
||||
if (localStorage.getItem('accessToken')) {
|
||||
return;
|
||||
}
|
||||
@@ -145,7 +148,7 @@ export async function redirectToLogin(config = null, force = false) {
|
||||
config = await getConfig();
|
||||
}
|
||||
|
||||
if (config.isLoginForm) {
|
||||
if (getAuthCategory(config) == 'token') {
|
||||
if (!force) {
|
||||
const params = new URLSearchParams(location.search);
|
||||
if (params.get('page') == 'login' || params.get('page') == 'admin-login' || params.get('page') == 'not-logged') {
|
||||
|
||||
@@ -12,6 +12,7 @@ import uuidv1 from 'uuid/v1';
|
||||
import { openWebLink } from './exportFileTools';
|
||||
import { callServerPing } from './connectionsPinger';
|
||||
import { batchDispatchCacheTriggers, dispatchCacheChange } from './cache';
|
||||
import { isAdminPage } from './pageDefs';
|
||||
|
||||
export const strmid = uuidv1();
|
||||
|
||||
@@ -251,6 +252,19 @@ export function installNewVolatileConnectionListener() {
|
||||
});
|
||||
}
|
||||
|
||||
export function getAuthCategory(config) {
|
||||
if (config.isBasicAuth) {
|
||||
return 'basic';
|
||||
}
|
||||
if (isAdminPage() && config.isAdminLoginForm) {
|
||||
return 'admin';
|
||||
}
|
||||
if (getElectron()) {
|
||||
return 'electron';
|
||||
}
|
||||
return 'token';
|
||||
}
|
||||
|
||||
function enableApiLog() {
|
||||
apiLogging = true;
|
||||
console.log('API loggin enabled');
|
||||
|
||||
@@ -21,8 +21,8 @@ export function resolveApiHeaders() {
|
||||
if (accessToken) {
|
||||
res['Authorization'] = `Bearer ${accessToken}`;
|
||||
}
|
||||
if (isAdminPage()) {
|
||||
res['x-is-admin-page'] = 'true';
|
||||
}
|
||||
// if (isAdminPage()) {
|
||||
// res['x-is-admin-page'] = 'true';
|
||||
// }
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user