mirror of
https://github.com/thelounge/thelounge.git
synced 2024-06-02 13:52:17 +02:00
a0d10989ad
The caller doesn't care which plugin is being used, so this commit consolidates implementation details within auth.js The motivation for this work is to prepare for extending the auth API (to allow "advanced" LDAP to query user entry ontological state at start up), by tidying up rather than duplicating the existing mechanism.
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
"use strict";
|
|
|
|
const log = require("../log");
|
|
const colors = require("chalk");
|
|
|
|
// The order defines priority: the first available plugin is used.
|
|
// Always keep 'local' auth plugin at the end of the list; it should always be enabled.
|
|
const plugins = [require("./auth/ldap"), require("./auth/local")];
|
|
|
|
function unimplemented(funcName) {
|
|
log.debug(
|
|
`Auth module ${colors.bold(
|
|
module.exports.moduleName
|
|
)} doesn't implement function ${colors.bold(funcName)}`
|
|
);
|
|
}
|
|
|
|
// Default API implementations
|
|
module.exports = {
|
|
moduleName: "<module with no name>",
|
|
|
|
// Must override: implements authentication mechanism
|
|
auth: () => unimplemented("auth"),
|
|
};
|
|
|
|
// local auth should always be enabled, but check here to verify
|
|
let somethingEnabled = false;
|
|
|
|
// Override default API stubs with exports from first enabled plugin found
|
|
for (const plugin of plugins) {
|
|
if (plugin.isEnabled()) {
|
|
somethingEnabled = true;
|
|
|
|
for (const name in plugin) {
|
|
module.exports[name] = plugin[name];
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!somethingEnabled) {
|
|
log.error("None of the auth plugins is enabled");
|
|
}
|