Unexpected HTTP Request: POST /mqtt/auth

450 Views Asked by At

I am new to emqtt. I am trying to use emq_auth_http but it is not working.

I have these 3 requests to console some data and send data back with status 200.

app.post('/mqtt/auth', function(req, res) {
console.log('This is body ', req.body);
res.status(200).send(req.body);
});
app.post('/mqtt/superuser', function(req, res) {
console.log('This is body in superuser ', req.body);
res.status(200).send(req.body);
});
app.get('/mqtt/acl', function(req, res) {
console.log('This is params in acl ', req.params);
res.status(200).send(req.body);
});

Requests are working fine on postman.

I have configured my emqtt on windows with docker. I have placed my config file in /etc/plugins/emq_auth_http.conf.

This is my config file

## Variables: %u = username, %c = clientid, %a = ipaddress, %P = password, %t = topic

auth.http.auth_req = http://127.0.0.1:3000/mqtt/auth
auth.http.auth_req.method = post
auth.http.auth_req.params = clientid=%c,username=%u,password=%P

auth.http.super_req = http://127.0.0.1:3000/mqtt/superuser
auth.http.super_req.method = post
auth.http.super_req.params = clientid=%c,username=%u

## 'access' parameter: sub = 1, pub = 2
auth.http.acl_req = http://127.0.0.1:3000/mqtt/acl
auth.http.acl_req.method = get
auth.http.acl_req.params = 
access=%A,username=%u,clientid=%c,ipaddr=%a,topic=%t

Then I enabled emq_auth_http from dashboard

Now when I tried to connect my mqtt client to my server it is not calling the api. It logs

09:28:29.642 [error] Unexpected HTTP Request: POST /mqtt/auth
09:28:29.644 [error] Client(19645050-9d1b-4c50-acf9- 
[email protected]:60968): Username 'username' login failed for 404

Is there anything I missed? Why it is not working?

Thanks

1

There are 1 best solutions below

4
On

127.0.0.1 in a container refers to the container itself and not the host machine. you should set the host machine ip,you can obtain the host machine ip from a container by issuing the command /sbin/ip route|awk '/default/ { print $3 }' which could be found here

ps: this way you can get the ip of docker machine and not the host ,if your service is served by windows you can reach the ip of host machine from the container which is 10.0.75.1. you can find it in How to connect to docker host from container on Windows 10 (Docker for Windows)