mirror of
https://github.com/Ride-The-Lightning/RTL.git
synced 2026-08-13 12:33:07 +02:00
Add Disable Authentication option in the backend
This commit is contained in:
parent
7d32bd68e9
commit
4613b889bf
6 changed files with 37 additions and 5 deletions
|
|
@ -48,7 +48,15 @@ export const verifyToken = (twoFAToken) => !!(common.appConfig.secret2FA && comm
|
|||
export const authenticateUser = (req, res, next) => {
|
||||
const { authenticateWith, authenticationValue, twoFAToken } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Authenticate', msg: 'Authenticating User..' });
|
||||
if (+common.appConfig.SSO.rtlSSO) {
|
||||
if (!!common.appConfig.disableAuth) {
|
||||
if (!req.session.selectedNode) {
|
||||
req.session.selectedNode = common.selectedNode;
|
||||
}
|
||||
const token = jwt.sign({ user: 'AUTH_DISABLED_USER' }, common.secret_key);
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Authenticate', msg: 'User Disabled Authentication' });
|
||||
res.status(200).json({ token: token });
|
||||
}
|
||||
else if (+common.appConfig.SSO.rtlSSO) {
|
||||
if (authenticateWith === 'JWT' && jwt.verify(authenticationValue, common.secret_key)) {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Authenticate', msg: 'User Authenticated' });
|
||||
res.status(406).json({ message: 'SSO Authentication Error', error: 'Login with Password is not allowed with SSO.' });
|
||||
|
|
|
|||
|
|
@ -40,11 +40,12 @@ export class Authentication {
|
|||
}
|
||||
}
|
||||
export class ApplicationConfig {
|
||||
constructor(defaultNodeIndex, selectedNodeIndex, dbDirectoryPath, rtlConfFilePath, rtlPass, multiPass, multiPassHashed, allowPasswordUpdate, enable2FA, secret2FA, SSO, nodes) {
|
||||
constructor(defaultNodeIndex, selectedNodeIndex, dbDirectoryPath, rtlConfFilePath, disableAuth, rtlPass, multiPass, multiPassHashed, allowPasswordUpdate, enable2FA, secret2FA, SSO, nodes) {
|
||||
this.defaultNodeIndex = defaultNodeIndex;
|
||||
this.selectedNodeIndex = selectedNodeIndex;
|
||||
this.dbDirectoryPath = dbDirectoryPath;
|
||||
this.rtlConfFilePath = rtlConfFilePath;
|
||||
this.disableAuth = disableAuth;
|
||||
this.rtlPass = rtlPass;
|
||||
this.multiPass = multiPass;
|
||||
this.multiPassHashed = multiPassHashed;
|
||||
|
|
|
|||
|
|
@ -118,9 +118,18 @@ export class ConfigService {
|
|||
this.validateNodeConfig = (config) => {
|
||||
config.allowPasswordUpdate = true;
|
||||
if ((process?.env?.RTL_SSO && +process?.env?.RTL_SSO === 0) || (typeof process?.env?.RTL_SSO === 'undefined' && +config.SSO.rtlSSO === 0)) {
|
||||
if (process?.env?.APP_PASSWORD && process?.env?.APP_PASSWORD.trim() !== '') {
|
||||
if (!!process?.env?.DISABLE_AUTH || !!config.disableAuth) {
|
||||
config.allowPasswordUpdate = false;
|
||||
config.enable2FA = false;
|
||||
this.logger.log({ selectedNode: this.common.selectedNode, level: 'WARN', fileName: 'Config', msg: 'Authentication is Disabled via environment or config' });
|
||||
if (process?.env?.APP_PASSWORD && process?.env?.APP_PASSWORD.trim() !== '') {
|
||||
this.errMsg = this.errMsg + '\nRTL Password cannot be set with disabled authentication. Please remove disableAuth option or password.';
|
||||
}
|
||||
}
|
||||
else if (process?.env?.APP_PASSWORD && process?.env?.APP_PASSWORD.trim() !== '') {
|
||||
config.rtlPass = this.hash.update(process?.env?.APP_PASSWORD).digest('hex');
|
||||
config.allowPasswordUpdate = false;
|
||||
this.logger.log({ selectedNode: this.common.selectedNode, level: 'WARN', fileName: 'Config', msg: 'Passing APP_PASSWORD via environment is suggested for standalone RTL application' });
|
||||
}
|
||||
else if (config.multiPassHashed && config.multiPassHashed !== '') {
|
||||
config.rtlPass = config.multiPassHashed;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue