首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >EMQX http ACL auth - broker不可用

EMQX http ACL auth - broker不可用
EN

Stack Overflow用户
提问于 2020-01-23 13:19:12
回答 1查看 515关注 0票数 2

我使用EMQXBrokerv4.0.1。简单的http auth很好,但是当我尝试使用http时,它并不适用于我,尽管设置非常接近。当我试图通过Eclipse引用代理时,我会得到状态代码3的错误,这意味着代理不可用。我从仪表板上打开了emqx_auth_http。这是我对http的EMQX设置:

emqx.conf

代码语言:javascript
复制
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/superuserhttp://somesite/mqtt/acl)运行良好,我可以从Postaman应用程序访问它。也许你可以告诉我我在哪里做错了什么,在我的配置或其他地方?

EN

回答 1

Stack Overflow用户

发布于 2020-02-06 01:10:15

也许你需要提供你的HTTP服务器代码。

http应答状态200是可以的

http响应状态4xx是未经授权的

http响应状态200和body is ignore意味着中断

这是一个刚刚通过测试的项目:蛋加mqtt

代码语言:javascript
复制
/**
 * 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
  }
})
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59879546

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档