forked from kcbanner/node-cas
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
support | ||
test | ||
examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
0.0.1 / 2010-01-03 | ||
================== | ||
|
||
* Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
test: | ||
@expresso -I lib | ||
|
||
.PHONY: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
# node-cas | ||
|
||
Central Authentication Service (CAS) client for Node.js | ||
|
||
## License | ||
|
||
(The MIT License) | ||
|
||
Copyright (c) 2011 Casey Banner <kcbanner@gmail.com> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
module.exports = require('./lib/node-cas'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
|
||
/*! | ||
* node-cas | ||
* Copyright(c) 2011 Casey Banner <kcbanner@gmail.com> | ||
* MIT Licensed | ||
*/ | ||
|
||
/** | ||
* Module dependencies | ||
*/ | ||
|
||
var https = require('https'); | ||
var url = require('url'); | ||
|
||
/** | ||
* Initialize CAS with the given `options`. | ||
* | ||
* @param {Object} options | ||
* @api public | ||
*/ | ||
var CAS = module.exports = function CAS(options) { | ||
options = options || {}; | ||
|
||
if (!options.base_url) { | ||
throw new Error('Required CAS option `base_url` missing.'); | ||
} | ||
|
||
if (!options.service) { | ||
throw new Error('Required CAS option `service` missing.'); | ||
} | ||
|
||
var cas_url = url.parse(options.base_url); | ||
if (cas_url.protocol != 'https:') { | ||
throw new Error('Only https CAS servers are supported.'); | ||
} else if (!cas_url.hostname) { | ||
throw new Error('Option `base_url` must be a valid url like: https://example.com/cas'); | ||
} else { | ||
this.hostname = cas_url.host; | ||
this.port = cas_url.port || 443; | ||
this.base_path = cas_url.pathname; | ||
} | ||
|
||
this.service = options.service; | ||
}; | ||
|
||
/** | ||
* Library version. | ||
*/ | ||
|
||
CAS.version = '0.0.1'; | ||
|
||
/** | ||
* Attempt to validate a given ticket with the CAS server. | ||
* `callback` is called with (err, auth_status, username) | ||
* | ||
* @param {String} ticket | ||
* @param {Function} callback | ||
* @api public | ||
*/ | ||
|
||
CAS.prototype.validate = function(ticket, callback) { | ||
var req = https.get({ | ||
host: this.hostname, | ||
port: this.port, | ||
path: url.format({ | ||
pathname: this.base_path+'/validate', | ||
query: {ticket: ticket, service: this.service} | ||
}) | ||
}, function(res) { | ||
// Handle server errors | ||
res.on('error', function(e) { | ||
callback(e); | ||
}); | ||
|
||
// Read result | ||
res.setEncoding('utf8'); | ||
var response = ''; | ||
res.on('data', function(chunk) { | ||
response += chunk; | ||
}); | ||
|
||
res.on('end', function() { | ||
var sections = response.split('\n'); | ||
if (sections.length >= 1) { | ||
if (sections[0] == 'no') { | ||
callback(undefined, false); | ||
return; | ||
} else if (sections[0] == 'yes' && sections.length >= 2) { | ||
callback(undefined, true, sections[1]); | ||
return; | ||
} | ||
} | ||
|
||
// Format was not correct, error | ||
callback({message: 'Bad response format.'}); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "node-cas", | ||
"version": "0.0.1", | ||
"description": "Central Authentication Service (CAS) client for Node.js", | ||
"keywords": ["cas", "central authentication service", "auth", "authentication", "central", "service"], | ||
"author": "Casey Banner <kcbanner@gmail.com>", | ||
"dependencies": {}, | ||
"main": "index", | ||
"engines": { "node": "0.4.x" } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var cas = require('node-cas') | ||
, should = require('should'); | ||
|
||
module.exports = { | ||
'test .version': function(){ | ||
cas.version.should.match(/^\d+\.\d+\.\d+$/); | ||
} | ||
}; |