Remove passport

This commit is contained in:
Johannes Zellner
2020-02-06 14:50:12 +01:00
parent 58d8f688e5
commit 12aa8ac0ad
8 changed files with 129 additions and 187 deletions

View File

@@ -34,7 +34,6 @@ let assert = require('assert'),
externalLdap = require('../externalldap.js'),
HttpError = require('connect-lastmile').HttpError,
HttpSuccess = require('connect-lastmile').HttpSuccess,
passport = require('passport'),
speakeasy = require('speakeasy'),
sysinfo = require('../sysinfo.js'),
system = require('../system.js'),
@@ -44,26 +43,23 @@ let assert = require('assert'),
updateChecker = require('../updatechecker.js');
function login(req, res, next) {
passport.authenticate('local', function (error, user) {
assert.strictEqual(typeof req.user, 'object');
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || null;
if (!req.user.ghost && !req.user.appPassword && req.user.twoFactorAuthenticationEnabled) {
if (!req.body.totpToken) return next(new HttpError(401, 'A totpToken must be provided'));
let verified = speakeasy.totp.verify({ secret: req.user.twoFactorAuthenticationSecret, encoding: 'base32', token: req.body.totpToken, window: 2 });
if (!verified) return next(new HttpError(401, 'Invalid totpToken'));
}
const auditSource = { authType: 'cli', ip: ip };
clients.issueDeveloperToken(req.user, auditSource, function (error, result) {
if (error) return next(new HttpError(500, error));
if (!user) return next(new HttpError(401, 'Invalid credentials'));
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || null;
if (!user.ghost && !user.appPassword && user.twoFactorAuthenticationEnabled) {
if (!req.body.totpToken) return next(new HttpError(401, 'A totpToken must be provided'));
let verified = speakeasy.totp.verify({ secret: user.twoFactorAuthenticationSecret, encoding: 'base32', token: req.body.totpToken, window: 2 });
if (!verified) return next(new HttpError(401, 'Invalid totpToken'));
}
const auditSource = { authType: 'cli', ip: ip };
clients.issueDeveloperToken(user, auditSource, function (error, result) {
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200, result));
});
})(req, res, next);
next(new HttpSuccess(200, result));
});
}
function logout(req, res) {