mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 08:43:57 +00:00
login WIP
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
@@ -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,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -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)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user