@@ -4,14 +4,13 @@ import { ProtectedRequest } from 'app-request';
44import { Types } from 'mongoose' ;
55import UserRepo from '../../../database/repository/UserRepo' ;
66import { AuthFailureError , } from '../../../core/ApiError' ;
7- import JWT , { ValidationParams } from '../../../core/JWT' ;
7+ import JWT from '../../../core/JWT' ;
88import KeystoreRepo from '../../../database/repository/KeystoreRepo' ;
99import crypto from 'crypto' ;
1010import { validateTokenData , createTokens , getAccessToken } from '../../../auth/authUtils' ;
1111import validator , { ValidationSource } from '../../../helpers/validator' ;
1212import schema from './schema' ;
1313import asyncHandler from '../../../helpers/asyncHandler' ;
14- import { tokenInfo } from '../../../config' ;
1514
1615const router = express . Router ( ) ;
1716
@@ -21,20 +20,17 @@ router.post('/refresh',
2120 req . accessToken = getAccessToken ( req . headers . authorization ) ; // Express headers are auto converted to lowercase
2221
2322 const accessTokenPayload = await JWT . decode ( req . accessToken ) ;
24- if ( ! accessTokenPayload . sub || ! Types . ObjectId . isValid ( accessTokenPayload . sub ) )
25- throw new AuthFailureError ( 'Invalid access token' ) ;
23+ validateTokenData ( accessTokenPayload ) ;
2624
2725 const user = await UserRepo . findById ( new Types . ObjectId ( accessTokenPayload . sub ) ) ;
2826 if ( ! user ) throw new AuthFailureError ( 'User not registered' ) ;
2927 req . user = user ;
3028
31- validateTokenData ( accessTokenPayload , req . user . _id ) ;
29+ const refreshTokenPayload = await JWT . validate ( req . body . refreshToken ) ;
30+ validateTokenData ( refreshTokenPayload ) ;
3231
33- const refreshTokenPayload = await JWT . validate ( req . body . refreshToken ,
34- new ValidationParams (
35- tokenInfo . issuer ,
36- tokenInfo . audience ,
37- req . user . _id . toHexString ( ) ) ) ;
32+ if ( accessTokenPayload . sub !== refreshTokenPayload . sub )
33+ throw new AuthFailureError ( 'Invalid access token' ) ;
3834
3935 const keystore = await KeystoreRepo . find (
4036 req . user . _id ,
0 commit comments