我使用EMQXBrokerv4.0.1。简单的http auth很好,但是当我尝试使用http时,它并不适用于我,尽管设置非常接近。当我试图通过Eclipse引用代理时,我会得到状态代码3的错误,这意味着代理不可用。我从仪表板上打开了emqx_auth_http。这是我对http的EMQX设置:
emqx.conf
listener.tcp.external = 1884
plugins/emqx_auth_http.conf
auth.http.auth_req = http://127.0.0.1:8991/mqtt/auth
auth.http.auth_req.method = post
auth.http.auth_req.params = clientid=%c,username=%u,password=%P
auth.http.super_req = http://somesite.com/mqtt/superuser
auth.http.super_req.method = post
auth.http.super_req.params = clientid=%c,username=%u
auth.http.acl_req = http://somesite/mqtt/acl
auth.http.acl_req.method = post
auth.http.acl_req.params = access=%A,username=%u,clientid=%c,ipaddr=%a,topic=%t,mountpoint=%m
auth.http.request.retry_times = 3
auth.http.request.retry_interval = 1s
auth.http.request.retry_backoff = 2.0端点(http://somesite.com/mqtt/superuser,http://somesite/mqtt/acl)运行良好,我可以从Postaman应用程序访问它。也许你可以告诉我我在哪里做错了什么,在我的配置或其他地方?
发布于 2020-02-06 01:10:15
也许你需要提供你的HTTP服务器代码。
http应答状态200是可以的
http响应状态4xx是未经授权的
http响应状态200和body is ignore意味着中断
这是一个刚刚通过测试的项目:蛋加mqtt
/**
* Auth
*/
router.post('/mqtt/auth', async (ctx, next) => {
const { clientid, username, password } = ctx.request.body
// Mock
// 200 means ok
if (clientid === '' || 'your condition') {
ctx.body = ''
} else {
// 4xx unauthorized
ctx.status = 401
}
})
/**
* ACL
*/
router.post('/mqtt/acl', async (ctx, next) => {
/**
* Request Body
* access: 1 | 2, 1 = sub, 2 = pub
* access in body now is string !!!
{
access: '1',
username: 'undefined',
clientid: 'mqttjs_bf980bf7',
ipaddr: '127.0.0.1',
topic: 't/1',
mountpoint: 'undefined'
}
*/
const info = ctx.request.body
console.log(info)
if (info.topic === 't/2') {
// 200 is ok
ctx.body = ''
} else {
// 4xx is unauthorized
ctx.status = 403
}
})https://stackoverflow.com/questions/59879546
复制相似问题