diff options
Diffstat (limited to 'server/lib/oauth-model.js')
-rw-r--r-- | server/lib/oauth-model.js | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/server/lib/oauth-model.js b/server/lib/oauth-model.js index d9f8b175a..45f796796 100644 --- a/server/lib/oauth-model.js +++ b/server/lib/oauth-model.js | |||
@@ -8,12 +8,12 @@ const User = mongoose.model('User') | |||
8 | 8 | ||
9 | // See https://github.com/oauthjs/node-oauth2-server/wiki/Model-specification for the model specifications | 9 | // See https://github.com/oauthjs/node-oauth2-server/wiki/Model-specification for the model specifications |
10 | const OAuthModel = { | 10 | const OAuthModel = { |
11 | getAccessToken: getAccessToken, | 11 | getAccessToken, |
12 | getClient: getClient, | 12 | getClient, |
13 | getRefreshToken: getRefreshToken, | 13 | getRefreshToken, |
14 | getUser: getUser, | 14 | getUser, |
15 | revokeToken: revokeToken, | 15 | revokeToken, |
16 | saveToken: saveToken | 16 | saveToken |
17 | } | 17 | } |
18 | 18 | ||
19 | // --------------------------------------------------------------------------- | 19 | // --------------------------------------------------------------------------- |
@@ -41,7 +41,22 @@ function getRefreshToken (refreshToken, callback) { | |||
41 | function getUser (username, password) { | 41 | function getUser (username, password) { |
42 | logger.debug('Getting User (username: ' + username + ', password: ' + password + ').') | 42 | logger.debug('Getting User (username: ' + username + ', password: ' + password + ').') |
43 | 43 | ||
44 | return User.getByUsernameAndPassword(username, password) | 44 | return User.getByUsername(username).then(function (user) { |
45 | if (!user) return null | ||
46 | |||
47 | // We need to return a promise | ||
48 | return new Promise(function (resolve, reject) { | ||
49 | return user.isPasswordMatch(password, function (err, isPasswordMatch) { | ||
50 | if (err) return reject(err) | ||
51 | |||
52 | if (isPasswordMatch === true) { | ||
53 | return resolve(user) | ||
54 | } | ||
55 | |||
56 | return resolve(null) | ||
57 | }) | ||
58 | }) | ||
59 | }) | ||
45 | } | 60 | } |
46 | 61 | ||
47 | function revokeToken (token) { | 62 | function revokeToken (token) { |