login WIP

This commit is contained in:
Jan Prochazka
2022-11-25 16:59:41 +01:00
parent 5ccd724166
commit 9a5287725b
3 changed files with 19 additions and 10 deletions

View File

@@ -74,7 +74,7 @@ module.exports = {
async login(params) { async login(params) {
const { login, password } = params; const { login, password } = params;
if (process.env.AD_URL && process.env.AD_BASEDN) { if (process.env.AD_URL) {
const adConfig = { const adConfig = {
url: process.env.AD_URL, url: process.env.AD_URL,
baseDN: process.env.AD_BASEDN, baseDN: process.env.AD_BASEDN,

View File

@@ -41,6 +41,7 @@ module.exports = {
permissions, permissions,
login, login,
oauth: process.env.OAUTH_AUTH, oauth: process.env.OAUTH_AUTH,
isLoginForm: !!process.env.AD_URL || (!!logins && !process.env.BASIC_AUTH),
...currentVersion, ...currentVersion,
}; };
}, },

View File

@@ -33,7 +33,7 @@ export function handleOauthCallback() {
} }
export async function handleAuthOnStartup(config) { export async function handleAuthOnStartup(config) {
if (config.oauth) { if (config.oauth || config.isLoginForm) {
if (localStorage.getItem('accessToken')) { if (localStorage.getItem('accessToken')) {
return; return;
} }
@@ -45,12 +45,20 @@ export async function handleAuthOnStartup(config) {
export async function redirectToLogin(config = null) { export async function redirectToLogin(config = null) {
if (!config) config = await getConfig(); if (!config) config = await getConfig();
const state = `dbg-oauth:${Math.random().toString().substr(2)}`; if (config.isLoginForm) {
sessionStorage.setItem('oauthState', state); const index = location.pathname.lastIndexOf('/');
console.log('Redirecting to OAUTH provider'); const loginPath = index >= 0 ? location.pathname.substring(0, index) + '/?page=login' : '/?page=login';
location.replace( location.replace(loginPath);
`${config.oauth}?client_id=dbgate&response_type=code&redirect_uri=${encodeURIComponent( }
location.origin + location.pathname
)}&state=${encodeURIComponent(state)}` if (config.oauth) {
); const state = `dbg-oauth:${Math.random().toString().substr(2)}`;
sessionStorage.setItem('oauthState', state);
console.log('Redirecting to OAUTH provider');
location.replace(
`${config.oauth}?client_id=dbgate&response_type=code&redirect_uri=${encodeURIComponent(
location.origin + location.pathname
)}&state=${encodeURIComponent(state)}`
);
}
} }