X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Fauth.js;h=5f4c7776601ceb0cbcd4117212c22c3ee8160382;hb=313dfe99cf8f763b36f333c5072e2430a6b7941f;hp=a885d492eb2a68cf5f9e572b02fc01188d01ca40;hpb=33ee47f3ca0322ccb19153cafa1c1f7b886dc61a;p=perso%2FImmae%2FProjets%2FNodejs%2FSurfer.git diff --git a/src/auth.js b/src/auth.js index a885d49..5f4c777 100644 --- a/src/auth.js +++ b/src/auth.js @@ -19,11 +19,13 @@ const LOGIN_TOKEN_PREFIX = 'login-'; const API_TOKEN_PREFIX = 'api-'; if (AUTH_METHOD === 'ldap') { - console.log('Use ldap auth'); + console.log('Using ldap auth'); } else { - console.log(`Use local auth file ${LOCAL_AUTH_FILE}`); + console.log(`Using local auth file at: ${LOCAL_AUTH_FILE}`); } +var gConfig = {}; + var tokenStore = { data: {}, save: function () { @@ -53,7 +55,7 @@ var tokenStore = { // load token store data if any try { - console.log(`Using tokenstore file: ${TOKENSTORE_FILE}`); + console.log(`Using tokenstore file at: ${TOKENSTORE_FILE}`); tokenStore.data = JSON.parse(fs.readFileSync(TOKENSTORE_FILE, 'utf-8')); } catch (e) { // start with empty token store @@ -103,6 +105,10 @@ function verifyUser(username, password, callback) { } } +exports.init = function (config) { + gConfig = config; +}; + exports.login = function (req, res, next) { verifyUser(req.body.username, req.body.password, function (error, user) { if (error) return next(new HttpError(401, 'Invalid credentials')); @@ -130,6 +136,11 @@ exports.verify = function (req, res, next) { }; +exports.verifyIfNeeded = function (req, res, next) { + if (!gConfig.folderListingEnabled) return exports.verify(req, res, next); + next(); +}; + exports.logout = function (req, res, next) { var accessToken = req.query.access_token || req.body.accessToken;