我使用 EMQ X Broker v4.0.1。简单的 http 身份验证工作正常,但是当我尝试使用 http ACL 身份验证时 - 它对我不起作用,尽管设置非常接近。当我尝试通过 Eclipse Paho 引用代理时,我收到状态代码 3 的错误,这意味着代理不可用。我从仪表板打开了 emqx_auth_http 。这是我的 http ACL auth 的 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 应用程序访问它。也许你可以告诉我我的配置或其他地方哪里出了问题?
最佳答案
也许您需要提供您的 HTTP 服务器代码。
http 响应状态 200 正常
http 响应状态 4xx 未经授权
http 响应状态 200 且正文为 ignore
表示中断
这是一个刚刚通过测试的项目: egg-iot-with-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
}
})
关于mqtt - EMQX http ACL 身份验证 - 代理不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59879546/