mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-28 00:06:53 +01:00
fea601099a
closes: #233
31 lines
868 B
JavaScript
31 lines
868 B
JavaScript
'use strict';
|
|
|
|
const auth = require('basic-auth');
|
|
const { User } = require('../lib/server-impl.js');
|
|
|
|
function basicAuthentication(app) {
|
|
app.use('/api/admin/', (req, res, next) => {
|
|
const credentials = auth(req);
|
|
|
|
if (credentials) {
|
|
// you will need to do some verification of credentials here.
|
|
const user = new User({ email: `${credentials.name}@domain.com` });
|
|
req.user = user;
|
|
next();
|
|
} else {
|
|
return res
|
|
.status('401')
|
|
.set({ 'WWW-Authenticate': 'Basic realm="example"' })
|
|
.end('access denied');
|
|
}
|
|
});
|
|
|
|
app.use((req, res, next) => {
|
|
// Updates active sessions every hour
|
|
req.session.nowInHours = Math.floor(Date.now() / 3600e3);
|
|
next();
|
|
});
|
|
}
|
|
|
|
module.exports = basicAuthentication;
|