Connection refused: Bad username or password
Hi! I'm trying to connect to a Thingstream broker running MQTT 3.1.1, using user and pass.
var username = "user";
var pass = "pass";
var client = mqtt.connect('mqtt:mqtt.thingstream.io',
{
username: username,
password: pass,
}
)
But I'm getting this error:
Error: Connection refused: Bad username or password
at MqttClient._handleConnack (\mqttNode\node_modules\mqtt\lib\client.js:1190:15)
at MqttClient._handlePacket (\mqttNode\node_modules\mqtt\lib\client.js:424:12)
at work (\mqttNode\node_modules\mqtt\lib\client.js:321:12)
at Writable.writable._write (\mqttNode\node_modules\mqtt\lib\client.js:335:5)
at doWrite (\mqttNode\node_modules\readable-stream\lib\_stream_writable.js:409:139)
at writeOrBuffer (\mqttNode\node_modules\readable-stream\lib\_stream_writable.js:398:5)
at Writable.write (\mqttNode\node_modules\readable-stream\lib\_stream_writable.js:307:11)
at Socket.ondata (internal/streams/readable.js:731:22)
at Socket.emit (events.js:400:28)
at addChunk (internal/streams/readable.js:293:12) {
code: 4
I'm able to connect without problems using mosquitto client.
Any suggestion? Thanks in advance!
Are the credentials just wrong?
Get Outlook for iOShttps://aka.ms/o0ukef
From: Nicolas @.> Sent: Friday, October 22, 2021 4:35:45 PM To: mqttjs/MQTT.js @.> Cc: Subscribed @.***> Subject: [mqttjs/MQTT.js] Connection refused: Bad username or password (Issue #1345)
Hi! I'm trying to connect to a Thingstream broker running MQTT 3.1.1, using user and pass.
var username = "user"; var pass = "pass";
var client = mqtt.connect('mqtt:mqtt.thingstream.io', { username: username, password: pass, } )
But I'm getting this error:
Error: Connection refused: Bad username or password at MqttClient._handleConnack (\mqttNode\node_modules\mqtt\lib\client.js:1190:15) at MqttClient._handlePacket (\mqttNode\node_modules\mqtt\lib\client.js:424:12) at work (\mqttNode\node_modules\mqtt\lib\client.js:321:12) at Writable.writable._write (\mqttNode\node_modules\mqtt\lib\client.js:335:5) at doWrite (\mqttNode\node_modules\readable-stream\lib_stream_writable.js:409:139) at writeOrBuffer (\mqttNode\node_modules\readable-stream\lib_stream_writable.js:398:5) at Writable.write (\mqttNode\node_modules\readable-stream\lib_stream_writable.js:307:11) at Socket.ondata (internal/streams/readable.js:731:22) at Socket.emit (events.js:400:28) at addChunk (internal/streams/readable.js:293:12) { code: 4
Any suggestion? Thanks in advance!
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmqttjs%2FMQTT.js%2Fissues%2F1345&data=04%7C01%7Cyoseph.maguire%40microsoft.com%7C5e006c7fd55542b8f5a208d995a3e8ff%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637705353483246087%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=y%2F8oaEUEoO3V4UEwBCfaipjPiA5UQWW1C4r4c4gcR3o%3D&reserved=0, or unsubscribehttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAB6VMLG52RQJSLVQU3YD2KDUIHKLDANCNFSM5GRNTBSA&data=04%7C01%7Cyoseph.maguire%40microsoft.com%7C5e006c7fd55542b8f5a208d995a3e8ff%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637705353483256079%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=4aZPbrMkhiYaFiTvpW7fE%2FhdgKhEfrT4dNBRXSDm71w%3D&reserved=0.
Nop, I'm able to connect without problems using mosquitto client.
Is that the correct way to specify a user and password? Thanks!
Probably because mosquitto_pub and mosquitto_sub bypass authentication on mosquitto. As i remember, there should be a root user called mosquitto that is always authorised on the mosquitto tools.
Is there a solution for this issue? I'm getting the same error connecting to RabbitMQ. I have 2 instances of the server, The first connected successfully but the second got this error. How can I fix this?
const client = mqtt.connect(mqtt://hostname:1883, {
username: "username",
password: "password",
});
when i put username and password mqtt does not work anymore
|camera | TypeError: Cannot read properties of undefined (reading 'resubscribe')
0|camera | at MqttClient.subscribe (/home/Shinobi/node_modules/mqtt/lib/client.js:701:27)
0|camera | at MqttClient.<anonymous> (/home/Shinobi/libs/notifications/mqtt.js:45:28)
0|camera | at MqttClient.emit (node:events:539:35)
0|camera | at Readable.<anonymous> (/home/Shinobi/node_modules/mqtt/lib/client.js:1863:14)
0|camera | at Readable.emit (node:events:527:28)
0|camera | at endReadableNT (/home/Shinobi/node_modules/readable-stream/lib/_stream_readable.js:1094:12)
0|camera | at processTicksAndRejections (node:internal/process/task_queues:83:21)
using command line client works fine with username and password
MQTT 5.0.0 BETA is now available! Try it out and give us feedback: npm i mqtt@beta. It may fix your issues
MQTT 5.0.0 BETA is now available! Try it out and give us feedback:
npm i mqtt@beta. It may fix your issues
I used the version 5.3.5 also have same issue.
Can you connect using another client with same username/password?
Can you connect using another client with same username/password?
Yes. I successfully used the MQTTX tool and same username/password to connect to our MQTT server.
My vue3 source code as below:
do you have a way to see what's coming to the broker? I would be curious to know what broker receives, I think it could be code/decode issue with the password/username, does they contain some strange char/symbol?
do you have a way to see what's coming to the broker? I would be curious to know what broker receives, I think it could be code/decode issue with the password/username, does they contain some strange char/symbol?
Hi RobertsLando, Thanks for you reply. Actually the username/password have ‘-’ symbol between the string word. How can I fixed this decode issue?
Mine was just a supposition, the - doesn't have any decode issue. I suggest you to try checking what the broker receives
Mine was just a supposition, the
-doesn't have any decode issue. I suggest you to try checking what the broker receives
Thanks for your suggestions. This is my fault. Because our MQTT broker setting the HTTP auth. The backend of the cloud server is responsible for verifying the username/password send by Websocket. Always return bad username/password when there is no response from the backend.
Closing this for now as I have a feel that when this happens it's most likely a user issue