implement authentication for embedded MQTT server
This commit is contained in:
parent
6b6d1768e4
commit
547b403361
1 changed files with 15 additions and 1 deletions
|
|
@ -12,7 +12,21 @@ import (
|
|||
func Start() {
|
||||
server := mqtt.New(nil)
|
||||
|
||||
_ = server.AddHook(new(auth.AllowHook), nil)
|
||||
if os.Getenv("MQTT_USERNAME") == "" {
|
||||
_ = server.AddHook(new(auth.AllowHook), nil)
|
||||
} else {
|
||||
_ = server.AddHook(new(auth.Hook), &auth.Options{
|
||||
Ledger: &auth.Ledger{
|
||||
Auth: auth.AuthRules{
|
||||
{
|
||||
Username: auth.RString(os.Getenv("MQTT_USERNAME")),
|
||||
Password: auth.RString(os.Getenv("MQTT_PASSWORD")),
|
||||
Allow: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if os.Getenv("MQTT_LISTEN") == "" {
|
||||
log.Log.Fatal("please set MQTT_LISTEN")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue