Tokens not required for ldap auth

This commit is contained in:
alecdwm 2016-12-14 11:50:10 +01:00
parent 6ba9a2f039
commit 3007163799
1 changed files with 30 additions and 4 deletions

View File

@ -135,10 +135,36 @@ if (config.ldap) {
provider: 'ldap',
}
var stringifiedProfile = JSON.stringify(profile);
// TODO: Generate secure tokens for LDAP users
var accessToken = 'debug-access-token|LDAP-' + user.uidNumber + '|' + config.ldap.tokenSecret + '|' + new Date().getTime();
var refreshToken = 'debug-refresh-token|LDAP-' + user.uidNumber + '|' + config.ldap.tokenSecret + '|' + new Date().getTime();
callback(accessToken, refreshToken, profile, done);
models.User.findOrCreate({
where: {
profileid: profile.id.toString()
},
defaults: {
profile: stringifiedProfile,
}
}).spread(function (user, created) {
if (user) {
var needSave = false;
if (user.profile != stringifiedProfile) {
user.profile = stringifiedProfile;
needSave = true;
}
if (needSave) {
user.save().then(function () {
if (config.debug)
logger.info('user login: ' + user.id);
return done(null, user);
});
} else {
if (config.debug)
logger.info('user login: ' + user.id);
return done(null, user);
}
}
}).catch(function (err) {
logger.error('ldap auth failed: ' + err);
return done(err, null);
});
}));
}
// email