mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-02 17:13:58 +00:00
AD auth supports basic auth
This commit is contained in:
@@ -49,10 +49,6 @@ class AuthProviderBase {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
getBasicAuthLogins() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldAuthorizeApi() {
|
shouldAuthorizeApi() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -163,11 +159,11 @@ class ADProvider extends AuthProviderBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
shouldAuthorizeApi() {
|
shouldAuthorizeApi() {
|
||||||
return true;
|
return !process.env.BASIC_AUTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
isLoginForm() {
|
isLoginForm() {
|
||||||
return true;
|
return !process.env.BASIC_AUTH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,13 +182,6 @@ class LoginsProvider extends AuthProviderBase {
|
|||||||
return { error: 'Invalid credentials' };
|
return { error: 'Invalid credentials' };
|
||||||
}
|
}
|
||||||
|
|
||||||
getBasicAuthLogins() {
|
|
||||||
const logins = getEnvLogins();
|
|
||||||
if (logins && process.env.BASIC_AUTH) {
|
|
||||||
return _.fromPairs(logins.filter(x => x.password).map(x => [x.login, x.password]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldAuthorizeApi() {
|
shouldAuthorizeApi() {
|
||||||
return !process.env.BASIC_AUTH;
|
return !process.env.BASIC_AUTH;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,11 +45,23 @@ function start() {
|
|||||||
|
|
||||||
const server = http.createServer(app);
|
const server = http.createServer(app);
|
||||||
|
|
||||||
const basicAuthLogins = createAuthProvider().getBasicAuthLogins();
|
if (process.env.BASIC_AUTH) {
|
||||||
if (basicAuthLogins) {
|
async function authorizer(username, password, cb) {
|
||||||
|
try {
|
||||||
|
const resp = await createAuthProvider().login(username, password);
|
||||||
|
if (resp.accessToken) {
|
||||||
|
cb(null, true);
|
||||||
|
} else {
|
||||||
|
cb(null, false);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
cb(err, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
app.use(
|
app.use(
|
||||||
basicAuth({
|
basicAuth({
|
||||||
users: basicAuthLogins,
|
authorizer,
|
||||||
|
authorizeAsync: true,
|
||||||
challenge: true,
|
challenge: true,
|
||||||
realm: 'DbGate Web App',
|
realm: 'DbGate Web App',
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user