oauth working, but cycling sometimes

This commit is contained in:
Jan Prochazka
2022-11-17 12:43:38 +01:00
parent f42d78b2fb
commit 37a8783751
10 changed files with 132 additions and 54 deletions

View File

@@ -20,38 +20,11 @@
import getElectron from './utility/getElectron';
import AppStartInfo from './widgets/AppStartInfo.svelte';
import SettingsListener from './utility/SettingsListener.svelte';
import { handleAuthOnStartup } from './clientAuth';
let loadedApi = false;
let loadedPlugins = false;
async function handleAuth(config) {
if (config.oauth) {
const params = new URLSearchParams(location.search);
const sentCode = params.get('code');
const sentState = params.get('state');
if (
sentCode &&
sentState &&
sentState.startsWith('dbg-oauth:') &&
sentState == sessionStorage.getItem('oauthState')
) {
const accessToken = await apiCall('auth/oauth-token', {
code: sentCode,
redirectUri: location.origin,
});
console.log('TOKEN', accessToken);
} else {
const state = `dbg-oauth:${Math.random().toString().substr(2)}`;
sessionStorage.setItem('oauthState', state);
location.replace(
`${config.oauth}/auth?client_id=dbgate&response_type=code&redirect_uri=${encodeURIComponent(
location.origin
)}&state=${encodeURIComponent(state)}`
);
}
}
}
async function loadApi() {
// if (shouldWaitForElectronInitialize()) {
// setTimeout(loadApi, 100);
@@ -61,10 +34,11 @@
try {
// console.log('************** LOADING API');
const config = await getConfig();
await handleAuthOnStartup(config);
const connections = await apiCall('connections/list');
const settings = await getSettings();
const config = await getConfig();
handleAuth(config);
const apps = await getUsedApps();
loadedApi = settings && connections && config && apps;