mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 00:56:01 +00:00
login WIP
This commit is contained in:
@@ -74,7 +74,7 @@ module.exports = {
|
||||
async login(params) {
|
||||
const { login, password } = params;
|
||||
|
||||
if (process.env.AD_URL && process.env.AD_BASEDN) {
|
||||
if (process.env.AD_URL) {
|
||||
const adConfig = {
|
||||
url: process.env.AD_URL,
|
||||
baseDN: process.env.AD_BASEDN,
|
||||
|
||||
@@ -41,6 +41,7 @@ module.exports = {
|
||||
permissions,
|
||||
login,
|
||||
oauth: process.env.OAUTH_AUTH,
|
||||
isLoginForm: !!process.env.AD_URL || (!!logins && !process.env.BASIC_AUTH),
|
||||
...currentVersion,
|
||||
};
|
||||
},
|
||||
|
||||
@@ -33,7 +33,7 @@ export function handleOauthCallback() {
|
||||
}
|
||||
|
||||
export async function handleAuthOnStartup(config) {
|
||||
if (config.oauth) {
|
||||
if (config.oauth || config.isLoginForm) {
|
||||
if (localStorage.getItem('accessToken')) {
|
||||
return;
|
||||
}
|
||||
@@ -45,12 +45,20 @@ export async function handleAuthOnStartup(config) {
|
||||
export async function redirectToLogin(config = null) {
|
||||
if (!config) config = await getConfig();
|
||||
|
||||
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)}`
|
||||
);
|
||||
if (config.isLoginForm) {
|
||||
const index = location.pathname.lastIndexOf('/');
|
||||
const loginPath = index >= 0 ? location.pathname.substring(0, index) + '/?page=login' : '/?page=login';
|
||||
location.replace(loginPath);
|
||||
}
|
||||
|
||||
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