I'm trying to access the user profile created by the passport-windowsauth authentication, and I seem to be missing something- I'm just not sure what. I want to be able to access the username and groups from the profile.
Here is my app.js:
/*jslint node: true */
/*jshint multistr: true */
var express = require('express');
var app = express();
var port = process.env.PORT || 5500;
app.use(express.static('public'));
app.set('views', './src/views');
app.set('view engine', 'ejs');
var passport = require('passport');
var WindowsStrategy = require('passport-windowsauth');
passport.authenticate(new WindowsStrategy({
ldap: {
url: 'ldapurl',
base: 'DC=dc,DC=dc',
bindDN: 'somename',
bindCredentials: 'itspss'
},
getUserNameFromHeader: function (req) {
//in the above apache config we set the x-forwarded-user header.
//mod_auth_kerb uses user@domain
return req.headers['x-forwarded-user'].split('@')[0];
}
}, function(profile, done){
User.findOrCreate({ waId: profile.id }, function (err, user) {
done(err, user);
});
}));
app.get('/', function (req, res) {
res.render('index', { user: req.user.sAMAccountName
});
});
app.listen(port, function (err) {
console.log('running server on port ' + port);
});
And my index.ejs is:
hello world
<br>
your name is <%=user%>
When I try to open the page, it authenticates, but I get this error:
TypeError: Cannot read property 'sAMAccountName' of undefined
at /home/.../node_test/app.js:35:38
at Layer.handle [as handle_request] (/home/.../node_test/node_modules/express/lib/router/layer.js:95:5)
at next (/home/.../node_test/node_modules/express/lib/router/route.js:131:13)
at Route.dispatch (/home/.../node_test/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/.../node_test/node_modules/express/lib/router/layer.js:95:5)
at /home/.../node_test/node_modules/express/lib/router/index.js:277:22
at Function.process_params (/home/.../node_test/node_modules/express/lib/router/index.js:330:12)
at next (/home/.../node_test/node_modules/express/lib/router/index.js:271:10)
at SendStream.error (/home/.../node_test/node_modules/express/node_modules/serve-static/index.js:121:7)
at emitOne (events.js:77:13)
I'm trying to access the user profile created by the passport-windowsauth authentication, and I seem to be missing something- I'm just not sure what. I want to be able to access the username and groups from the profile.
Here is my app.js:
And my index.ejs is:
When I try to open the page, it authenticates, but I get this error:
What am I missing?