moscajs / mosca

MQTT broker as a module
mosca.io
3.2k stars 508 forks source link

Minimatch style auth for pub/sub. For Reference #628

Closed spydmobile closed 7 years ago

spydmobile commented 7 years ago

Good day Matteo! First thank you for Mosca, I love it! I was having an issue with my pattern matching for my auth scheme.

in my credentials in my single user I have:

    "authorizePublish": "psaas/*",
    "authorizeSubscribe": "psaas/*"

If I pub with said user to topic psaas/demo it worked, but if I pub to topic psaas/webClient/request it fails silently and closes the connection because that pub is not approved. I want my user to be permitted to pub/sub to topic psaas/ followed by any combination, in the same way that a subscribe via MQTT to psaas/# would allow. For anyone else looking to solve this confusion, you need to use minimatch globstar ** so your entry should look like:

    "authorizePublish": "psaas/**",
    "authorizeSubscribe": "psaas/**"

I hope this helps others who are using Mosca for similar applications. Cheers Franco

mcollina commented 7 years ago

Thanks!