diff options
author | Chocobozzz <me@florianbigard.com> | 2021-02-25 15:25:48 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-02-25 15:25:48 +0100 |
commit | e7812bf0919ebc8e41d53ff981e1fbf77282e86f (patch) | |
tree | 70fd8cbe537ea82cf3d0f0949cf1e91baa083389 | |
parent | 031ea8efed6979cb01d0a7857cea6aa27270ceb7 (diff) | |
download | PeerTube-e7812bf0919ebc8e41d53ff981e1fbf77282e86f.tar.gz PeerTube-e7812bf0919ebc8e41d53ff981e1fbf77282e86f.tar.zst PeerTube-e7812bf0919ebc8e41d53ff981e1fbf77282e86f.zip |
Add refresh_token_expires_in to oauth res
-rw-r--r-- | server/lib/auth.ts | 1 | ||||
-rw-r--r-- | server/lib/oauth-model.ts | 12 |
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' | |||
4 | import { UserModel } from '../models/account/user' | 4 | import { UserModel } from '../models/account/user' |
5 | import { OAuthClientModel } from '../models/oauth/oauth-client' | 5 | import { OAuthClientModel } from '../models/oauth/oauth-client' |
6 | import { OAuthTokenModel } from '../models/oauth/oauth-token' | 6 | import { OAuthTokenModel } from '../models/oauth/oauth-token' |
7 | import { LRU_CACHE } from '../initializers/constants' | 7 | import { LRU_CACHE, OAUTH_LIFETIME } from '../initializers/constants' |
8 | import { Transaction } from 'sequelize' | 8 | import { Transaction } from 'sequelize' |
9 | import { CONFIG } from '../initializers/config' | 9 | import { CONFIG } from '../initializers/config' |
10 | import * as LRUCache from 'lru-cache' | 10 | import * 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 | // --------------------------------------------------------------------------- |