everyauth
everyauth copied to clipboard
Change required for Azure ACS integration
In order to get the custom user object returned by findOrCreateUser so that the req.user is populated properly. I had to make the following changes....
azureacs.js
.step('addToSession')
.accepts('session user token') ///so that we get the custom user not acsUser returned from ACS...
.promises(null)
I also had to change the addToSession function as follows so that the user id is passed from the custom user object.
.addToSession( function (sess, user, token) {
var _auth = sess.auth || (sess.auth = {})
, mod = _auth[this.name] || (_auth[this.name] = {});
_auth.loggedIn = true;
_auth.userId || (_auth.userId = user[this._userPkey]);
mod.user = user;
mod.accessToken = token;
})
For running under connect instead of express I had to make a change to node-wsfederation module because it was expectsing a res.req property which isn't on the res object. So I had to pass in the req object instead with these small changes...
wsfederation.js
extractToken: function(req) {
var promise = {};
var parser = new xml2js.Parser();
parser.on('end', function(result) {
promise = result['t:RequestedSecurityToken'];
});
parser.parseString(req.body['wresult']); // changed from res.req.body since there is no req property on res... Maybe express adds the req property to res but connect middleware doesn't.
return promise;
}
};
As well as make sure to pass req instead of res in azureacs.js under the getToken function.
.getToken(function (req, res) {
var token = this.wsfederation.extractToken(req); //changed from this.wsfederation.extractToken(res)