From 33f3f3eaed96cf9bd86bd532d09baf162369074d Mon Sep 17 00:00:00 2001 From: Paulo Albuquerque Date: Tue, 12 Dec 2017 20:00:02 -0200 Subject: [PATCH 1/4] Inserted multiple users through list. --- nodes/http-auth-multiple.html | 107 ++++++++++++++++++ nodes/http-auth-multiple.js | 53 +++++++++ nodes/http-auth.html | 204 +++++++++++++++++----------------- package.json | 80 ++++++++++--- 4 files changed, 321 insertions(+), 123 deletions(-) create mode 100644 nodes/http-auth-multiple.html create mode 100644 nodes/http-auth-multiple.js diff --git a/nodes/http-auth-multiple.html b/nodes/http-auth-multiple.html new file mode 100644 index 0000000..f06d004 --- /dev/null +++ b/nodes/http-auth-multiple.html @@ -0,0 +1,107 @@ + + \ No newline at end of file diff --git a/nodes/http-auth-multiple.js b/nodes/http-auth-multiple.js new file mode 100644 index 0000000..b9d7ebc --- /dev/null +++ b/nodes/http-auth-multiple.js @@ -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); +}; \ No newline at end of file diff --git a/nodes/http-auth.html b/nodes/http-auth.html index 23995fb..911ea6f 100644 --- a/nodes/http-auth.html +++ b/nodes/http-auth.html @@ -1,111 +1,105 @@ - - \ No newline at end of file diff --git a/package.json b/package.json index 8cd9392..f410d06 100644 --- a/package.json +++ b/package.json @@ -1,30 +1,74 @@ { - "name": "node-red-contrib-httpauth", - "version": "1.0.12", - "description": "Node which implements HTTP Basic/Digest Authorization.", - "keywords": [ - "node-red", - "http", - "authorization", - "basic", - "digest" + "_from": "git+https://github.com/pjalbuquerque/node-red-contrib-httpauth.git", + "_id": "node-red-contrib-httpauth@1.0.12", + "_inBundle": false, + "_location": "/node-red-contrib-httpauth", + "_phantomChildren": {}, + "_requested": { + "type": "git", + "raw": "https://github.com/pjalbuquerque/node-red-contrib-httpauth.git", + "rawSpec": "https://github.com/pjalbuquerque/node-red-contrib-httpauth.git", + "saveSpec": "git+https://github.com/pjalbuquerque/node-red-contrib-httpauth.git", + "fetchSpec": "https://github.com/pjalbuquerque/node-red-contrib-httpauth.git", + "gitCommittish": null + }, + "_requiredBy": [ + "#USER", + "/" ], - "author": "Endemecio Santana", - "license": "GPL-2.0", - "dependencies": { + "_resolved": "git+https://github.com/pjalbuquerque/node-red-contrib-httpauth.git#64cec192cb907141387abdc6855c1a7c7ddcca5e", + "_spec": "https://github.com/pjalbuquerque/node-red-contrib-httpauth.git", + "_where": "/Users/Paulo/.node-red", + "author": { + "name": "Endemecio Santana" }, - "repository": { - "type": "git", - "url": "https://github.com/endemecio02/node-red-contrib-httpauth.git" + "bugs": { + "url": "https://github.com/endemecio02/node-red-contrib-httpauth/issues" }, + "bundleDependencies": false, + "dependencies": {}, + "deprecated": false, + "description": "Node which implements HTTP Basic/Digest Authorization.", "engines": { - "node": "^0.12.7" + "node": "^0.12.7" }, + "homepage": "https://github.com/endemecio02/node-red-contrib-httpauth#readme", + "keywords": [ + "node-red", + "http", + "authorization", + "basic", + "digest" + ], + "license": "GPL-2.0", + "name": "node-red-contrib-httpauth", "node-red": { "nodes": { "node-red-contrib-httpauth": "nodes/http-auth.js", "node-red-contrib-httpauthcred": "nodes/http-auth-cred.js", - "node-red-contrib-httpauthfile": "nodes/http-auth-file.js" + "node-red-contrib-httpauthfile": "nodes/http-auth-file.js", + "node-red-contrib-httpauthmultiple": "nodes/http-auth-multiple.js" + } + }, + "repository": { + "type": "git", + "url": "git+https://github.com/endemecio02/node-red-contrib-httpauth.git" + }, + "version": "1.0.12", + "warnings": [ + { + "code": "ENOTSUP", + "required": { + "node": "^0.12.7" + }, + "pkgid": "node-red-contrib-httpauth@1.0.12" + }, + { + "code": "ENOTSUP", + "required": { + "node": "^0.12.7" + }, + "pkgid": "node-red-contrib-httpauth@1.0.12" } - } + ] } From 5db5dabdb1cdcc376f59e9939daa424ab133c60b Mon Sep 17 00:00:00 2001 From: Paulo Albuquerque Date: Tue, 12 Dec 2017 20:20:14 -0200 Subject: [PATCH 2/4] Update list --- nodes/http-auth.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nodes/http-auth.js b/nodes/http-auth.js index 68ca63f..896ff40 100644 --- a/nodes/http-auth.js +++ b/nodes/http-auth.js @@ -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; From 1396faf2266067e2feb351a5c05462218cab80df Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 12 Oct 2023 17:56:39 +0200 Subject: [PATCH 3/4] Inserted multiple users through list. Re-apply https://github.com/endemecio02/node-red-contrib-httpauth/pull/4 by @pjalbuquerque --- nodes/http-auth-multiple.html | 189 +++++++++++++++++----------------- nodes/http-auth-multiple.js | 97 ++++++++--------- nodes/http-auth.html | 11 +- nodes/http-auth.js | 5 +- 4 files changed, 149 insertions(+), 153 deletions(-) diff --git a/nodes/http-auth-multiple.html b/nodes/http-auth-multiple.html index f06d004..368e8cb 100644 --- a/nodes/http-auth-multiple.html +++ b/nodes/http-auth-multiple.html @@ -1,107 +1,104 @@ - \ No newline at end of file + + + +
+ + +
+
+ +
+
+
    +
    + diff --git a/nodes/http-auth-multiple.js b/nodes/http-auth-multiple.js index b9d7ebc..2b416cc 100644 --- a/nodes/http-auth-multiple.js +++ b/nodes/http-auth-multiple.js @@ -1,53 +1,44 @@ -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); -}; \ No newline at end of file +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); +}; diff --git a/nodes/http-auth.html b/nodes/http-auth.html index 41bcae3..abb112b 100644 --- a/nodes/http-auth.html +++ b/nodes/http-auth.html @@ -8,6 +8,7 @@ name: { value: '' }, file: { value: '', type: 'http-basic-auth-file', required: false }, cred: { value: '', type: 'http-basic-auth-cred', required: false }, + multiple: { value: '', type: 'http-basic-auth-multiple', required: false }, realm: { value: '' }, username: { value: '' }, password: { value: '' }, @@ -54,7 +55,15 @@
    - Option 3: File + Option 3: Multiple +
    + + +
    +
    + +
    + Option 4: File
    diff --git a/nodes/http-auth.js b/nodes/http-auth.js index 1aa113b..caac187 100644 --- a/nodes/http-auth.js +++ b/nodes/http-auth.js @@ -82,10 +82,9 @@ module.exports = function (RED) { getUser = file.getUser; } - var multiple = RED.nodes.getNode(config.multiple); + const multiple = RED.nodes.getNode(config.multiple); if (multiple) { - src = "multiple"; - authType = multiple.authType; + src = 'multiple'; realm = multiple.realm.trim(); realmL = realm.toLowerCase(); getUser = multiple.getUser; From e07ae94f8102a0a0c861795db979df5da5c5b0f0 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 12 Oct 2023 21:39:08 +0200 Subject: [PATCH 4/4] Remove http-basic-auth-cred, replaced by http-basic-auth-multiple --- README.md | 41 +++++++++++++------------ nodes/http-auth-cred.html | 34 -------------------- nodes/http-auth-cred.js | 13 -------- nodes/http-auth-multiple.html | 11 ------- nodes/http-auth.html | 58 +++++++++++++++-------------------- nodes/http-auth.js | 26 +++++----------- package-lock.json | 23 ++++++++------ package.json | 12 +++++--- 8 files changed, 75 insertions(+), 143 deletions(-) delete mode 100644 nodes/http-auth-cred.html delete mode 100644 nodes/http-auth-cred.js diff --git a/README.md b/README.md index e9c05c5..af98a7f 100644 --- a/README.md +++ b/README.md @@ -22,36 +22,39 @@ curl 'https://test:test@nodered.example.net/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: + -- 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 diff --git a/nodes/http-auth-cred.html b/nodes/http-auth-cred.html deleted file mode 100644 index 328d53b..0000000 --- a/nodes/http-auth-cred.html +++ /dev/null @@ -1,34 +0,0 @@ - - - diff --git a/nodes/http-auth-cred.js b/nodes/http-auth-cred.js deleted file mode 100644 index 96269e2..0000000 --- a/nodes/http-auth-cred.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function (RED) { - 'use strict'; - - function HttpAuthCredNode(config) { - RED.nodes.createNode(this, config); - - this.realm = config.realm; - this.username = config.username; - this.password = config.password; - } - - RED.nodes.registerType('http-basic-auth-cred', HttpAuthCredNode); -}; diff --git a/nodes/http-auth-multiple.html b/nodes/http-auth-multiple.html index 368e8cb..ba12823 100644 --- a/nodes/http-auth-multiple.html +++ b/nodes/http-auth-multiple.html @@ -79,21 +79,10 @@
    -
    - - -
    -
    - - -
    diff --git a/nodes/http-auth.html b/nodes/http-auth.html index abb112b..e3eae5e 100644 --- a/nodes/http-auth.html +++ b/nodes/http-auth.html @@ -7,7 +7,6 @@ defaults: { name: { value: '' }, file: { value: '', type: 'http-basic-auth-file', required: false }, - cred: { value: '', type: 'http-basic-auth-cred', required: false }, multiple: { value: '', type: 'http-basic-auth-multiple', required: false }, realm: { value: '' }, username: { value: '' }, @@ -47,23 +46,15 @@
    - Option 2: Shared + Option 2: Multiple credentials
    - - -
    -
    - -
    - Option 3: Multiple -
    - +
    - Option 4: File + Option 3: File with multiple credentials
    @@ -84,32 +75,31 @@

    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. -
    3. Shared: credentials shared with multiple nodes. (one credential)
    4. -
    5. File: the user credentials are stored in a file. (multiple credentials)
    6. +
    7. Multiple credentials: credentials shared with multiple nodes. (multiple credentials)
    8. +
    9. File with multiple credentials: the user credentials are stored in a file. (multiple credentials)
    -

    With all three config types you must specify the following:

    -
      -
    • Realm: what authorization realm will be used with this node
    • -
    +

    Definitions

    +
    +
    Username
    +
    The username
    +
    Example: alice + +
    Realm
    +
    Authorization realm for which the credentials will be valid
    +
    Example: node-red
    -

    With Simple and Shared config types you must specify the following:

    -
      -
    • Username: the username
    • -
    • - Password: the password may be in plain-text or hashed (only bcrypt is supported). -
    • -
    +
    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
    -

    With File config type you must specify the following:

    -
      -
    • - 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). -
    • -
    +
    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
    +
    diff --git a/nodes/http-auth.js b/nodes/http-auth.js index caac187..d122e3f 100644 --- a/nodes/http-auth.js +++ b/nodes/http-auth.js @@ -50,9 +50,9 @@ module.exports = function (RED) { let src = 'inline'; let realm = config.realm.trim(); let realmL = realm.toLowerCase(); - let username = config.username.trim(); - let usernameL = username.toLowerCase(); - let password = config.password; + const username = config.username.trim(); + const usernameL = username.toLowerCase(); + const password = config.password; let getUser = function (_realm, _username) { if (_realm.trim().toLowerCase() === realmL && _username.trim().toLowerCase() === usernameL) { return { @@ -64,14 +64,12 @@ module.exports = function (RED) { return null; }; - const cred = RED.nodes.getNode(config.cred); - if (cred) { - src = 'cred'; - realm = cred.realm.trim(); + const multiple = RED.nodes.getNode(config.multiple); + if (multiple) { + src = 'multiple'; + realm = multiple.realm.trim(); realmL = realm.toLowerCase(); - username = cred.username.trim(); - usernameL = username.toLowerCase(); - password = cred.password; + getUser = multiple.getUser; } const file = RED.nodes.getNode(config.file); @@ -82,14 +80,6 @@ module.exports = function (RED) { getUser = file.getUser; } - const multiple = RED.nodes.getNode(config.multiple); - if (multiple) { - src = 'multiple'; - realm = multiple.realm.trim(); - realmL = realm.toLowerCase(); - getUser = multiple.getUser; - } - this.httpauthconf = {}; this.httpauthconf.src = src; this.httpauthconf.realm = realm; diff --git a/package-lock.json b/package-lock.json index c143763..6c434bd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@alexandrainst/node-red-http-basic-auth", - "version": "2.3.0", + "version": "3.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@alexandrainst/node-red-http-basic-auth", - "version": "2.3.0", + "version": "3.0.0", "license": "GPL-2.0", "dependencies": { "bcryptjs": "^2.4.3" @@ -18,7 +18,7 @@ "eslint-plugin-import": "^2.28.1", "eslint-plugin-n": "^16.1.0", "eslint-plugin-promise": "^6.1.1", - "node-red-contrib-mock-cli": "^1.3.1" + "node-red-contrib-mock-cli": "^1.4.0" }, "engines": { "node": ">=12" @@ -1271,10 +1271,13 @@ "devOptional": true }, "node_modules/function-bind": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", - "dev": true + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } }, "node_modules/function.prototype.name": { "version": "1.1.6", @@ -2097,9 +2100,9 @@ } }, "node_modules/node-red-contrib-mock-cli": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/node-red-contrib-mock-cli/-/node-red-contrib-mock-cli-1.3.1.tgz", - "integrity": "sha512-Xt48d6VuPa5SgHvTBh5+mOyGkJZhPQ2ts7QHdufGCdaUWf3XmGa4NjHEtyRBhSVYf4Te222WZ+Pq8EASC86sDg==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/node-red-contrib-mock-cli/-/node-red-contrib-mock-cli-1.4.0.tgz", + "integrity": "sha512-z5HE5hTZiZ1lcariugJWhhF2YJpTSnIYWjB6PK/WO1fgtx8iumRw8LHrW2wLoD0QB0CA/laaAymSwZVLjRxBmQ==", "dev": true, "engines": { "node": ">=8" diff --git a/package.json b/package.json index eacb45f..9efcbb4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@alexandrainst/node-red-http-basic-auth", - "version": "2.3.0", + "version": "3.0.0", "description": "Node-RED node for HTTP Basic Authorization", "keywords": [ "node-red", @@ -20,6 +20,10 @@ { "name": "Endemecio Santana", "url": "https://github.com/endemecio02" + }, + { + "name": "Paulo Albuquerque", + "url": "https://github.com/pjalbuquerque" } ], "license": "GPL-2.0", @@ -34,8 +38,8 @@ "version": ">=2.0.0", "nodes": { "http-basic-auth": "nodes/http-auth.js", - "http-basic-auth-cred": "nodes/http-auth-cred.js", - "http-basic-auth-file": "nodes/http-auth-file.js" + "http-basic-auth-file": "nodes/http-auth-file.js", + "http-basic-auth-multiple": "nodes/http-auth-multiple.js" } }, "dependencies": { @@ -51,7 +55,7 @@ "eslint-plugin-import": "^2.28.1", "eslint-plugin-n": "^16.1.0", "eslint-plugin-promise": "^6.1.1", - "node-red-contrib-mock-cli": "^1.3.1" + "node-red-contrib-mock-cli": "^1.4.0" }, "scripts": { "start": "node ./index.js",