Skip to content

Commit

Permalink
add basic authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
vially committed Feb 25, 2012
1 parent 12503f0 commit 8129958
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions lib/cpanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exports.createClient = function (options) {
port: options.port || 2087,
secure: options.secure,
username: options.username,
password: options.password,
accessKey: options.accessKey,
path: options.path || '/json-api/'
});
Expand All @@ -21,14 +22,19 @@ var cpanelJsonClient = function (obj) {

obj.connection = obj.secure ? require('https') : require('http');
obj.call = function (action, query, callback) {
if (obj.host == null || obj.username == null || obj.accessKey == null) {
throw("Host, username and accessKey must be set")
if (obj.host == null || obj.username == null || (obj.accessKey == null && obj.password == null)) {
throw("Host, username and an accessKey or a password must be set")
}

var params = qs.stringify(query);
var headers = {
"Authorization": "WHM " + obj.username + ":" + obj.accessKey
};
var headers = {};
if (obj.accessKey != null) {
// WHM access hash authenticaion
headers.Authorization = "WHM " + obj.username + ":" + obj.accessKey
} else {
// basic user authentication
headers.Authorization = "Basic " + new Buffer(obj.username + ":" + obj.password).toString('base64')
}

var options = {
host: obj.host,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Valentin-Costel Hăloiu <vially.ichb@gmail.com>",
"name": "cpanel-lib",
"description": "Node.js library for the cPanel/WHM API",
"version": "0.0.2",
"version": "0.0.3",
"homepage": "https://github.com/vially/cpanel-lib",
"repository": {
"type": "git",
Expand Down

0 comments on commit 8129958

Please sign in to comment.