Permalink
Browse files

add basic authentication

  • Loading branch information...
1 parent 12503f0 commit 8129958b1e5b805047253df1dd0af6b10f246ed6 @vially committed Feb 25, 2012
Showing with 12 additions and 6 deletions.
  1. +11 −5 lib/cpanel.js
  2. +1 −1 package.json
View
@@ -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/'
});
@@ -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,
View
@@ -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",

0 comments on commit 8129958

Please sign in to comment.