Mosquitto: MQTT API authentication with Node-RED

This documentation is part of the API authentication guide. View the full guide here: How to authenticate thousands of devices using an external API.

👋 Welcome to the Stackhero documentation!

Stackhero offers a ready-to-use Mosquitto MQTT cloud solution that provides a host of benefits, including:

  • Unlimited message exchanges and transfers.
  • Unlimited devices authentication via an external API.
  • Advanced ACLs on topics, users and actions.
  • Customizable domain name secured with HTTPS (for example, https://mqtt.your-company.com).
  • Effortless updates with just a click.
  • Optimal performance and robust security powered by a private and dedicated VM.

Save time and simplify your life: it only takes 5 minutes to try Stackhero's Mosquitto MQTT cloud hosting solution!

Stackhero for Node-RED includes a Mosquitto server. Nevertheless, for advanced usage, having a standalone Mosquitto service is recommended. This example shows how to use the API authentication system with a standalone Mosquitto service and a Node-RED service. If you use the Mosquitto service included with your Node-RED, this guide does not apply to you.

Stackhero for Node-RED provides an example of an MQTT API connection in the flow named "MQTT authentication." This flow is also used with the integrated Mosquitto server in Stackhero for Node-RED.

To use Node-RED as your API authentication endpoint, update your Mosquitto configuration as follows:

  1. Enable the API authentication option.
  2. Set the Host field to your Node-RED domain.
  3. Choose HTTPS as the Protocol and enter 443 for the Port.
  4. Specify the User route as /mqttAuthentication/userGet.
  5. Specify the ACLs route as /mqttAuthentication/aclCheck.

For debugging, you might set the "Authentication cache time" to 1 second. Once your setup is operating smoothly, the recommended value is 30 seconds.

Mosquitto configuration exampleMosquitto configuration example

After updating the Mosquitto configuration, launch Node-RED and open the MQTT authentication flow. Edit the Users node to configure your user credentials. The provided examples include several username and password combinations. Feel free to add as many users as necessary.

Node-RED MQTT authentication flowNode-RED MQTT authentication flow