AD auth supports basic auth

This commit is contained in:
Jan Prochazka
2024-07-26 09:57:27 +02:00
parent 05329951f9
commit 8db941dc06
2 changed files with 17 additions and 16 deletions

View File

@@ -45,11 +45,23 @@ function start() {
const server = http.createServer(app);
const basicAuthLogins = createAuthProvider().getBasicAuthLogins();
if (basicAuthLogins) {
if (process.env.BASIC_AUTH) {
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(
basicAuth({
users: basicAuthLogins,
authorizer,
authorizeAsync: true,
challenge: true,
realm: 'DbGate Web App',
})