BVB Source Codes

prerender Show basicAuth.js Source code

Return Download prerender: download basicAuth.js Source code - Download prerender Source code - Type:.js
  1. //adapted from https://github.com/visionmedia/node-basic-auth
  2.  
  3. module.exports = {
  4.     beforePhantomRequest: function(req, res, next) {
  5.  
  6.         var auth = req.headers.authorization;
  7.         if (!auth) return this.fail(req, res, next);
  8.  
  9.         // malformed
  10.         var parts = auth.split(' ');
  11.         if ('basic' != parts[0].toLowerCase()) return this.fail(req, res, next);
  12.         if (!parts[1]) return this.fail(req, res, next);
  13.         auth = parts[1];
  14.  
  15.         // credentials
  16.         auth = new Buffer(auth, 'base64').toString();
  17.         auth = auth.match(/^([^:]+):(.+)$/);
  18.         if (!auth) return this.fail(req, res, next);
  19.  
  20.         if (!this.isAuthorized(auth[1], auth[2])) return this.fail(req, res, next);
  21.  
  22.         req.prerender.authentication = { name: auth[1], password: auth[2] };
  23.  
  24.         return next();
  25.     },
  26.  
  27.     fail: function(req, res, next) {
  28.         res.send(401);
  29.     },
  30.  
  31.     isAuthorized: function(username, password) {
  32.         if(username === process.env.BASIC_AUTH_USERNAME && password === process.env.BASIC_AUTH_PASSWORD) return true;
  33.     }
  34. }
downloadbasicAuth.js Source code - Download prerender Source code
Related Source Codes/Software:
libsodium - A modern and easy-to-use crypto library. 2017-01-09
Side-Menu.Android - Side menu with some categories to choose. ... 2017-01-09
docker-gitlab - Dockerized GitLab http://www.da... 2017-01-09
sinon - Test spies, stubs and mocks for JavaScript. ... 2017-01-09
in-view - Get notified when a DOM element enters or exits th... 2017-01-09
falcon - Falcon is a low-level, high-performance Python fra... 2017-01-09
ImageOptim - GUI image optimizer for Mac htt... 2017-01-09
node-style-guide - A guide for styling your node.js / JavaScript code... 2017-01-09
FDFullscreenPopGesture - A UINavigationController's category to enable full... 2017-01-10
Gource - oftware version control visualization ... 2017-01-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top