auth0 / passport-windowsauth

Windows Authentication strategy for Passport.js
MIT License
178 stars 54 forks source link

Using passport-windowsauth locally #61

Open ndomenic opened 5 years ago

ndomenic commented 5 years ago

I have tried to get passport-windowsauth to work locally on my machine, however I am continually getting Unauthorized when trying to get from my test endpoint. This works fine on IIS, however. Is there a way to set up so that I can still use passport-windowsauth locally? My code is as follows:

web.config

<configuration>
  <system.webServer>
    <iisnode node_env="production" promoteServerVars="LOGON_USER"/>
  </system.webServer>
</configuration>

index.js

const passport = require('passport');
const 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 (req, res, next){
  next();
});

app.get('/testAuth', (req, res, next) => {
  res.send(req.user.id + " is authenticated");
});