@@ -169,7 +169,7 @@ OAuthClient.prototype.createToken = function createToken(uri) {
169
169
170
170
const request = {
171
171
url : OAuthClient . tokenEndpoint ,
172
- body,
172
+ data : body ,
173
173
method : 'POST' ,
174
174
headers : {
175
175
Authorization : `Basic ${ this . authHeader ( ) } ` ,
@@ -182,8 +182,8 @@ OAuthClient.prototype.createToken = function createToken(uri) {
182
182
resolve ( this . getTokenRequest ( request ) ) ;
183
183
} )
184
184
. then ( ( res ) => {
185
- const authResponse = res . json ? res : null ;
186
- const json = ( authResponse && authResponse . getJson ( ) ) || res ;
185
+ const { response , ... authResponse } = res . json ? res : null ;
186
+ const json = ( authResponse && authResponse . json ) || res ;
187
187
this . token . setToken ( json ) ;
188
188
this . log ( 'info' , 'Create Token response is : ' , JSON . stringify ( authResponse , null , 2 ) ) ;
189
189
return authResponse ;
@@ -210,7 +210,7 @@ OAuthClient.prototype.refresh = function refresh() {
210
210
211
211
const request = {
212
212
url : OAuthClient . tokenEndpoint ,
213
- body,
213
+ data : body ,
214
214
method : 'POST' ,
215
215
headers : {
216
216
Authorization : `Basic ${ this . authHeader ( ) } ` ,
@@ -223,7 +223,7 @@ OAuthClient.prototype.refresh = function refresh() {
223
223
resolve ( this . getTokenRequest ( request ) ) ;
224
224
} )
225
225
. then ( ( res ) => {
226
- const authResponse = res . json ? res : null ;
226
+ const { request , ... authResponse } = res . json ? res : null ;
227
227
const json = ( authResponse && authResponse . getJson ( ) ) || res ;
228
228
this . token . setToken ( json ) ;
229
229
this . log ( 'info' , 'Refresh Token () response is : ' , JSON . stringify ( authResponse , null , 2 ) ) ;
@@ -252,7 +252,7 @@ OAuthClient.prototype.refreshUsingToken = function refreshUsingToken(refresh_tok
252
252
253
253
const request = {
254
254
url : OAuthClient . tokenEndpoint ,
255
- body,
255
+ data : body ,
256
256
method : 'POST' ,
257
257
headers : {
258
258
Authorization : `Basic ${ this . authHeader ( ) } ` ,
@@ -265,7 +265,7 @@ OAuthClient.prototype.refreshUsingToken = function refreshUsingToken(refresh_tok
265
265
resolve ( this . getTokenRequest ( request ) ) ;
266
266
} )
267
267
. then ( ( res ) => {
268
- const authResponse = res . json ? res : null ;
268
+ const { request , ... authResponse } = res . json ? res : null ;
269
269
const json = ( authResponse && authResponse . getJson ( ) ) || res ;
270
270
this . token . setToken ( json ) ;
271
271
this . log (
@@ -303,7 +303,7 @@ OAuthClient.prototype.revoke = function revoke(params) {
303
303
304
304
const request = {
305
305
url : OAuthClient . revokeEndpoint ,
306
- body,
306
+ data : body ,
307
307
method : 'POST' ,
308
308
headers : {
309
309
Authorization : `Basic ${ this . authHeader ( ) } ` ,
@@ -315,7 +315,7 @@ OAuthClient.prototype.revoke = function revoke(params) {
315
315
316
316
resolve ( this . getTokenRequest ( request ) ) ;
317
317
} )
318
- . then ( ( authResponse ) => {
318
+ . then ( ( { request , ... authResponse } ) => {
319
319
this . token . clearToken ( ) ;
320
320
this . log ( 'info' , 'Revoke Token () response is : ' , JSON . stringify ( authResponse , null , 2 ) ) ;
321
321
return authResponse ;
@@ -349,7 +349,7 @@ OAuthClient.prototype.getUserInfo = function getUserInfo() {
349
349
resolve ( this . getTokenRequest ( request ) ) ;
350
350
} )
351
351
. then ( ( res ) => {
352
- const authResponse = res . json ? res : null ;
352
+ const { request , ... authResponse } = res . json ? res : null ;
353
353
this . log (
354
354
'info' ,
355
355
'The Get User Info () response is : ' ,
@@ -365,47 +365,43 @@ OAuthClient.prototype.getUserInfo = function getUserInfo() {
365
365
366
366
/**
367
367
* Make API call. Pass the url,method,headers using `params` object
368
- * *
369
- * @param {Object } params
368
+ *
369
+ * @param {params } params
370
+ * @param {string } params.url
371
+ * @param {string } params.method (optional) default is GET
372
+ * @param {Object } params.headers (optional)
373
+ * @param {Object } params.body (optional)
374
+ * @param {string } params.responseType (optional) default is json - options are json, text, stream, arraybuffer
370
375
* @returns {Promise }
371
376
*/
372
377
OAuthClient . prototype . makeApiCall = function makeApiCall ( params ) {
373
378
return new Promise ( ( resolve ) => {
374
379
params = params || { } ;
375
- const transport = params . transport ? params . transport : { responseType : 'text' } ;
380
+ const responseType = params . responseType ? params . responseType : 'json' ;
381
+
382
+ const baseHeaders = {
383
+ Authorization : `Bearer ${ this . getToken ( ) . access_token } ` ,
384
+ Accept : AuthResponse . _jsonContentType ,
385
+ 'User-Agent' : OAuthClient . user_agent ,
386
+ } ;
376
387
377
388
const headers =
378
389
params . headers && typeof params . headers === 'object'
379
- ? Object . assign (
380
- { } ,
381
- {
382
- Authorization : `Bearer ${ this . getToken ( ) . access_token } ` ,
383
- Accept : AuthResponse . _jsonContentType ,
384
- 'User-Agent' : OAuthClient . user_agent ,
385
- } ,
386
- params . headers
387
- )
388
- : Object . assign (
389
- { } ,
390
- {
391
- Authorization : `Bearer ${ this . getToken ( ) . access_token } ` ,
392
- Accept : AuthResponse . _jsonContentType ,
393
- 'User-Agent' : OAuthClient . user_agent ,
394
- }
395
- ) ;
390
+ ? Object . assign ( { } , baseHeaders , params . headers )
391
+ : Object . assign ( { } , baseHeaders ) ;
396
392
397
393
const request = {
398
394
url : params . url ,
399
395
method : params . method || 'GET' ,
400
396
headers,
401
- transport ,
397
+ responseType ,
402
398
} ;
403
399
404
- params . body && ( request . body = params . body ) ;
400
+ params . body && ( request . data = params . body ) ;
405
401
406
402
resolve ( this . getTokenRequest ( request ) ) ;
407
403
} )
408
- . then ( ( authResponse ) => {
404
+ . then ( ( { request , ... authResponse } ) => {
409
405
this . log ( 'info' , 'The makeAPICall () response is : ' , JSON . stringify ( authResponse , null , 2 ) ) ;
410
406
return authResponse ;
411
407
} )
@@ -552,7 +548,7 @@ OAuthClient.prototype.validateToken = function validateToken() {
552
548
* @returns response
553
549
*/
554
550
OAuthClient . prototype . loadResponse = function loadResponse ( request ) {
555
- return axios . get ( request ) . then ( ( response ) => response ) ;
551
+ return axios ( request ) . then ( ( response ) => response ) ;
556
552
} ;
557
553
558
554
/**
0 commit comments