oidc dashboard login
This commit is contained in:
@@ -9,6 +9,7 @@ exports = module.exports = {
|
||||
del
|
||||
},
|
||||
|
||||
dashboardLoginCallback,
|
||||
destroyUserSession
|
||||
};
|
||||
|
||||
@@ -17,7 +18,8 @@ const assert = require('assert'),
|
||||
oidc = require('../oidc.js'),
|
||||
HttpError = require('connect-lastmile').HttpError,
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
||||
safe = require('safetydance');
|
||||
safe = require('safetydance'),
|
||||
tokens = require('../tokens.js');
|
||||
|
||||
async function add(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
@@ -109,11 +111,26 @@ async function del(req, res, next) {
|
||||
next(new HttpSuccess(204));
|
||||
}
|
||||
|
||||
const tokens = require('../tokens.js');
|
||||
|
||||
async function dashboardLoginCallback(req, res, next) {
|
||||
const [error, token] = await safe(tokens.add({ clientId: tokens.ID_WEBADMIN, identifier: req.user.id, expires: Date.now() + constants.DEFAULT_TOKEN_EXPIRATION_MSECS }));
|
||||
if (error) return next(new HttpError(500, error));
|
||||
|
||||
await eventlog.add(req.user.ghost ? eventlog.ACTION_USER_LOGIN_GHOST : eventlog.ACTION_USER_LOGIN, auditSource, { userId: req.user.id, user: users.removePrivateFields(req.user) });
|
||||
|
||||
if (!req.user.ghost) safe(users.notifyLoginLocation(req.user, ip, userAgent, auditSource), { debug });
|
||||
|
||||
next(new HttpSuccess(200, token));
|
||||
}
|
||||
|
||||
async function destroyUserSession(req, res, next) {
|
||||
assert.strictEqual(typeof req.user, 'object');
|
||||
|
||||
const [error] = await safe(oidc.revokeByUserId(req.user.id));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
await safe(tokens.delByAccessToken(req.token));
|
||||
|
||||
next(new HttpSuccess(204));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user