Skip to content

Commit

Permalink
Format corrections.
Browse files Browse the repository at this point in the history
  • Loading branch information
gevorg committed Dec 3, 2011
1 parent a365d75 commit d5a3c32
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 60 deletions.
46 changes: 23 additions & 23 deletions lib/auth/basic.js
Expand Up @@ -15,30 +15,30 @@ module.exports = Basic;
* @param {Array} authUsers array of users.
*/
function Basic(authRealm, authUsers) {

// Realm.
this.realm = authRealm;
// Users.
this.users = authUsers;

// Used for async callback.
var self = this;

/**
* Applies basic authentication and calls next after user is authenticated.
*
* @param {Request} request HTTP request object.
* @param {Response} response HTTP response object.
* @param {Function} next function that will be called after user is authenticated.
*/
this.apply = function(request, response, next) {
var authenticated = self.isAuthenticated(request, response);
if(!authenticated) {
self.ask(request, response);
} else {
next();
// Realm.
this.realm = authRealm;
// Users.
this.users = authUsers;
// Used for async callback.
var self = this;
/**
* Applies basic authentication and calls next after user is authenticated.
*
* @param {Request} request HTTP request object.
* @param {Response} response HTTP response object.
* @param {Function} next function that will be called after user is authenticated.
*/
this.apply = function(request, response, next) {
var authenticated = self.isAuthenticated(request, response);
if(!authenticated) {
self.ask(request, response);
} else {
next();
}
}
}};
};

/**
* Checks authorization header in request.
Expand Down
3 changes: 2 additions & 1 deletion lib/defaults.js
Expand Up @@ -5,7 +5,8 @@ module.exports = {
/**
* Default HTML for not authorized page.
*/
'HTML_401' : "<!DOCTYPE html>\n<html><head><title>401 Unauthorized</title></head><body><h1>401 Unauthorized</h1><p>This page requires authorization.</p></body></html>",
'HTML_401' : "<!DOCTYPE html>\n<html><head><title>401 Unauthorized</title></head><body><h1>401 "
+ "Unauthorized</h1><p>This page requires authorization.</p></body></html>",
/**
* Nonce expire timeout.
*/
Expand Down
3 changes: 2 additions & 1 deletion lib/http-auth.js
Expand Up @@ -15,7 +15,8 @@ var opt = require('./options');
*
* - authRealm authentication realm.
* - authFile file where user details are stored in format {user:pass}.
* - authList list where user details are stored in format {user:pass}, ignored if authFile is specified.
* - authList list where user details are stored in format {user:pass},
* ignored if authFile is specified.
* - authType type of authentication, digest | basic, optional, default is basic.
* - algorithm algorithm that will be used, may be MD5 or MD5-sess, optional, default is MD5.
* @return {Object} authentication instance.
Expand Down
29 changes: 15 additions & 14 deletions lib/provider.js
Expand Up @@ -7,18 +7,19 @@ var Digest = require('./auth/digest'), Basic = require('./auth/basic');
* Provider creates new basic or digest authentication instance.
*/
module.exports = {
/**
* Creates new authentication instance.
*
* @param {Array} options authentication options.
* @return {Object} authentication instance.
*/
'newInstance' : function(options) {
if(options && options.authType == 'digest') {
return new Digest(options.authRealm, options.authUsers, options.algorithm);
} else if(options && options.authType == 'basic') {
return new Basic(options.authRealm, options.authUsers);
} else {
throw new Error("Invalid type, may be digest | basic!");
/**
* Creates new authentication instance.
*
* @param {Array} options authentication options.
* @return {Object} authentication instance.
*/
'newInstance' : function(options) {
if(options && options.authType == 'digest') {
return new Digest(options.authRealm, options.authUsers, options.algorithm);
} else if(options && options.authType == 'basic') {
return new Basic(options.authRealm, options.authUsers);
} else {
throw new Error("Invalid type, may be digest | basic!");
}
}
}};
};
43 changes: 22 additions & 21 deletions lib/utils.js
Expand Up @@ -7,24 +7,25 @@ var crypto = require('crypto');
* Utility module.
*/
module.exports = {
/**
* Function for encoding string to base64.
*
* @param {String} str string to encode.
* @return {String} bas64 encoded string.
*/
'base64' : function(str) {
return new Buffer(str, 'UTF-8').toString('base64');
},
/**
* MD5 hash method.
*
* @param {String} str string to hash.
* @return {String} md5 hash of string.
*/
'md5' : function(str) {
var hash = crypto.createHash('MD5');
hash.update(str);

return hash.digest('hex');
}};
/**
* Function for encoding string to base64.
*
* @param {String} str string to encode.
* @return {String} bas64 encoded string.
*/
'base64' : function(str) {
return new Buffer(str, 'UTF-8').toString('base64');
},
/**
* MD5 hash method.
*
* @param {String} str string to hash.
* @return {String} md5 hash of string.
*/
'md5' : function(str) {
var hash = crypto.createHash('MD5');
hash.update(str);

return hash.digest('hex');
}
};

0 comments on commit d5a3c32

Please sign in to comment.