diff options
author | alecdwm | 2016-12-14 11:50:10 +0100 |
---|---|---|
committer | alecdwm | 2016-12-14 12:38:03 +0100 |
commit | 30071637998097b25a36b69af3a1affe3c18bf23 (patch) | |
tree | e9189520c94d83bf70e1b90100499febe6d80279 | |
parent | 6ba9a2f039fe9c4d7495d30ae4f255b96d7f7530 (diff) |
Tokens not required for ldap auth
Diffstat (limited to '')
-rw-r--r-- | lib/auth.js | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/lib/auth.js b/lib/auth.js index 1e21eb9f..b2c787b9 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -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 |