Advertisement
Guest User

Untitled

a guest
Jul 16th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. var basicAuth = require('basic-auth');
  2.  
  3. var auth = function (req, res, next) {
  4. function unauthorized(res) {
  5. res.set('WWW-Authenticate', 'Basic realm=Authorization Required');
  6. return res.send(401);
  7. };
  8.  
  9. var user = basicAuth(req);
  10.  
  11. if (!user || !user.name || !user.pass) {
  12. return unauthorized(res);
  13. };
  14.  
  15. if (user.name === 'foo' && user.pass === 'bar') {
  16. return next();
  17. } else {
  18. return unauthorized(res);
  19. };
  20. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement