From e7812bf0919ebc8e41d53ff981e1fbf77282e86f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 25 Feb 2021 15:25:48 +0100 Subject: Add refresh_token_expires_in to oauth res --- server/lib/auth.ts | 1 + 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({ useErrorHandler: true, accessTokenLifetime: OAUTH_LIFETIME.ACCESS_TOKEN, refreshTokenLifetime: OAUTH_LIFETIME.REFRESH_TOKEN, + allowExtendedTokenAttributes: true, continueMiddleware: true, model: require('./oauth-model') }) 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' import { UserModel } from '../models/account/user' import { OAuthClientModel } from '../models/oauth/oauth-client' import { OAuthTokenModel } from '../models/oauth/oauth-token' -import { LRU_CACHE } from '../initializers/constants' +import { LRU_CACHE, OAUTH_LIFETIME } from '../initializers/constants' import { Transaction } from 'sequelize' import { CONFIG } from '../initializers/config' import * as LRUCache from 'lru-cache' @@ -192,7 +192,15 @@ async function saveToken (token: TokenInfo, client: OAuthClientModel, user: User user.lastLoginDate = new Date() await user.save() - return Object.assign(tokenCreated, { client, user }) + return { + accessToken: tokenCreated.accessToken, + accessTokenExpiresAt: tokenCreated.accessTokenExpiresAt, + refreshToken: tokenCreated.refreshToken, + refreshTokenExpiresAt: tokenCreated.refreshTokenExpiresAt, + client, + user, + refresh_token_expires_in: Math.floor((tokenCreated.refreshTokenExpiresAt.getTime() - new Date().getTime()) / 1000) + } } // --------------------------------------------------------------------------- -- cgit v1.2.3