From d2d7a2e57748786a429459a0c46d5dc23d87ff59 Mon Sep 17 00:00:00 2001 From: Rajesh Gupta Date: Mon, 11 Mar 2024 21:57:20 -0700 Subject: [PATCH 1/2] fix authResponse.json issue --- package.json | 2 +- sample/app.js | 10 +++++----- src/OAuthClient.js | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 9d5a2c8d..e624c1fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "intuit-oauth", - "version": "4.1.0", + "version": "4.1.1", "description": "Intuit Node.js client for OAuth2.0 and OpenIDConnect", "main": "./src/OAuthClient.js", "scripts": { diff --git a/sample/app.js b/sample/app.js index 9c56f73f..fd57bc2a 100644 --- a/sample/app.js +++ b/sample/app.js @@ -72,7 +72,7 @@ app.get('/callback', function (req, res) { oauthClient .createToken(req.url) .then(function (authResponse) { - oauth2_token_json = JSON.stringify(authResponse.getJson(), null, 2); + oauth2_token_json = JSON.stringify(authResponse.json, null, 2); }) .catch(function (e) { console.error(e); @@ -95,8 +95,8 @@ app.get('/refreshAccessToken', function (req, res) { oauthClient .refresh() .then(function (authResponse) { - console.log(`The Refresh Token is ${JSON.stringify(authResponse.getJson())}`); - oauth2_token_json = JSON.stringify(authResponse.getJson(), null, 2); + console.log(`The Refresh Token is ${JSON.stringify(authResponse.json)}`); + oauth2_token_json = JSON.stringify(authResponse.json, null, 2); res.send(oauth2_token_json); }) .catch(function (e) { @@ -118,8 +118,8 @@ app.get('/getCompanyInfo', function (req, res) { oauthClient .makeApiCall({ url: `${url}v3/company/${companyID}/companyinfo/${companyID}` }) .then(function (authResponse) { - console.log(`The response for API call is :${JSON.stringify(authResponse)}`); - res.send(JSON.parse(authResponse.text())); + console.log(`The response for API call is :${JSON.stringify(authResponse.json)}`); + res.send(authResponse.json); }) .catch(function (e) { console.error(e); diff --git a/src/OAuthClient.js b/src/OAuthClient.js index c6b3b0d8..3ede239f 100644 --- a/src/OAuthClient.js +++ b/src/OAuthClient.js @@ -182,10 +182,10 @@ OAuthClient.prototype.createToken = function createToken(uri) { resolve(this.getTokenRequest(request)); }) .then((res) => { - const { response, ...authResponse } = res.json ? res : null; + const { request, ...authResponse } = res.json ? res : null; const json = (authResponse && authResponse.json) || res; this.token.setToken(json); - this.log('info', 'Create Token response is : ', JSON.stringify(authResponse, null, 2)); + this.log('info', 'Create Token response is : ', JSON.stringify(authResponse.json, null, 2)); return authResponse; }) .catch((e) => { @@ -224,9 +224,9 @@ OAuthClient.prototype.refresh = function refresh() { }) .then((res) => { const { request, ...authResponse } = res.json ? res : null; - const json = (authResponse && authResponse.getJson()) || res; + const json = (authResponse && authResponse.json) || res; this.token.setToken(json); - this.log('info', 'Refresh Token () response is : ', JSON.stringify(authResponse, null, 2)); + this.log('info', 'Refresh Token () response is : ', JSON.stringify(authResponse.json, null, 2)); return authResponse; }) .catch((e) => { @@ -266,7 +266,7 @@ OAuthClient.prototype.refreshUsingToken = function refreshUsingToken(refresh_tok }) .then((res) => { const { request, ...authResponse } = res.json ? res : null; - const json = (authResponse && authResponse.getJson()) || res; + const json = (authResponse && authResponse.json) || res; this.token.setToken(json); this.log( 'info', @@ -402,7 +402,7 @@ OAuthClient.prototype.makeApiCall = function makeApiCall(params) { resolve(this.getTokenRequest(request)); }) .then(({ request, ...authResponse }) => { - this.log('info', 'The makeAPICall () response is : ', JSON.stringify(authResponse, null, 2)); + this.log('info', 'The makeAPICall () response is : ', JSON.stringify(authResponse.json, null, 2)); return authResponse; }) .catch((e) => { From 2bd86f254cad30276e774bd5e16cedc8eb6768c1 Mon Sep 17 00:00:00 2001 From: Rajesh Gupta Date: Wed, 13 Mar 2024 11:01:37 -0700 Subject: [PATCH 2/2] correction to get response obj updated --- src/OAuthClient.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OAuthClient.js b/src/OAuthClient.js index 3ede239f..be7b87ed 100644 --- a/src/OAuthClient.js +++ b/src/OAuthClient.js @@ -182,7 +182,7 @@ OAuthClient.prototype.createToken = function createToken(uri) { resolve(this.getTokenRequest(request)); }) .then((res) => { - const { request, ...authResponse } = res.json ? res : null; + const { response, ...authResponse } = res.json ? res : null; const json = (authResponse && authResponse.json) || res; this.token.setToken(json); this.log('info', 'Create Token response is : ', JSON.stringify(authResponse.json, null, 2));