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 06680dd7..dfd5bc64 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; } /** @@ -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'); }