@@ -62,6 +62,7 @@ class TokenHandler {
6262 this . requireClientAuthentication = options . requireClientAuthentication || { } ;
6363 this . alwaysIssueNewRefreshToken = options . alwaysIssueNewRefreshToken !== false ;
6464 this . enablePlainPKCE = options . enablePlainPKCE === true ;
65+ this . requestProcessor = options . requestProcessor ;
6566 }
6667
6768 /**
@@ -86,8 +87,13 @@ class TokenHandler {
8687 }
8788
8889 try {
89- const client = await this . getClient ( request , response ) ;
90- const data = await this . handleGrantType ( request , client ) ;
90+ const body = this . requestProcessor ?. ( request ) ?? request . body ;
91+ const req = new Request ( {
92+ ...request ,
93+ body,
94+ } ) ;
95+ const client = await this . getClient ( req , response ) ;
96+ const data = await this . handleGrantType ( req , client ) ;
9197 const model = new TokenModel ( data , {
9298 allowExtendedTokenAttributes : this . allowExtendedTokenAttributes ,
9399 } ) ;
@@ -146,7 +152,9 @@ class TokenHandler {
146152 }
147153
148154 try {
149- const client = await ( isAssertion ? this . model . getClientFromAssertion ?. ( credentials ) : this . model . getClient ( credentials . clientId , credentials . clientSecret ) ) ;
155+ const client = await ( isAssertion
156+ ? this . model . getClientFromAssertion ?. ( credentials )
157+ : this . model . getClient ( credentials . clientId , credentials . clientSecret ) ) ;
150158
151159 if ( ! client ) {
152160 throw new InvalidClientError ( 'Invalid client: client is invalid' ) ;
@@ -204,7 +212,11 @@ class TokenHandler {
204212 }
205213
206214 if ( this . isClientAssertionRequest ( request ) ) {
207- return { clientId : request . body . client_id , clientAssertion : request . body . client_assertion , clientAssertionType : request . body . client_assertion_type } ;
215+ return {
216+ clientId : request . body . client_id ,
217+ clientAssertion : request . body . client_assertion ,
218+ clientAssertionType : request . body . client_assertion_type ,
219+ } ;
208220 }
209221
210222 if ( pkce . isPKCERequest ( { grantType, codeVerifier } ) ) {
0 commit comments