diff options
Diffstat (limited to 'server/lib/oauth-model.ts')
-rw-r--r-- | server/lib/oauth-model.ts | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/server/lib/oauth-model.ts b/server/lib/oauth-model.ts index 3bdf0f478..7cf42e94c 100644 --- a/server/lib/oauth-model.ts +++ b/server/lib/oauth-model.ts | |||
@@ -1,27 +1,30 @@ | |||
1 | import { OAuthClientInstance, UserInstance } from '../models' | ||
1 | import { database as db } from '../initializers/database' | 2 | import { database as db } from '../initializers/database' |
2 | import { logger } from '../helpers' | 3 | import { logger } from '../helpers' |
3 | 4 | ||
5 | type TokenInfo = { accessToken: string, refreshToken: string, accessTokenExpiresAt: Date, refreshTokenExpiresAt: Date } | ||
6 | |||
4 | // --------------------------------------------------------------------------- | 7 | // --------------------------------------------------------------------------- |
5 | 8 | ||
6 | function getAccessToken (bearerToken) { | 9 | function getAccessToken (bearerToken: string) { |
7 | logger.debug('Getting access token (bearerToken: ' + bearerToken + ').') | 10 | logger.debug('Getting access token (bearerToken: ' + bearerToken + ').') |
8 | 11 | ||
9 | return db.OAuthToken.getByTokenAndPopulateUser(bearerToken) | 12 | return db.OAuthToken.getByTokenAndPopulateUser(bearerToken) |
10 | } | 13 | } |
11 | 14 | ||
12 | function getClient (clientId, clientSecret) { | 15 | function getClient (clientId: string, clientSecret: string) { |
13 | logger.debug('Getting Client (clientId: ' + clientId + ', clientSecret: ' + clientSecret + ').') | 16 | logger.debug('Getting Client (clientId: ' + clientId + ', clientSecret: ' + clientSecret + ').') |
14 | 17 | ||
15 | return db.OAuthClient.getByIdAndSecret(clientId, clientSecret) | 18 | return db.OAuthClient.getByIdAndSecret(clientId, clientSecret) |
16 | } | 19 | } |
17 | 20 | ||
18 | function getRefreshToken (refreshToken) { | 21 | function getRefreshToken (refreshToken: string) { |
19 | logger.debug('Getting RefreshToken (refreshToken: ' + refreshToken + ').') | 22 | logger.debug('Getting RefreshToken (refreshToken: ' + refreshToken + ').') |
20 | 23 | ||
21 | return db.OAuthToken.getByRefreshTokenAndPopulateClient(refreshToken) | 24 | return db.OAuthToken.getByRefreshTokenAndPopulateClient(refreshToken) |
22 | } | 25 | } |
23 | 26 | ||
24 | function getUser (username, password) { | 27 | function getUser (username: string, password: string) { |
25 | logger.debug('Getting User (username: ' + username + ', password: ' + password + ').') | 28 | logger.debug('Getting User (username: ' + username + ', password: ' + password + ').') |
26 | 29 | ||
27 | return db.User.getByUsername(username).then(function (user) { | 30 | return db.User.getByUsername(username).then(function (user) { |
@@ -42,7 +45,7 @@ function getUser (username, password) { | |||
42 | }) | 45 | }) |
43 | } | 46 | } |
44 | 47 | ||
45 | function revokeToken (token) { | 48 | function revokeToken (token: TokenInfo) { |
46 | return db.OAuthToken.getByRefreshTokenAndPopulateUser(token.refreshToken).then(function (tokenDB) { | 49 | return db.OAuthToken.getByRefreshTokenAndPopulateUser(token.refreshToken).then(function (tokenDB) { |
47 | if (tokenDB) tokenDB.destroy() | 50 | if (tokenDB) tokenDB.destroy() |
48 | 51 | ||
@@ -60,7 +63,7 @@ function revokeToken (token) { | |||
60 | }) | 63 | }) |
61 | } | 64 | } |
62 | 65 | ||
63 | function saveToken (token, client, user) { | 66 | function saveToken (token: TokenInfo, client: OAuthClientInstance, user: UserInstance) { |
64 | logger.debug('Saving token ' + token.accessToken + ' for client ' + client.id + ' and user ' + user.id + '.') | 67 | logger.debug('Saving token ' + token.accessToken + ' for client ' + client.id + ' and user ' + user.id + '.') |
65 | 68 | ||
66 | const tokenToCreate = { | 69 | const tokenToCreate = { |