From 59bf1c0a278a2e5ea534068a25409bbd16ce433c Mon Sep 17 00:00:00 2001 From: Ludovic Dussart Date: Fri, 2 Dec 2016 16:23:51 +0100 Subject: [PATCH] fix(http.request): allow developpers to use additionnals request options Close #12 --- .gitignore | 1 + README.md | 2 +- index.js | 8 ++++++-- package.json | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index eef9b26..39b785d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea node_modules/ test/ diff --git a/README.md b/README.md index a60d832..8bdd232 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ var cas = new CASAuthentication({ | session_name | _string_ | The name of the session variable that will store the CAS user once they are authenticated. | _"cas_user"_ | | session_info | _string_ | The name of the session variable that will store the CAS user information once they are authenticated. If set to false (or something that evaluates as false), the additional information supplied by the CAS will not be forwarded. This will not work with CAS 1.0, as it does not support additional user information. | _false_ | | destroy_session | _boolean_ | If true, the logout function will destroy the entire session upon CAS logout. Otherwise, it will only delete the session variable storing the CAS user. | _false_ | - +| additionnals_request_options | _Object_ | Additionnals request options used to call CAS services. See [node.js documentation](https://nodejs.org/dist/latest-v7.x/docs/api/http.html#http_http_request_options_callback) for details | {} ## Usage ```javascript diff --git a/index.js b/index.js index a09fe0c..613b298 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,8 @@ var url = require('url'), http = require('http'), https = require('https'), parseXML = require('xml2js').parseString, - XMLprocessors = require('xml2js/lib/processors'); + XMLprocessors = require('xml2js/lib/processors'), + objectAssign = require('object-assign'); /** * The CAS authentication types. @@ -26,6 +27,7 @@ var AUTH_TYPE = { * @property {string} [session_name='cas_user'] * @property {string} [session_info=false] * @property {boolean} [destroy_session=false] + * @property {object} [additionnals_request_options] */ /** @@ -45,6 +47,7 @@ function CASAuthentication(options) { } this.cas_version = options.cas_version !== undefined ? options.cas_version : '3.0'; + this.additionnals_request_options = options.additionnals_request_options || {}; if (this.cas_version === '1.0') { this._validateUri = '/validate'; @@ -335,7 +338,8 @@ CASAuthentication.prototype._handleTicket = function(req, res, next) { }; } - var request = this.request_client.request(requestOptions, function(response) { + var mergedRequestOptions = objectAssign({}, requestOptions, this.additionnals_request_options); + var request = this.request_client.request(mergedRequestOptions, function(response) { response.setEncoding( 'utf8' ); var body = ''; response.on( 'data', function(chunk) { diff --git a/package.json b/package.json index c2d92db..e362cba 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "url": "https://github.com/kylepixel/cas-authentication.git" }, "dependencies": { + "object-assign": "^4.1.0", "xml2js": "^0.4.8" }, "devDependencies": {