Advertisement
Guest User

Untitled

a guest
May 25th, 2019
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. app.use((req, res, next) => {
  2. const auth = { login: 'username', password: 'password' };
  3. const b64auth = (req.headers.authorization || '').split(' ')[1] || '';
  4. const [login, password] = new Buffer(b64auth, 'base64').toString().split(':');
  5.  
  6. if (login && password && login === auth.login && password === auth.password) {
  7. return next();
  8. }
  9.  
  10. res.set('WWW-Authenticate', 'Basic realm="401"');
  11. res.status(401).send('Authentication required.');
  12. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement