Create custom Node-Red node to save the third party login credential securely
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.
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.
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
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”>
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
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