I'm trying to create a chat application for android using MQTT, but there is limited information on how to do that.
So far I've set up the MQTT broker but any user can listen and publish to any topics they would like (surely that's not what one wants in chat applications).
I'm using mosquitto as my broker and it's listing this set of features in it's documentation:
Topic access is added with lines of the format:
topic [read|write|readwrite] <topic>
It is also possible to define ACLs based on pattern substitution within the topic. The form is the same as for the topic keyword, but using pattern as the keyword.
pattern [read|write|readwrite] <topic>
The patterns available for substition are:
%c to match the client id of the client %u to match the username of the client
The substitution pattern must be the only text for that level of hierarchy. Pattern ACLs apply to all users even if the "user" keyword has previously been given.
Example:
pattern write sensor/%u/data
Allow access for bridge connection messages:
pattern write $SYS/broker/connection/%c/state
So far I thought of doing something like:
pattern readwrite chat/%u/msg
But this limits each user to read/write on their own topic, and that's not the intended behavior.
So my question is:
Is there a way to set on-the-fly permissions to topics?
How would one ensure eg in a chat between A-B-C there is a topic for A-B-C that only A-B-C can read and write on?