MQTTnet icon indicating copy to clipboard operation
MQTTnet copied to clipboard

Report unauthorized subscription

Open ygoe opened this issue 10 months ago • 3 comments

Describe the feature request

The public MQTT broker on broker.emqx.io doesn't allow subscribing to #. The client MQTTX tells me after I try that it has failed because I'm not authorized to do that. MQTTnet doesn't tell me. I've looked around for any members of the result object or the client itself but couldn't find anything and no exception is thrown. The subscription was apparently successful but I receive no data after that.

Which project is your feature request related to?

MQTTnet's MqttClient class, I guess, or anywhere, I don't know what you mean.

Describe the solution you'd like

Best would be an exception or some information in the MqttClientSubscribeResult class.

Describe alternatives you've considered

N/A

Additional context

Image

ygoe avatar Jan 31 '25 14:01 ygoe

Please provide a full code sample. Generally the broker does not deny subscriptions by default (event when subscribing to '#'). If you want to deny such a subscription please use the event InterceptingSubscriptionAsync. There you can set the response code to NotAuthorized etc. and thus deny the subscription.

chkr1011 avatar Oct 20 '25 11:10 chkr1011

Sorry, the requested information can no longer be found. But I guess I was using the MQTTnet client, not server. And that client just didn't tell me what the MQTTX application could. So it appeared to me that MQTTnet client silently ignores error responses from a broker.

ygoe avatar Oct 21 '25 12:10 ygoe

The method SubscribeAsyncreturns a MqttClientSubscribeResult which has Items. One per topic filter which as sent before. Such an item has a ResultCode which should contain the same error code. But it requires that you set the protocol version to 5.0.0. Otherwise the error code are very limited. Is this what you are looking for?

chkr1011 avatar Oct 21 '25 13:10 chkr1011