@@ -185,7 +185,7 @@ OAuthClient.prototype.createToken = function createToken(uri) {
185
185
const authResponse = res . json ? res : null ;
186
186
const json = ( authResponse && authResponse . json ) || res ;
187
187
this . token . setToken ( json ) ;
188
- this . log ( 'info' , 'Create Token response is : ' , JSON . stringify ( authResponse . json , null , 2 ) ) ;
188
+ this . log ( 'info' , 'Create Token response is : ' , JSON . stringify ( authResponse && authResponse . json , null , 2 ) ) ;
189
189
return authResponse ;
190
190
} )
191
191
. catch ( ( e ) => {
@@ -226,7 +226,7 @@ OAuthClient.prototype.refresh = function refresh() {
226
226
const authResponse = res . json ? res : null ;
227
227
const json = ( authResponse && authResponse . json ) || res ;
228
228
this . token . setToken ( json ) ;
229
- this . log ( 'info' , 'Refresh Token () response is : ' , JSON . stringify ( authResponse . json , null , 2 ) ) ;
229
+ this . log ( 'info' , 'Refresh Token () response is : ' , JSON . stringify ( authResponse && authResponse . json , null , 2 ) ) ;
230
230
return authResponse ;
231
231
} )
232
232
. catch ( ( e ) => {
@@ -270,8 +270,7 @@ OAuthClient.prototype.refreshUsingToken = function refreshUsingToken(refresh_tok
270
270
this . token . setToken ( json ) ;
271
271
this . log (
272
272
'info' ,
273
- 'Refresh usingToken () response is : ' ,
274
- JSON . stringify ( authResponse . json , null , 2 ) ,
273
+ 'Refresh usingToken () response is : ' , JSON . stringify ( authResponse && authResponse . json , null , 2 ) ,
275
274
) ;
276
275
return authResponse ;
277
276
} )
@@ -318,7 +317,7 @@ OAuthClient.prototype.revoke = function revoke(params) {
318
317
. then ( ( res ) => {
319
318
const authResponse = res . json ? res : null ;
320
319
this . token . clearToken ( ) ;
321
- this . log ( 'info' , 'Revoke Token () response is : ' , JSON . stringify ( authResponse . json , null , 2 ) ) ;
320
+ this . log ( 'info' , 'Revoke Token () response is : ' , JSON . stringify ( authResponse && authResponse . json , null , 2 ) ) ;
322
321
return authResponse ;
323
322
} )
324
323
. catch ( ( e ) => {
@@ -353,8 +352,7 @@ OAuthClient.prototype.getUserInfo = function getUserInfo() {
353
352
const authResponse = res . json ? res : null ;
354
353
this . log (
355
354
'info' ,
356
- 'The Get User Info () response is : ' ,
357
- JSON . stringify ( authResponse . json , null , 2 ) ,
355
+ 'The Get User Info () response is : ' , JSON . stringify ( authResponse && authResponse . json , null , 2 ) ,
358
356
) ;
359
357
return authResponse ;
360
358
} )
@@ -403,8 +401,15 @@ OAuthClient.prototype.makeApiCall = function makeApiCall(params) {
403
401
resolve ( this . getTokenRequest ( request ) ) ;
404
402
} )
405
403
. then ( ( res ) => {
406
- const authResponse = res . json ? res : null ;
404
+ const { body , ... authResponse } = res ;
407
405
this . log ( 'info' , 'The makeAPICall () response is : ' , JSON . stringify ( authResponse . json , null , 2 ) ) ;
406
+
407
+ if ( authResponse . json === null && body ) {
408
+ return {
409
+ ...authResponse ,
410
+ body : body
411
+ }
412
+ }
408
413
return authResponse ;
409
414
} )
410
415
. catch ( ( e ) => {
@@ -477,8 +482,7 @@ OAuthClient.prototype.getKeyFromJWKsURI = function getKeyFromJWKsURI(id_token, k
477
482
. then ( ( response ) => {
478
483
if ( Number ( response . status ) !== 200 ) throw new Error ( 'Could not reach JWK endpoint' ) ;
479
484
// Find the key by KID
480
- const responseBody = JSON . parse ( response . data ) ;
481
- const key = responseBody . keys . find ( ( el ) => el . kid === kid ) ;
485
+ const key = response . data . keys . find ( ( el ) => el . kid === kid ) ;
482
486
const cert = this . getPublicKey ( key . n , key . e ) ;
483
487
484
488
return jwt . verify ( id_token , cert ) ;
0 commit comments