aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-25 15:25:48 +0100
committerChocobozzz <me@florianbigard.com>2021-02-25 15:25:48 +0100
commite7812bf0919ebc8e41d53ff981e1fbf77282e86f (patch)
tree70fd8cbe537ea82cf3d0f0949cf1e91baa083389 /server/lib
parent031ea8efed6979cb01d0a7857cea6aa27270ceb7 (diff)
downloadPeerTube-e7812bf0919ebc8e41d53ff981e1fbf77282e86f.tar.gz
PeerTube-e7812bf0919ebc8e41d53ff981e1fbf77282e86f.tar.zst
PeerTube-e7812bf0919ebc8e41d53ff981e1fbf77282e86f.zip
Add refresh_token_expires_in to oauth res
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/auth.ts1
-rw-r--r--server/lib/oauth-model.ts12
2 files changed, 11 insertions, 2 deletions
diff --git a/server/lib/auth.ts b/server/lib/auth.ts
index 466c9bdd4..dbd421a7b 100644
--- a/server/lib/auth.ts
+++ b/server/lib/auth.ts
@@ -19,6 +19,7 @@ const oAuthServer = new OAuthServer({
19 useErrorHandler: true, 19 useErrorHandler: true,
20 accessTokenLifetime: OAUTH_LIFETIME.ACCESS_TOKEN, 20 accessTokenLifetime: OAUTH_LIFETIME.ACCESS_TOKEN,
21 refreshTokenLifetime: OAUTH_LIFETIME.REFRESH_TOKEN, 21 refreshTokenLifetime: OAUTH_LIFETIME.REFRESH_TOKEN,
22 allowExtendedTokenAttributes: true,
22 continueMiddleware: true, 23 continueMiddleware: true,
23 model: require('./oauth-model') 24 model: require('./oauth-model')
24}) 25})
diff --git a/server/lib/oauth-model.ts b/server/lib/oauth-model.ts
index 3f8b8e618..75aee2567 100644
--- a/server/lib/oauth-model.ts
+++ b/server/lib/oauth-model.ts
@@ -4,7 +4,7 @@ import { logger } from '../helpers/logger'
4import { UserModel } from '../models/account/user' 4import { UserModel } from '../models/account/user'
5import { OAuthClientModel } from '../models/oauth/oauth-client' 5import { OAuthClientModel } from '../models/oauth/oauth-client'
6import { OAuthTokenModel } from '../models/oauth/oauth-token' 6import { OAuthTokenModel } from '../models/oauth/oauth-token'
7import { LRU_CACHE } from '../initializers/constants' 7import { LRU_CACHE, OAUTH_LIFETIME } from '../initializers/constants'
8import { Transaction } from 'sequelize' 8import { Transaction } from 'sequelize'
9import { CONFIG } from '../initializers/config' 9import { CONFIG } from '../initializers/config'
10import * as LRUCache from 'lru-cache' 10import * as LRUCache from 'lru-cache'
@@ -192,7 +192,15 @@ async function saveToken (token: TokenInfo, client: OAuthClientModel, user: User
192 user.lastLoginDate = new Date() 192 user.lastLoginDate = new Date()
193 await user.save() 193 await user.save()
194 194
195 return Object.assign(tokenCreated, { client, user }) 195 return {
196 accessToken: tokenCreated.accessToken,
197 accessTokenExpiresAt: tokenCreated.accessTokenExpiresAt,
198 refreshToken: tokenCreated.refreshToken,
199 refreshTokenExpiresAt: tokenCreated.refreshTokenExpiresAt,
200 client,
201 user,
202 refresh_token_expires_in: Math.floor((tokenCreated.refreshTokenExpiresAt.getTime() - new Date().getTime()) / 1000)
203 }
196} 204}
197 205
198// --------------------------------------------------------------------------- 206// ---------------------------------------------------------------------------