Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions nodes/http-auth-multiple.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<script type="text/javascript">
RED.nodes.registerType("node-red-contrib-httpauthmultiple", {
category: "config",
defaults: {
name: { value: "" },
authType: { value: "Basic", required: true },
realm: { value: "", required: true },
hashed: { value: false, required: true },
auths: { value: {} }
},
color: "#E7E7AE",
icon: "white-globe.png",
label: function() { return (this.name || "http auth multiple"); },
oneditprepare: function() {
function resizeRule(rule) {
var newWidth = rule.width();
rule.find('.red-ui-typedInput').typedInput("width", (newWidth - 15) / 2);

}
var authList = $("#node-input-auths-container").css('min-height', '150px').css('min-width', '450px')
.editableList({
addItem: function(container, i, auth) {
var row = $('<div/>').appendTo(container);

var propertyUser = $('<input/>', { class: "node-input-auth-user", type: "text", style: "width: 30%;", placeholder: "user" })
.appendTo(row);

var propertyRealm = $('<input/>', { class: "node-input-auth-realm", type: "text", style: "margin-left: 3%; width: 30%;", placeholder: "realm" })
.appendTo(row);

var propertyPassword = $('<input/>', { class: "node-input-auth-password", type: "text", style: "margin-left: 3%; width: 30%;", placeholder: "password" })
.appendTo(row);

propertyUser.val(auth.user);
propertyRealm.val(auth.realm);
propertyPassword.val(auth.password);

resizeRule(container);
},
resizeItem: resizeRule,
removable: true
});

if (this.auths) {
for (var key in this.auths) {
if ((this.auths[key]).length) {
this.auths[key].forEach(function(value, index) {
authList.editableList('addItem', { realm: key, user: value.user, password: value.password });
})
}
}
}
},
oneditsave: function() {
var auths = $("#node-input-auths-container").editableList('items');
var node = this;
node.auths = {};
auths.each(function(i) {
var auth = $(this);
var user = auth.find(".node-input-auth-user").val();
var realm = auth.find(".node-input-auth-realm").val();
var password = auth.find(".node-input-auth-password").val();

if (!node.auths[realm]) {
node.auths[realm] = [];
}

if (realm && user && password) {
node.auths[realm].push({
"user": user,
"password": password
});
}
});

},
paletteLabel: "http auth"
});
</script>
<script type="text/x-red" data-template-name="node-red-contrib-httpauthmultiple">
<div class="form-row">
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="texth" id="node-config-input-name">
</div>
<div class="form-row">
<label for="node-input-authType"><i class="fa fa-list"></i> Auth Type</label>
<select id="node-input-authType">
<option value="Basic">Basic</option>
<option value="Digest">Digest</option>
</select>
</div>
<div class="form-row">
<label for="node-config-input-realm"><i class="fa fa-globe"></i> Realm</label>
<input type="text" id="node-config-input-realm">
</div>
<div class="form-row">
<label for="node-config-input-hashed"><i class="fa fa-asterisk"></i> Hashed</label>
<input type="checkbox" id="node-config-input-hashed">
</div>
<div class="form-row">
<label><i class="fa fa-list"></i> Auths</span>
</label>
</div>
<div class="form-row node-input-auths-container-row">
<ol id="node-input-auths-container"></ol>
</div>
</script>
53 changes: 53 additions & 0 deletions nodes/http-auth-multiple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
var fs = require("fs");

module.exports = function(RED) {
"use strict";

function HttpAuthMultipleNode(config) {
RED.nodes.createNode(this, config);

var authType = config.authType;
var realm = config.realm.trim();
var realmL = realm.toLowerCase();
var hashed = config.hashed;
var users = {};
for (var key in config.auths) {

config.auths[key].forEach(function(value, index) {

var _username = value.user.trim();
var _usernameL = _username.toLowerCase();
var _realm = key;
var _realmL = _realm.toLowerCase();
var _password = value.password;

if (_realmL == realmL) {
users[_usernameL] = {
realm: _realm,
username: _username,
password: _password,
hashed: hashed
};
}
});
}

this.authType = config.authType;
this.realm = config.realm;
this.getUser = function(_realm, _username) {
var _realmL = _realm.trim().toLowerCase();
var _usernameL = _username.trim().toLowerCase();
if (_realmL == realmL && users[_usernameL]) {
return {
realm: users[_usernameL].realm,
username: users[_usernameL].username,
password: users[_usernameL].password,
hashed: users[_usernameL].hashed
};
}
return null;
};
}

RED.nodes.registerType("node-red-contrib-httpauthmultiple", HttpAuthMultipleNode);
};
204 changes: 99 additions & 105 deletions nodes/http-auth.html
Original file line number Diff line number Diff line change
@@ -1,111 +1,105 @@
<script type="text/javascript">
RED.nodes.registerType("node-red-contrib-httpauth", {
category: "function",
inputs: 1,
outputs: 1,
defaults: {
name: {value: ""},
file: {value: "", type: "node-red-contrib-httpauthfile", required: false},
cred: {value: "", type: "node-red-contrib-httpauthcred", required: false},
authType: {value: "Basic"},
realm: {value: ""},
username: {value: ""},
password: {value: ""},
hashed: {value: false}
},
color: "#E7E7AE",
icon: "white-globe.png",
label: function() {return this.name.trim() || "http auth";},
labelStyle: function() {return this.name.trim() ? "node_label_italic" : "";},
paletteLabel: "http auth"
});
RED.nodes.registerType("node-red-contrib-httpauth", {
category: "function",
inputs: 1,
outputs: 1,
defaults: {
name: { value: "" },
file: { value: "", type: "node-red-contrib-httpauthfile", required: false },
cred: { value: "", type: "node-red-contrib-httpauthcred", required: false },
multiple: { value: "", type: "node-red-contrib-httpauthmultiple", required: false },
authType: { value: "Basic" },
realm: { value: "" },
username: { value: "" },
password: { value: "" },
hashed: { value: false }
},
color: "#E7E7AE",
icon: "white-globe.png",
label: function() { return this.name.trim() || "http auth"; },
labelStyle: function() { return this.name.trim() ? "node_label_italic" : ""; },
paletteLabel: "http auth"
});
</script>

<script type="text/x-red" data-template-name="node-red-contrib-httpauth">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name">
</div>
<hr />
<div class="form-row">
<label for="node-input-file"><i class="fa fa-list"></i> File</label>
<input type="text" id="node-input-file">
</div>
<hr />
<div class="form-row">
<label for="node-input-cred"><i class="fa fa-list"></i> Credentials</label>
<input type="text" id="node-input-cred">
</div>
<hr />
<div class="form-row">
<label for="node-input-authType"><i class="fa fa-list"></i> Auth Type</label>
<select id="node-input-authType">
<option value="Basic">Basic</option>
<option value="Digest">Digest</option>
</select>
</div>
<div class="form-row">
<label for="node-input-realm"><i class="fa fa-globe"></i> Realm</label>
<input type="text" id="node-input-realm">
</div>
<div class="form-row">
<label for="node-input-username"><i class="fa fa-user"></i> Username</label>
<input type="text" id="node-input-username">
</div>
<div class="form-row">
<label for="node-input-password"><i class="fa fa-key"></i> Password</label>
<input type="text" id="node-input-password">
</div>
<div class="form-row">
<label for="node-input-hashed"><i class="fa fa-asterisk"></i> Hashed</label>
<input type="checkbox" id="node-input-hashed">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name">
</div>
<hr />
<div class="form-row">
<label for="node-input-file"><i class="fa fa-list"></i> File</label>
<input type="text" id="node-input-file">
</div>
<hr />
<div class="form-row">
<label for="node-input-cred"><i class="fa fa-list"></i> Credentials</label>
<input type="text" id="node-input-cred">
</div>
<hr />
<div class="form-row">
<label for="node-input-multiple"><i class="fa fa-list"></i> Multiple</label>
<input type="text" id="node-input-multiple">
</div>
<hr />
<div class="form-row">
<label for="node-input-authType"><i class="fa fa-list"></i> Auth Type</label>
<select id="node-input-authType">
<option value="Basic">Basic</option>
<option value="Digest">Digest</option>
</select>
</div>
<div class="form-row">
<label for="node-input-realm"><i class="fa fa-globe"></i> Realm</label>
<input type="text" id="node-input-realm">
</div>
<div class="form-row">
<label for="node-input-username"><i class="fa fa-user"></i> Username</label>
<input type="text" id="node-input-username">
</div>
<div class="form-row">
<label for="node-input-password"><i class="fa fa-key"></i> Password</label>
<input type="text" id="node-input-password">
</div>
<div class="form-row">
<label for="node-input-hashed"><i class="fa fa-asterisk"></i> Hashed</label>
<input type="checkbox" id="node-input-hashed">
</div>
</script>

