Skip to content

Commit

Permalink
changed api to async
Browse files Browse the repository at this point in the history
Signed-off-by: abbr <[email protected]>
  • Loading branch information
abbr committed Jul 11, 2014
1 parent 731ebff commit 0725568
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ app.configure(function () {
var nodeSSPIObj = new nodeSSPI({
retrieveGroups: true
});
nodeSSPIObj.authenticate(req, res);
res.finished || next();
nodeSSPIObj.authenticate(req, res, function(err){
res.finished || next();
});
});
app.use(function (req, res, next) {
var out = 'Hello ' + req.connection.user + '! You belong to following groups:<br/><ul>';
Expand Down Expand Up @@ -102,7 +103,7 @@ The call to `new nodeSSPI(opts)` in above code can take following options:
* 403 if max login attempts are reached
* 401 for all in-progress authentications, including protocols that require multiple round trips or if max login attempts has not been reached.
* 500 when NodeSSPI encountered exception it cannot handle.
* If option `authoritative` is not set to *true*, then response headers and `res.statusCode` will still be populated as described above, but NodeSSPI will not block the request, i.e. it will not call `res.end()`. Also, error message will be returned from calling `nodeSSPIObj.authenticate(req, res);` rather than sending to response. This allows the caller and downstream middleware to make decision.
* If option `authoritative` is not set to *true*, then response headers and `res.statusCode` will still be populated as described above, but NodeSSPI will not block the request, i.e. it will not call `res.end()`. Also, error message will be returned from calling `nodeSSPIObj.authenticate(req, res, cb(err){});` in the *err* callback parameter rather than sending to response. This allows the caller and downstream middleware to make decision.

## Platforms
NodeSSPI has been tested working on these Windows platforms:
Expand Down
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function main(opts) {
this.opts = opts;
}

main.prototype.authenticate = function (req, res) {
main.prototype.authenticate = function (req, res, cb) {
if (this.opts.perRequestAuth) {
delete req.connection.user;
}
Expand All @@ -49,14 +49,17 @@ main.prototype.authenticate = function (req, res) {
} catch (ex) {
if (this.opts.authoritative) {
res.end(ex);
cb();
return;
} else {
return ex;
cb(ex);
return;
}
}
if (this.opts.authoritative && req.connection.user === undefined) {
res.end();
}
cb();
}

module.exports = main;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-sspi",
"version": "0.0.4",
"version": "0.1.0",
"description": "Windows SSPI server-side authentication for Node",
"main": "index.js",
"author": "Fred Wen<[email protected]>",
Expand Down

0 comments on commit 0725568

Please sign in to comment.