diff options
Diffstat (limited to 'src/auth.js')
-rw-r--r-- | src/auth.js | 17 |
1 files changed, 14 insertions, 3 deletions
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-'; | |||
19 | const API_TOKEN_PREFIX = 'api-'; | 19 | const API_TOKEN_PREFIX = 'api-'; |
20 | 20 | ||
21 | if (AUTH_METHOD === 'ldap') { | 21 | if (AUTH_METHOD === 'ldap') { |
22 | console.log('Use ldap auth'); | 22 | console.log('Using ldap auth'); |
23 | } else { | 23 | } else { |
24 | console.log(`Use local auth file ${LOCAL_AUTH_FILE}`); | 24 | console.log(`Using local auth file at: ${LOCAL_AUTH_FILE}`); |
25 | } | 25 | } |
26 | 26 | ||
27 | var gConfig = {}; | ||
28 | |||
27 | var tokenStore = { | 29 | var tokenStore = { |
28 | data: {}, | 30 | data: {}, |
29 | save: function () { | 31 | save: function () { |
@@ -53,7 +55,7 @@ var tokenStore = { | |||
53 | 55 | ||
54 | // load token store data if any | 56 | // load token store data if any |
55 | try { | 57 | try { |
56 | console.log(`Using tokenstore file: ${TOKENSTORE_FILE}`); | 58 | console.log(`Using tokenstore file at: ${TOKENSTORE_FILE}`); |
57 | tokenStore.data = JSON.parse(fs.readFileSync(TOKENSTORE_FILE, 'utf-8')); | 59 | tokenStore.data = JSON.parse(fs.readFileSync(TOKENSTORE_FILE, 'utf-8')); |
58 | } catch (e) { | 60 | } catch (e) { |
59 | // start with empty token store | 61 | // start with empty token store |
@@ -103,6 +105,10 @@ function verifyUser(username, password, callback) { | |||
103 | } | 105 | } |
104 | } | 106 | } |
105 | 107 | ||
108 | exports.init = function (config) { | ||
109 | gConfig = config; | ||
110 | }; | ||
111 | |||
106 | exports.login = function (req, res, next) { | 112 | exports.login = function (req, res, next) { |
107 | verifyUser(req.body.username, req.body.password, function (error, user) { | 113 | verifyUser(req.body.username, req.body.password, function (error, user) { |
108 | if (error) return next(new HttpError(401, 'Invalid credentials')); | 114 | if (error) return next(new HttpError(401, 'Invalid credentials')); |
@@ -130,6 +136,11 @@ exports.verify = function (req, res, next) { | |||
130 | 136 | ||
131 | }; | 137 | }; |
132 | 138 | ||
139 | exports.verifyIfNeeded = function (req, res, next) { | ||
140 | if (!gConfig.folderListingEnabled) return exports.verify(req, res, next); | ||
141 | next(); | ||
142 | }; | ||
143 | |||
133 | exports.logout = function (req, res, next) { | 144 | exports.logout = function (req, res, next) { |
134 | var accessToken = req.query.access_token || req.body.accessToken; | 145 | var accessToken = req.query.access_token || req.body.accessToken; |
135 | 146 | ||