Skip to content

Instantly share code, notes, and snippets.

@hns
Created May 12, 2010 19:45
Show Gist options
  • Save hns/399046 to your computer and use it in GitHub Desktop.
Save hns/399046 to your computer and use it in GitHub Desktop.
diff --git a/auth.js b/auth.js
index 0ae0627..b324f8e 100644
--- a/auth.js
+++ b/auth.js
@@ -6,11 +6,11 @@ module.shared = true;
exports.middleware = function (app) {
return function (env) {
- if (auth[env.PATH_INFO.replace(/^\//, '').replace(/\/$/, '')]) {
+ if (auth[env.pathInfo.replace(/^\//, '').replace(/\/$/, '')]) {
var toAuth = // Determine path to authorize with credentials.
- auth[env.PATH_INFO.replace(/^\//, '').replace(/\/$/, '')];
- if (env.HTTP_AUTHORIZATION) { // Extract credentials from HTTP.
- var credentials = base64.decode(env.HTTP_AUTHORIZATION.
+ auth[env.pathInfo.replace(/^\//, '').replace(/\/$/, '')];
+ if (env.headers.authorization) { // Extract credentials from HTTP.
+ var credentials = base64.decode(env.headers.authorization.
replace(/Basic /, '')).split(':');
if (credentials[1].digest('sha1') === toAuth[credentials[0]]) {
return app(env); // Authorization.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment