Add refresh_token_expires_in to oauth res

pull/3782/head
Chocobozzz 2021-02-25 15:25:48 +01:00
parent 031ea8efed
commit e7812bf091
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 11 additions and 2 deletions

View File

@ -19,6 +19,7 @@ const oAuthServer = new OAuthServer({
useErrorHandler: true, useErrorHandler: true,
accessTokenLifetime: OAUTH_LIFETIME.ACCESS_TOKEN, accessTokenLifetime: OAUTH_LIFETIME.ACCESS_TOKEN,
refreshTokenLifetime: OAUTH_LIFETIME.REFRESH_TOKEN, refreshTokenLifetime: OAUTH_LIFETIME.REFRESH_TOKEN,
allowExtendedTokenAttributes: true,
continueMiddleware: true, continueMiddleware: true,
model: require('./oauth-model') model: require('./oauth-model')
}) })

View File

@ -4,7 +4,7 @@ import { logger } from '../helpers/logger'
import { UserModel } from '../models/account/user' import { UserModel } from '../models/account/user'
import { OAuthClientModel } from '../models/oauth/oauth-client' import { OAuthClientModel } from '../models/oauth/oauth-client'
import { OAuthTokenModel } from '../models/oauth/oauth-token' 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 { Transaction } from 'sequelize'
import { CONFIG } from '../initializers/config' import { CONFIG } from '../initializers/config'
import * as LRUCache from 'lru-cache' import * as LRUCache from 'lru-cache'
@ -192,7 +192,15 @@ async function saveToken (token: TokenInfo, client: OAuthClientModel, user: User
user.lastLoginDate = new Date() user.lastLoginDate = new Date()
await user.save() 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)
}
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------