aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/oauth-model.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-06-10 22:15:25 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-06-10 22:15:25 +0200
commit69818c9394366b954b6ba3bd697bd9d2b09f2a16 (patch)
treead199a18ec3c322460d6f9523fc383ee562554e0 /server/lib/oauth-model.ts
parent4d4e5cd4dca78480ec7f40e747f424cd107376a4 (diff)
downloadPeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.gz
PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.zst
PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.zip
Type functions
Diffstat (limited to 'server/lib/oauth-model.ts')
-rw-r--r--server/lib/oauth-model.ts15
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 @@
1import { OAuthClientInstance, UserInstance } from '../models'
1import { database as db } from '../initializers/database' 2import { database as db } from '../initializers/database'
2import { logger } from '../helpers' 3import { logger } from '../helpers'
3 4
5type TokenInfo = { accessToken: string, refreshToken: string, accessTokenExpiresAt: Date, refreshTokenExpiresAt: Date }
6
4// --------------------------------------------------------------------------- 7// ---------------------------------------------------------------------------
5 8
6function getAccessToken (bearerToken) { 9function 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
12function getClient (clientId, clientSecret) { 15function 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
18function getRefreshToken (refreshToken) { 21function 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
24function getUser (username, password) { 27function 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
45function revokeToken (token) { 48function 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
63function saveToken (token, client, user) { 66function 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 = {