Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.use((req, res, next) => {
- const auth = { login: 'username', password: 'password' };
- const b64auth = (req.headers.authorization || '').split(' ')[1] || '';
- const [login, password] = new Buffer(b64auth, 'base64').toString().split(':');
- if (login && password && login === auth.login && password === auth.password) {
- return next();
- }
- res.set('WWW-Authenticate', 'Basic realm="401"');
- res.status(401).send('Authentication required.');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement