From 6ed570d378cf2ce9fede1c1758a8a750acb2c988 Mon Sep 17 00:00:00 2001 From: abisalehalliprasan Date: Thu, 2 Jul 2020 14:47:03 -0700 Subject: [PATCH 1/4] Adding support for custom Authorize Endpoints --- src/OAuthClient.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/OAuthClient.js b/src/OAuthClient.js index f18c4e19..54e88998 100644 --- a/src/OAuthClient.js +++ b/src/OAuthClient.js @@ -108,6 +108,24 @@ OAuthClient.user_agent = `Intuit-OAuthClient-JS_${ version.version }_${os.type()}_${os.release()}_${os.platform()}`; +/** + * Helper function for setting custom authorizeEndpoint/tokenEndpoint URL's + * * + * @param params + * @returns {null} + */ +OAuthClient.prototype.setAuthorizeURLs = function setAuthorizeURLs(params) { + params = params || {}; + + // check if the customURL's are passed correctly + if (!params.authorizeEndpoint || !params.tokenEndpoint) + throw new Error('Provide the custom authorize URL'); + + OAuthClient.authorizeEndpoint = params.authorizeEndpoint; + OAuthClient.tokenEndpoint = params.tokenEndpoint; + return null; +}; + /** * Redirect User to Authorization Page * * From 9a99dd9ddb2c932cbf48d69fbd09f46c4359b101 Mon Sep 17 00:00:00 2001 From: abisalehalliprasan Date: Thu, 9 Jul 2020 17:56:13 -0700 Subject: [PATCH 2/4] Passing custom revokeEndpoint, userInfoEndpoint --- src/OAuthClient.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OAuthClient.js b/src/OAuthClient.js index 54e88998..0dc8c49e 100644 --- a/src/OAuthClient.js +++ b/src/OAuthClient.js @@ -115,15 +115,15 @@ OAuthClient.user_agent = `Intuit-OAuthClient-JS_${ * @returns {null} */ OAuthClient.prototype.setAuthorizeURLs = function setAuthorizeURLs(params) { - params = params || {}; - // check if the customURL's are passed correctly - if (!params.authorizeEndpoint || !params.tokenEndpoint) - throw new Error('Provide the custom authorize URL'); + if (!params) { + throw new Error("Provide the custom authorize URL's"); + } OAuthClient.authorizeEndpoint = params.authorizeEndpoint; OAuthClient.tokenEndpoint = params.tokenEndpoint; - return null; + OAuthClient.revokeEndpoint = params.revokeEndpoint; + return this; }; /** From b345921490cf5d4daf64e1e5a5e516b54677685e Mon Sep 17 00:00:00 2001 From: abisalehalliprasan Date: Thu, 9 Jul 2020 17:57:49 -0700 Subject: [PATCH 3/4] Bump new version 3.0.2 --- package.json | 2 +- src/OAuthClient.js | 23 ++++++++++------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 250d44bf..239c74a4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "intuit-oauth", - "version": "3.0.1", + "version": "3.0.2", "description": "Intuit Node.js client for OAuth2.0 and OpenIDConnect", "main": "./src/OAuthClient.js", "scripts": { diff --git a/src/OAuthClient.js b/src/OAuthClient.js index 0dc8c49e..a537d317 100644 --- a/src/OAuthClient.js +++ b/src/OAuthClient.js @@ -65,7 +65,7 @@ function OAuthClient(config) { level: 'info', format: winston.format.combine( winston.format.timestamp(), - winston.format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}`), + winston.format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}`) ), transports: [ new winston.transports.File({ @@ -108,21 +108,18 @@ OAuthClient.user_agent = `Intuit-OAuthClient-JS_${ version.version }_${os.type()}_${os.release()}_${os.platform()}`; -/** - * Helper function for setting custom authorizeEndpoint/tokenEndpoint URL's - * * - * @param params - * @returns {null} - */ OAuthClient.prototype.setAuthorizeURLs = function setAuthorizeURLs(params) { // check if the customURL's are passed correctly if (!params) { throw new Error("Provide the custom authorize URL's"); } - OAuthClient.authorizeEndpoint = params.authorizeEndpoint; OAuthClient.tokenEndpoint = params.tokenEndpoint; OAuthClient.revokeEndpoint = params.revokeEndpoint; + this.environment === 'sandbox' + ? (OAuthClient.userinfo_endpoint_sandbox = params.userInfoEndpoint) + : (OAuthClient.userinfo_endpoint_production = params.userInfoEndpoint); + return this; }; @@ -274,7 +271,7 @@ OAuthClient.prototype.refreshUsingToken = function refreshUsingToken(refresh_tok this.log( 'info', 'Refresh usingToken () response is : ', - JSON.stringify(authResponse, null, 2), + JSON.stringify(authResponse, null, 2) ); return authResponse; }) @@ -356,7 +353,7 @@ OAuthClient.prototype.getUserInfo = function getUserInfo() { this.log( 'info', 'The Get User Info () response is : ', - JSON.stringify(authResponse, null, 2), + JSON.stringify(authResponse, null, 2) ); return authResponse; }) @@ -385,7 +382,7 @@ OAuthClient.prototype.makeApiCall = function makeApiCall(params) { Accept: AuthResponse._jsonContentType, 'User-Agent': OAuthClient.user_agent, }, - params.headers, + params.headers ) : Object.assign( {}, @@ -393,7 +390,7 @@ OAuthClient.prototype.makeApiCall = function makeApiCall(params) { Authorization: `Bearer ${this.getToken().access_token}`, Accept: AuthResponse._jsonContentType, 'User-Agent': OAuthClient.user_agent, - }, + } ); const request = { @@ -490,7 +487,7 @@ OAuthClient.prototype.getKeyFromJWKsURI = function getKeyFromJWKsURI(id_token, k this.log( 'error', 'The getKeyFromJWKsURI () threw an exception : ', - JSON.stringify(e, null, 2), + JSON.stringify(e, null, 2) ); throw e; }); From dea87bcfdeaadd22e14acdc1aa95831e76ebf75d Mon Sep 17 00:00:00 2001 From: abisalehalliprasan Date: Thu, 9 Jul 2020 17:59:14 -0700 Subject: [PATCH 4/4] Bump new version 3.0.2 --- src/OAuthClient.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/OAuthClient.js b/src/OAuthClient.js index a537d317..011c251b 100644 --- a/src/OAuthClient.js +++ b/src/OAuthClient.js @@ -65,7 +65,7 @@ function OAuthClient(config) { level: 'info', format: winston.format.combine( winston.format.timestamp(), - winston.format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}`) + winston.format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}`), ), transports: [ new winston.transports.File({ @@ -271,7 +271,7 @@ OAuthClient.prototype.refreshUsingToken = function refreshUsingToken(refresh_tok this.log( 'info', 'Refresh usingToken () response is : ', - JSON.stringify(authResponse, null, 2) + JSON.stringify(authResponse, null, 2), ); return authResponse; }) @@ -353,7 +353,7 @@ OAuthClient.prototype.getUserInfo = function getUserInfo() { this.log( 'info', 'The Get User Info () response is : ', - JSON.stringify(authResponse, null, 2) + JSON.stringify(authResponse, null, 2), ); return authResponse; }) @@ -382,7 +382,7 @@ OAuthClient.prototype.makeApiCall = function makeApiCall(params) { Accept: AuthResponse._jsonContentType, 'User-Agent': OAuthClient.user_agent, }, - params.headers + params.headers, ) : Object.assign( {}, @@ -390,7 +390,7 @@ OAuthClient.prototype.makeApiCall = function makeApiCall(params) { Authorization: `Bearer ${this.getToken().access_token}`, Accept: AuthResponse._jsonContentType, 'User-Agent': OAuthClient.user_agent, - } + }, ); const request = { @@ -487,7 +487,7 @@ OAuthClient.prototype.getKeyFromJWKsURI = function getKeyFromJWKsURI(id_token, k this.log( 'error', 'The getKeyFromJWKsURI () threw an exception : ', - JSON.stringify(e, null, 2) + JSON.stringify(e, null, 2), ); throw e; });