iegomez / mosquitto-go-auth

Auth plugin for mosquitto.
MIT License
519 stars 170 forks source link

How to check if a client is disconnected from the broker #294

Open irfanazam1 opened 1 year ago

irfanazam1 commented 1 year ago

I am using the HTTP auth plugin for authentication, that calls into a REST API hosted by a Node.js process. I want to implement a feature where I don't want to allow multiple connections to the broker by a user. I am using auth_opt_http_getuser_uri to get the login request, I verify the request and let the user to connect if the credentials are correct. I want to cache or store the session information about the user and don't want another connection to be made by the same user if it the user is already connected. It is simple to implement if I could find an option that can call an HTTP method when a client is disconnected; I will clear the session/cache in that case, and the user will be able to connect again. I want to know if such option present in the HTTP auth plugin that can call a function when the client is disconnected? Or, could someone suggest me a solution to the problem i.e. don't want to allow multiple connection from the same user.

iegomez commented 1 year ago

I don't know why you want to limit connections to the broker itself, but you're probably better off handling it there. So I'd recommend forking the plugin and implementing it at this level, your http backend shouldn't worry about connections to the broker.

irfanazam1 commented 1 year ago

I want to do that to safeguard another connection in case our device password is leaked. I can implement that but I don't know how the broker will call the disconnect function on the plugin interface?