Skip to content

Commit

Permalink
fix(http.request): allow developpers to use additionnals request options
Browse files Browse the repository at this point in the history
  • Loading branch information
M3lkior committed Dec 2, 2016
1 parent 63e55fe commit 59bf1c0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
node_modules/
test/

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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]
*/

/**
Expand All @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"url": "https://github.com/kylepixel/cas-authentication.git"
},
"dependencies": {
"object-assign": "^4.1.0",
"xml2js": "^0.4.8"
},
"devDependencies": {
Expand Down

0 comments on commit 59bf1c0

Please sign in to comment.