From 7bd5f66d256132e960270896b25a62492c49758b Mon Sep 17 00:00:00 2001 From: Stephen Asiedu Date: Fri, 3 Jul 2020 14:37:39 +0200 Subject: [PATCH 1/2] KEYCLOAK-14664 Makes X-Client header optional by configuring it in the config --- middleware/auth-utils/grant-manager.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/middleware/auth-utils/grant-manager.js b/middleware/auth-utils/grant-manager.js index 06680dd7..889e1630 100644 --- a/middleware/auth-utils/grant-manager.js +++ b/middleware/auth-utils/grant-manager.js @@ -41,6 +41,7 @@ function GrantManager (config) { this.notBefore = 0; this.rotation = new Rotation(config); this.verifyTokenAudience = config.verifyTokenAudience; + this.useCustomHeaders = config.useCustomHeaders || true; } /** @@ -290,10 +291,13 @@ GrantManager.prototype.userInfo = function userInfo (token, callback) { options.headers = { 'Authorization': 'Bearer ' + t, - 'Accept': 'application/json', - 'X-Client': 'keycloak-nodejs-connect' + 'Accept': 'application/json' }; + if (this.useCustomHeaders) { + options['X-Client'] = 'keycloak-nodejs-connect'; + } + const promise = new Promise((resolve, reject) => { const req = getProtocol(options).request(options, (response) => { if (response.statusCode < 200 || response.statusCode >= 300) { @@ -503,9 +507,11 @@ const postOptions = (manager, path) => { const realPath = path || '/protocol/openid-connect/token'; const opts = URL.parse(manager.realmUrl + realPath); opts.headers = { - 'Content-Type': 'application/x-www-form-urlencoded', - 'X-Client': 'keycloak-nodejs-connect' + 'Content-Type': 'application/x-www-form-urlencoded' }; + if (manager.useCustomHeaders) { + opts['X-Client'] = 'keycloak-nodejs-connect'; + } if (!manager.public) { opts.headers.Authorization = 'Basic ' + Buffer.from(manager.clientId + ':' + manager.secret).toString('base64'); } From c4cac0514fa8011f249eb7e1740d605a662c11df Mon Sep 17 00:00:00 2001 From: Stephen Asiedu Date: Fri, 3 Jul 2020 15:08:49 +0200 Subject: [PATCH 2/2] KEYCLOAK-14664 Adds customHeaders --- middleware/auth-utils/config.js | 6 ++++++ middleware/auth-utils/grant-manager.js | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/middleware/auth-utils/config.js b/middleware/auth-utils/config.js index 28ab7af2..fa6768eb 100644 --- a/middleware/auth-utils/config.js +++ b/middleware/auth-utils/config.js @@ -118,6 +118,12 @@ Config.prototype.configure = function configure (config) { */ this.public = resolveValue(config['public-client'] || config.public || false); + /** + * Enable/Disable the use of X-Custom headers + * @type {String} + */ + this.useCustomHeaders = resolveValue(config.useCustomHeaders || true); + /** * Authentication server URL * @type {String} diff --git a/middleware/auth-utils/grant-manager.js b/middleware/auth-utils/grant-manager.js index 889e1630..dfd5bc64 100644 --- a/middleware/auth-utils/grant-manager.js +++ b/middleware/auth-utils/grant-manager.js @@ -41,7 +41,7 @@ function GrantManager (config) { this.notBefore = 0; this.rotation = new Rotation(config); this.verifyTokenAudience = config.verifyTokenAudience; - this.useCustomHeaders = config.useCustomHeaders || true; + this.useCustomHeaders = config.useCustomHeaders; } /**