<script type="text/x-red" data-help-name="node-red-contrib-httpauth">
<p>Node-RED node for HTTP Basic/Digest Auth</p>

<p>This Node-RED module performs Basic and Digest authentication.<br />It is to be used in conjunction with an http input node.</p>

<img src="https://raw.githubusercontent.com/endemecio02/node-red-contrib-httpauth/master/images/flow.png" />

<h2>Config</h2>

<img src="https://raw.githubusercontent.com/endemecio02/node-red-contrib-httpauth/master/images/config.png" />

<p>There are three type of configuration:</p>
<ol>
<li>File: the user credentials are stored in a file. (mutliple credentials)</li>
<li>Shared: credentials shared which multiple nodes. (one credential)</li>
<li>Not Shared: each node has it's own credentials. (one credential)</li>
</ol>

<p>With all three config types you must specify the following:</p>
<ul>
<li>Auth Type: what authentication type will be used: Basic, Digest</li>
<li>Realm: what realm will be used with this node</li>
<li>Hashed: are the passwords in the Password field or in the credentials file hashed.<br />
This field is only relavent if Auth Type is Digest. It has no effect on Basic.<br />
Hash format: MD5(Username:Realm:Password)</li>
</ul>

<p>With Shared and Not Shared config types you must specify the following:</p>
<ul>
<li>Username: the username</li>
<li>Password: the password<br />
If you entered a hashed password you must check the Hashed checkbox.</li>
</ul>

<p>With File config type you must specify the following:</p>
<ul>
<li>File: location of the file containing the credentials relative to the presently working directory<br />
If the password are hashed you must check the Hashed checkbox.</li>
</ul>
<h3>File Configuration</h3>

<img src="https://raw.githubusercontent.com/endemecio02/node-red-contrib-httpauth/master/images/file.png" />

<h3>Shared config</h3>

<img src="https://raw.githubusercontent.com/endemecio02/node-red-contrib-httpauth/master/images/cred.png" />
<p>Node-RED node for HTTP Basic/Digest Auth</p>
<p>This Node-RED module performs Basic and Digest authentication.
<br />It is to be used in conjunction with an http input node.</p>
<img src="https://raw.githubusercontent.com/endemecio02/node-red-contrib-httpauth/master/images/flow.png" />
<h2>Config</h2>
<img src="https://raw.githubusercontent.com/endemecio02/node-red-contrib-httpauth/master/images/config.png" />
<p>There are three type of configuration:</p>
<ol>
<li>File: the user credentials are stored in a file. (mutliple credentials)</li>
<li>Shared: credentials shared which multiple nodes. (one credential)</li>
<li>Not Shared: each node has it's own credentials. (one credential)</li>
</ol>
<p>With all three config types you must specify the following:</p>
<ul>
<li>Auth Type: what authentication type will be used: Basic, Digest</li>
<li>Realm: what realm will be used with this node</li>
<li>Hashed: are the passwords in the Password field or in the credentials file hashed.
<br /> This field is only relavent if Auth Type is Digest. It has no effect on Basic.
<br /> Hash format: MD5(Username:Realm:Password)</li>
</ul>
<p>With Shared and Not Shared config types you must specify the following:</p>
<ul>
<li>Username: the username</li>
<li>Password: the password
<br /> If you entered a hashed password you must check the Hashed checkbox.</li>
</ul>
<p>With File config type you must specify the following:</p>
<ul>
<li>File: location of the file containing the credentials relative to the presently working directory
<br /> If the password are hashed you must check the Hashed checkbox.</li>
</ul>
<h3>File Configuration</h3>
<img src="https://raw.githubusercontent.com/endemecio02/node-red-contrib-httpauth/master/images/file.png" />
<h3>Shared config</h3>
<img src="https://raw.githubusercontent.com/endemecio02/node-red-contrib-httpauth/master/images/cred.png" />
</script>
9 changes: 9 additions & 0 deletions nodes/http-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ module.exports = function(RED) {
getUser = file.getUser;
}

var multiple = RED.nodes.getNode(config.multiple);
if (multiple) {
src = "multiple";
authType = multiple.authType;
realm = multiple.realm.trim();
realmL = realm.toLowerCase();
getUser = multiple.getUser;
}

this.httpauthconf = {};
this.httpauthconf.src = src;
this.httpauthconf.authType = authType;
Expand Down
Loading