Using Credentials on HTTP Request Nodes causes flow to not work on startup

Dear all,

I am currently trying to port my flow into an executable using electron-node-red: https://github.com/dceejay/electron-node-red.

I am compiling/building for a windows x64 system using electron packager within the mentioned repository and I have a http request node in the flow that uses basic authentication.

I have followed the following guide: https://nodered.org/docs/creating-nodes/credentials
The credentials can be added, and is stored within the application itself. This works across 3 different computers, both Windows 10 and Windows 7.

The main issue is that when Node-Red begins the service: the flow is loaded, the dashboard is initialised, but the credentials are not automatically converted into a _cred.json for usage in the flow.

Instead, it is required for me to open the editor within the application itself to merely shift/change a minor thing(such as node position), click deploy, and the _cred.json will be generated. Without doing this, I currently am unable to pass basic authentication from startup without touching the editor and clicking deploy.

Now, I know that it is possible to use an API call to post the flow to Node-RED in main.js(electron-node-red).
https://nodered.org/docs/api/admin/methods/post/flows/
This is very much doable by doing a POST request using the flowfile directory.

My main question: Is it possible in the future to make this much more simpler? Or is there a simpler way that I currently do not know of? My concern is that moving to different computers may create complications in terms of directories and operating systems. This can definitely be worked around, but it would be much nicer to add this improvement for user benefit.

An example of an improvement would be perhaps a RED.redeploy() function in js, though I know the current deploy.js also uses a POST request.

If you have a flow with credentials in then you must already have a _creds file alongside your flow file. Why are you not including that when you build your image?

2 Likes

Thank you for replying,

How do I include the _cred.json into the windows application when building using electron-packager? is it a variable i include in settings when packaging?

I couldn't find any examples of building with a _cred.json alongside a flowfile, and I couldn't find the setting for _cred.json in the default settings.js.

Thank you.

in my default electron project there are two files elecronflow.json and electronflow_cred.json
They are the default files used first time the app is run to provide an initial dashboard and flow app - you should be able to replace both of those (using the same name)

1 Like

Dear all,

Thank you for replying and helping out.

I found the solution which was to include the _cred.json file within package.json before building into an executable on Windows. This was done by adding a "files" array in package.json.

Replacing dceejay's cred file did not work as previously stated. The _cred.json seemed to be ignored when packaged, resulting in empty credentials. This was remedied by the solution above.

For anyone else reading, the new machine should have the same secret-key u used when deploying the flow. This is how the _cred.json file is encrypted, so without the key you will not be able to decrypt the _cred.json. Check this secret key in your default setting.js on the new machine when exporting the executable. I have yet to devise a programmatic way of automatically changing the default setting.js on a new machine when running the executable.

As a side question, is there any proper documentation on the Node-RED's runtime API? I specifically mean the javascript module, not the HTTP endpoints. It will save time trawling through the node-red github and make it more accessible.

https://nodered.org/docs/api/

1 Like