Create custom Node-Red node to save the third party login credential securely

Karthik Suresh
2 min readFeb 24, 2021
image source: https://nodered.org/about/resources/media/node-red-icon.png

Node-Red credential node (node-red-contrib-credentials) exactly serve the purpose where the exported json would not contain the plain text credentials. But the credentials are visible in plain text.

There problem would be if a non-admin user can see the plain text credentials and we cannot disable the flow for a particular node-RED user because runtime is not a multi-tenant system with each user getting their own set of flows — All users share the same flows.

Credentials Node

There was a need to mask the password and credentials node does not support this feature yet!.

Let’s create a custom node for this use case.
A simple node would constitute of
1. package.json
2. login.js
3. login.html

1. Create a package.json file with “npm init” and typing the answers for series of questions.

package.json

2. Create a login.js file with a function which takes a single argument RED that provides the module access to the Node-RED runtime api.

To add a credentials to a node define the credentials and RED.nodes.registerType must be updated to include the credentials

login.js

3. Create a login.html file and add suitable entries to the edit template of the node.

<input type=”text” id=”node-input-username”>

<input type=”password” id=”node-input-password”>

login.html

Now finally import the custom node navigating to your user directory and .node-red folder and execute

npm install “{absolute path of the folder containing all three files}”

Restart the node-red and the custom node should be visible in the palette

Login Node

References:
https://nodered.org/docs/creating-nodes/first-node
https://nodered.org/docs/creating-nodes/credentials

Source Code:
https://github.com/karthiksuresh6666/Node-Red/blob/main/login.js

--

--