You need a broker proxy, or a webserver...
First of all, you absolutely need a authentication service somewhere connected to your broker to perform the 2FA using specific topics (/auth/RFID
,...). It would then allow client to publish information (see below).
The first problem I can see here is that anybody subscribed to this topic can read the information of that topic, but you can lock topics!
You can then tell (force) all your devices to publish information to /proxy/mytopic
. With the clientId feature of mqtt, the auth service can check if the messages sent from this topic are from an authenticated device that used 2FA previously, and then publish its own message on behalf of the device to /proxyout/mytopic
with the device's id in the payload.
The problem now is checking for devices that can recieve messages if they are authenticated, because, well, MQTT is all about mass publication. The auth service needs to have a list of authenticated devices and check if they are eligible for reception. Again, payload encryption and decryption device-side...
I think my solution is very overkill over MQTT capabilities. You should therefore use a socket or a web server...