azure auth - access token obtained

This commit is contained in:
Jan Prochazka
2024-08-02 16:09:59 +02:00
parent 112513a569
commit a6822dd293
7 changed files with 69 additions and 9 deletions

View File

@@ -20,7 +20,7 @@
import getElectron from './utility/getElectron';
import AppStartInfo from './widgets/AppStartInfo.svelte';
import SettingsListener from './utility/SettingsListener.svelte';
import { handleAuthOnStartup, handleOauthCallback } from './clientAuth';
import { handleAuthOnStartup } from './clientAuth';
export let isAdminPage = false;

View File

@@ -12,6 +12,16 @@ export function isOauthCallback() {
);
}
export function isDbLoginCallback() {
const params = new URLSearchParams(location.search);
const sentCode = params.get('code');
const sentState = params.get('state');
return (
sentCode && sentState && sentState.startsWith('dbg-dblogin:') && sentState == localStorage.getItem('dbloginState')
);
}
export function handleOauthCallback() {
const params = new URLSearchParams(location.search);
const sentCode = params.get('code');
@@ -37,6 +47,32 @@ 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];
localStorage.removeItem('dbloginState');
apiCall('connections/dblogin-token', {
code: sentCode,
conid,
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('/');
} else {
console.log('Error when processing OAUTH callback', error || errorMessage);
internalRedirectTo(`?page=not-logged&error=${error || errorMessage}`);
}
});
return true;
}
return false;
}

View File

@@ -12,6 +12,7 @@ import uuidv1 from 'uuid/v1';
import { openWebLink } from './exportFileTools';
export const strmid = uuidv1();
const privateApiState = Math.random().toString().substr(2);
let eventSource;
let apiLogging = false;
@@ -65,7 +66,13 @@ function processApiResponse(route, args, resp) {
if (resp?.missingCredentials) {
if (resp.detail.redirectToDbLogin) {
openWebLink(`connections/dblogin?conid=${resp.detail.conid}`);
const state = `dbg-dblogin:${privateApiState}@${resp.detail.conid}`;
localStorage.setItem('dbloginState', state);
openWebLink(
`connections/dblogin?conid=${resp.detail.conid}&state=${encodeURIComponent(state)}&redirectUri=${
location.origin + location.pathname
}`
);
} else if (!isDatabaseLoginVisible()) {
showModal(DatabaseLoginModal, resp.detail);
}