aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/initializers/database.js1
-rw-r--r--server/lib/oauth-model.js9
-rw-r--r--server/models/oauth-client.js2
-rw-r--r--server/models/oauth-token.js6
4 files changed, 9 insertions, 9 deletions
diff --git a/server/initializers/database.js b/server/initializers/database.js
index 4a19bc230..8626895ee 100644
--- a/server/initializers/database.js
+++ b/server/initializers/database.js
@@ -23,6 +23,7 @@ const database = {
23} 23}
24 24
25function connect () { 25function connect () {
26 mongoose.Promise = global.Promise
26 mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname) 27 mongoose.connect('mongodb://' + host + ':' + port + '/' + dbname)
27 mongoose.connection.on('error', function () { 28 mongoose.connection.on('error', function () {
28 throw new Error('Mongodb connection error.') 29 throw new Error('Mongodb connection error.')
diff --git a/server/lib/oauth-model.js b/server/lib/oauth-model.js
index 555a54e90..d9f8b175a 100644
--- a/server/lib/oauth-model.js
+++ b/server/lib/oauth-model.js
@@ -62,7 +62,7 @@ function revokeToken (token) {
62} 62}
63 63
64function saveToken (token, client, user) { 64function saveToken (token, client, user) {
65 logger.debug('Saving token for client ' + client.id + ' and user ' + user.id + '.') 65 logger.debug('Saving token ' + token.accessToken + ' for client ' + client.id + ' and user ' + user.id + '.')
66 66
67 const tokenObj = new OAuthToken({ 67 const tokenObj = new OAuthToken({
68 accessToken: token.accessToken, 68 accessToken: token.accessToken,
@@ -73,13 +73,12 @@ function saveToken (token, client, user) {
73 user: user.id 73 user: user.id
74 }) 74 })
75 75
76 return tokenObj.save(function (err, tokenCreated) { 76 return tokenObj.save().then(function (tokenCreated) {
77 if (err) throw err // node-oauth2-server library uses Promise.try
78
79 tokenCreated.client = client 77 tokenCreated.client = client
80 tokenCreated.user = user 78 tokenCreated.user = user
81
82 return tokenCreated 79 return tokenCreated
80 }).catch(function (err) {
81 throw err
83 }) 82 })
84} 83}
85 84
diff --git a/server/models/oauth-client.js b/server/models/oauth-client.js
index 830f68857..45834c5a5 100644
--- a/server/models/oauth-client.js
+++ b/server/models/oauth-client.js
@@ -29,5 +29,5 @@ function loadFirstClient (callback) {
29} 29}
30 30
31function getByIdAndSecret (id, clientSecret) { 31function getByIdAndSecret (id, clientSecret) {
32 return this.findOne({ _id: id, clientSecret: clientSecret }) 32 return this.findOne({ _id: id, clientSecret: clientSecret }).exec()
33} 33}
diff --git a/server/models/oauth-token.js b/server/models/oauth-token.js
index 23c698732..f6a814c36 100644
--- a/server/models/oauth-token.js
+++ b/server/models/oauth-token.js
@@ -28,7 +28,7 @@ mongoose.model('OAuthToken', OAuthTokenSchema)
28// --------------------------------------------------------------------------- 28// ---------------------------------------------------------------------------
29 29
30function getByRefreshTokenAndPopulateClient (refreshToken) { 30function getByRefreshTokenAndPopulateClient (refreshToken) {
31 return this.findOne({ refreshToken: refreshToken }).populate('client').then(function (token) { 31 return this.findOne({ refreshToken: refreshToken }).populate('client').exec().then(function (token) {
32 if (!token) return token 32 if (!token) return token
33 33
34 const tokenInfos = { 34 const tokenInfos = {
@@ -47,9 +47,9 @@ function getByRefreshTokenAndPopulateClient (refreshToken) {
47} 47}
48 48
49function getByTokenAndPopulateUser (bearerToken) { 49function getByTokenAndPopulateUser (bearerToken) {
50 return this.findOne({ accessToken: bearerToken }).populate('user') 50 return this.findOne({ accessToken: bearerToken }).populate('user').exec()
51} 51}
52 52
53function getByRefreshToken (refreshToken) { 53function getByRefreshToken (refreshToken) {
54 return this.findOne({ refreshToken: refreshToken }) 54 return this.findOne({ refreshToken: refreshToken }).exec()
55} 55}