-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into two-outputs
- Loading branch information
Showing
9 changed files
with
209 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,36 +22,39 @@ curl 'https://test:[email protected]/basic-auth-demo' | |
|
||
## Config | ||
|
||
There are three type of configuration: | ||
There are three types of configuration: | ||
|
||
1. *Simple*: each node has it’s own credentials. (one credential) | ||
2. *Shared*: credentials shared with multiple nodes. (one credential) | ||
3. *File*: the user credentials are stored in a file. (multiple credentials) | ||
2. *Multiple credentials*: credentials shared with multiple nodes. (multiple credentials) | ||
3. *File with multiple credentials*: the user credentials are stored in a file. (multiple credentials) | ||
|
||
With all three config types you must specify the following: | ||
## Definitions | ||
|
||
- *Realm*: what authorization realm will be used with this node. | ||
* *Username* | ||
* The username | ||
* Example: `alice` | ||
|
||
With *Simple* and *Shared* config types you must specify the following: | ||
* *Realm* | ||
* Authorization realm for which the credentials will be valid | ||
* Example: `node-red` | ||
|
||
- *Username*: the username | ||
- *Password*: the password may be in plain-text or hashed (only bcrypt is supported). | ||
Example of hashed password `test`: | ||
* *Password* | ||
* The password may be in plain-text or hashed (only bcrypt is supported) | ||
* Example in plain-text: `test` | ||
* Example in bcrypt: `$2y$10$5TSZDldoJ7MxDZdtK/SG2O3cwORqLDhHabYlKX9OsM.W/Z/oLwKW6` | ||
|
||
```plain | ||
$2y$10$5TSZDldoJ7MxDZdtK/SG2O3cwORqLDhHabYlKX9OsM.W/Z/oLwKW6 | ||
``` | ||
* *File* | ||
* Location of the file containing the credentials relative to the presently working directory | ||
* Example: `/data/.credentials` | ||
* The format for each line is `user:realm:password` | ||
|
||
With *File* config type you must specify the following: | ||
</dl> | ||
|
||
- File: location of the file containing the credentials relative to the presently working directory. | ||
The format for each line is `user:realm:password`. | ||
The passwords may be in plain-text or hashed (only bcrypt is supported). | ||
Example of file: | ||
Example of file: | ||
|
||
```plain | ||
user1:application1:test | ||
user2:application1:$2y$10$5TSZDldoJ7MxDZdtK/SG2O3cwORqLDhHabYlKX9OsM.W/Z/oLwKW6 | ||
user1:node-red:test | ||
user2:node-red:$2y$10$5TSZDldoJ7MxDZdtK/SG2O3cwORqLDhHabYlKX9OsM.W/Z/oLwKW6 | ||
``` | ||
|
||
## Hints | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<script type="text/javascript"> | ||
/* global RED:false, $:false */ | ||
RED.nodes.registerType('http-basic-auth-multiple', { | ||
category: 'config', | ||
defaults: { | ||
name: { value: '' }, | ||
realm: { value: '', required: true }, | ||
auths: { value: {} }, | ||
}, | ||
color: '#E7E7AE', | ||
icon: 'white-globe.png', | ||
label: function () { return (this.name || 'http auth multiple'); }, | ||
oneditprepare: function () { | ||
function resizeRule(rule) { | ||
const newWidth = rule.width(); | ||
rule.find('.red-ui-typedInput').typedInput('width', (newWidth - 15) / 2); | ||
} | ||
const authList = $('#node-input-auths-container').css('min-height', '150px').css('min-width', '450px') | ||
.editableList({ | ||
addItem: function (container, i, auth) { | ||
const row = $('<div/>').appendTo(container); | ||
|
||
const propertyUser = $('<input/>', | ||
{ class: 'node-input-auth-user', type: 'text', style: 'width: 30%;', placeholder: 'user' }).appendTo(row); | ||
|
||
const propertyRealm = $('<input/>', | ||
{ class: 'node-input-auth-realm', type: 'text', style: 'margin-left: 3%; width: 30%;', placeholder: 'realm' }).appendTo(row); | ||
|
||
const 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 (const 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 () { | ||
const auths = $('#node-input-auths-container').editableList('items'); | ||
const node = this; | ||
node.auths = {}; | ||
auths.each(function (i) { | ||
const auth = $(this); | ||
const user = auth.find('.node-input-auth-user').val(); | ||
const realm = auth.find('.node-input-auth-realm').val(); | ||
const password = auth.find('.node-input-auth-password').val(); | ||
|
||
if (!node.auths[realm]) { | ||
node.auths[realm] = []; | ||
} | ||
|
||
if (realm && user && password) { | ||
node.auths[realm].push({ | ||
user, | ||
password, | ||
}); | ||
} | ||
}); | ||
}, | ||
paletteLabel: 'http auth', | ||
}); | ||
</script> | ||
<script type="text/x-red" data-template-name="http-basic-auth-multiple"> | ||
<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-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><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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module.exports = function (RED) { | ||
'use strict'; | ||
|
||
function HttpAuthMultipleNode(config) { | ||
RED.nodes.createNode(this, config); | ||
|
||
const realm = config.realm.trim(); | ||
const realmL = realm.toLowerCase(); | ||
const users = {}; | ||
for (const key in config.auths) { | ||
config.auths[key].forEach(function (value, index) { | ||
const _username = value.user.trim(); | ||
const _usernameL = _username.toLowerCase(); | ||
const _realm = key; | ||
const _realmL = _realm.toLowerCase(); | ||
const _password = value.password; | ||
|
||
if (_realmL === realmL) { | ||
users[_usernameL] = { | ||
realm: _realm, | ||
username: _username, | ||
password: _password, | ||
}; | ||
} | ||
}); | ||
} | ||
|
||
this.realm = config.realm; | ||
this.getUser = function (_realm, _username) { | ||
const _realmL = _realm.trim().toLowerCase(); | ||
const _usernameL = _username.trim().toLowerCase(); | ||
if (_realmL === realmL && users[_usernameL]) { | ||
return { | ||
realm: users[_usernameL].realm, | ||
username: users[_usernameL].username, | ||
password: users[_usernameL].password, | ||
}; | ||
} | ||
return null; | ||
}; | ||
} | ||
|
||
RED.nodes.registerType('http-basic-auth-multiple', HttpAuthMultipleNode); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.