Authentication Windows Nodejs or ExpressJS

I would like to authenticate a Windows user in a NodeJS application. Are there any add-ons for this yet? There is node-krb5 , but it does not yet support windows.

+6
source share
3 answers

If you host on IIS with iisnode https://github.com/auth0/passport-windowsauth , this is great! Passport-windowsauth comes with ad integration, but if you only want a username to implement your own authorship logic, you can do it like this:

web.config:

 <system.webServer> <iisnode promoteServerVars="LOGON_USER" /> </system.webServer> 

server.js:

 var passport = require('passport'); var WindowsStrategy = require('passport-windowsauth'); app.use(passport.initialize()); app.use(passport.session()); passport.serializeUser(function(user, done) { done(null, user); }); passport.deserializeUser(function(user, done) { done(null, user); }); passport.use(new WindowsStrategy({ integrated: true }, function(profile,done) { var user = { id: profile.id, }; done(null, user); })); app.all("*", passport.authenticate("WindowsAuthentication"), function (request,response,next){ next(); }); 

then you can access the user ID in the request object on other routes:

 app.get("/api/testAuthentication", function(request, response){ console.log(request.user.id + " is authenticated"); }); 

if you want to implement your own authorization logic using a user ID, you can define an intermediate layer function like this:

 app.get("/api/testAuthorization", hasRole("a role"), function(request, response, next){ console.log(request.user.id " is authenticated and authorized"); }); 

where hasRole looks like this:

 function hasRole(role) { return function(request,response,next){ //your own authorzation logic if(role == "a role") next(); else response.status(403).send(); } } 
+3
source

I added a blog post for this here http://hadenoughpi.wordpress.com/2013/04/16/node-js-windows-authentication-using-edgejs/ I hope this is one of the right ways.

0
source

node-sspi : was easy and efficient to use.

https://www.npmjs.com/package/node-sspi

0
source

All Articles