@@ -4,14 +4,13 @@ import { ProtectedRequest } from 'app-request';
4
4
import { Types } from 'mongoose' ;
5
5
import UserRepo from '../../../database/repository/UserRepo' ;
6
6
import { AuthFailureError , } from '../../../core/ApiError' ;
7
- import JWT , { ValidationParams } from '../../../core/JWT' ;
7
+ import JWT from '../../../core/JWT' ;
8
8
import KeystoreRepo from '../../../database/repository/KeystoreRepo' ;
9
9
import crypto from 'crypto' ;
10
10
import { validateTokenData , createTokens , getAccessToken } from '../../../auth/authUtils' ;
11
11
import validator , { ValidationSource } from '../../../helpers/validator' ;
12
12
import schema from './schema' ;
13
13
import asyncHandler from '../../../helpers/asyncHandler' ;
14
- import { tokenInfo } from '../../../config' ;
15
14
16
15
const router = express . Router ( ) ;
17
16
@@ -21,20 +20,17 @@ router.post('/refresh',
21
20
req . accessToken = getAccessToken ( req . headers . authorization ) ; // Express headers are auto converted to lowercase
22
21
23
22
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 ) ;
26
24
27
25
const user = await UserRepo . findById ( new Types . ObjectId ( accessTokenPayload . sub ) ) ;
28
26
if ( ! user ) throw new AuthFailureError ( 'User not registered' ) ;
29
27
req . user = user ;
30
28
31
- validateTokenData ( accessTokenPayload , req . user . _id ) ;
29
+ const refreshTokenPayload = await JWT . validate ( req . body . refreshToken ) ;
30
+ validateTokenData ( refreshTokenPayload ) ;
32
31
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' ) ;
38
34
39
35
const keystore = await KeystoreRepo . find (
40
36
req . user . _id ,
0 commit comments