aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/oauth-model.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/oauth-model.ts')
-rw-r--r--server/lib/oauth-model.ts54
1 files changed, 25 insertions, 29 deletions
diff --git a/server/lib/oauth-model.ts b/server/lib/oauth-model.ts
index 9aa3ea52f..d91b00c55 100644
--- a/server/lib/oauth-model.ts
+++ b/server/lib/oauth-model.ts
@@ -24,39 +24,36 @@ function getRefreshToken (refreshToken: string) {
24 return db.OAuthToken.getByRefreshTokenAndPopulateClient(refreshToken) 24 return db.OAuthToken.getByRefreshTokenAndPopulateClient(refreshToken)
25} 25}
26 26
27function getUser (username: string, password: string) { 27async function getUser (username: string, password: string) {
28 logger.debug('Getting User (username: ' + username + ', password: ******).') 28 logger.debug('Getting User (username: ' + username + ', password: ******).')
29 29
30 return db.User.getByUsername(username).then(user => { 30 const user = await db.User.getByUsername(username)
31 if (!user) return null 31 if (!user) return null
32 32
33 return user.isPasswordMatch(password).then(passwordMatch => { 33 const passwordMatch = await user.isPasswordMatch(password)
34 if (passwordMatch === false) return null 34 if (passwordMatch === false) return null
35 35
36 return user 36 return user
37 })
38 })
39} 37}
40 38
41function revokeToken (token: TokenInfo) { 39async function revokeToken (tokenInfo: TokenInfo) {
42 return db.OAuthToken.getByRefreshTokenAndPopulateUser(token.refreshToken).then(tokenDB => { 40 const token = await db.OAuthToken.getByRefreshTokenAndPopulateUser(tokenInfo.refreshToken)
43 if (tokenDB) tokenDB.destroy() 41 if (token) token.destroy()
44 42
45 /* 43 /*
46 * Thanks to https://github.com/manjeshpv/node-oauth2-server-implementation/blob/master/components/oauth/mongo-models.js 44 * Thanks to https://github.com/manjeshpv/node-oauth2-server-implementation/blob/master/components/oauth/mongo-models.js
47 * "As per the discussion we need set older date 45 * "As per the discussion we need set older date
48 * revokeToken will expected return a boolean in future version 46 * revokeToken will expected return a boolean in future version
49 * https://github.com/oauthjs/node-oauth2-server/pull/274 47 * https://github.com/oauthjs/node-oauth2-server/pull/274
50 * https://github.com/oauthjs/node-oauth2-server/issues/290" 48 * https://github.com/oauthjs/node-oauth2-server/issues/290"
51 */ 49 */
52 const expiredToken = tokenDB 50 const expiredToken = token
53 expiredToken.refreshTokenExpiresAt = new Date('2015-05-28T06:59:53.000Z') 51 expiredToken.refreshTokenExpiresAt = new Date('2015-05-28T06:59:53.000Z')
54 52
55 return expiredToken 53 return expiredToken
56 })
57} 54}
58 55
59function saveToken (token: TokenInfo, client: OAuthClientInstance, user: UserInstance) { 56async function saveToken (token: TokenInfo, client: OAuthClientInstance, user: UserInstance) {
60 logger.debug('Saving token ' + token.accessToken + ' for client ' + client.id + ' and user ' + user.id + '.') 57 logger.debug('Saving token ' + token.accessToken + ' for client ' + client.id + ' and user ' + user.id + '.')
61 58
62 const tokenToCreate = { 59 const tokenToCreate = {
@@ -68,11 +65,10 @@ function saveToken (token: TokenInfo, client: OAuthClientInstance, user: UserIns
68 userId: user.id 65 userId: user.id
69 } 66 }
70 67
71 return db.OAuthToken.create(tokenToCreate).then(tokenCreated => { 68 const tokenCreated = await db.OAuthToken.create(tokenToCreate)
72 const tokenToReturn = Object.assign(tokenCreated, { client, user }) 69 const tokenToReturn = Object.assign(tokenCreated, { client, user })
73 70
74 return tokenToReturn 71 return tokenToReturn
75 })
76} 72}
77 73
78// --------------------------------------------------------------------------- 74// ---------------------------------------------------------------------------