Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect fails silently if no username is provided but only a password #1685

Open
AuspeXeu opened this issue Sep 5, 2023 · 3 comments
Open

Comments

@AuspeXeu
Copy link

AuspeXeu commented Sep 5, 2023

Consider the following piece of code.

import Server, { AuthenticateError } from 'aedes';
import * as net from 'net';
import { connect } from 'mqtt';

const mqttServer = new Server({
  authenticate(_, __, password, callback) {
    if (password?.toString() !== 'MY GOOD SECURE PASSWORD') {
      const error: AuthenticateError = { ...new Error('Auth error'), returnCode: 4 };
      callback(error, null);
    } else {
      callback(null, true);
    }
  }
});

net
  .createServer(mqttServer.handle)
  .on('error', (err) => console.error(err))
  .listen(1883, '192.168.0.21', () => {
    console.log(`Aedes server listening on 192.168.0.21:1883`);
    const mqttClient = connect('mqtt://192.168.0.21', {
      // username: 'does-not-matter',
      password: 'MY GOOD SECURE PASSWORD',
      reconnectPeriod: 2 * 1000
    })
  })

In this example, the client will never connect and you will never find out why until you comment the username back in.

@robertsLando
Copy link
Member

Would you like to submit a PR to fix this?

rts-rob added a commit to rts-rob/MQTT.js that referenced this issue Oct 24, 2023
Copy link

github-actions bot commented Sep 5, 2024

This is an automated message to let you know that this issue has
gone 365 days without any activity. In order to ensure that we work
on issues that still matter, this issue will be closed in 14 days.

If this issue is still important, you can simply comment with a
"bump" to keep it open.

Thank you for your contribution.

@github-actions github-actions bot added the stale label Sep 5, 2024
@AuspeXeu
Copy link
Author

AuspeXeu commented Sep 5, 2024

Bump

@github-actions github-actions bot removed the stale label Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants