在阅读该教程以前,假定你已经了解 MQTT、EMQX 的简单知识。架构
emqx_auth_http 它将每一个终端的接入事件、ACL事件抛给用户本身的 WebServer 以实现接入认证和ACL鉴权的功能。其架构逻辑以下:post
emqx_auth_http 主要处理的事情有:插件
实际上,在 EMQX 的集群里面,emqx_auth_http 对于用户的 Web Services 来说只是一个简单的、无状态的 HTTP Client,他只是将 EMQX 内部的登陆认证、和ACL控制的请求转发到用户的 Web Services,并作必定逻辑处理而已。3d
在这里给出了其3.1.0版本的默认配置文件,虽然看着内容比较多,其实只是配置了 三个 HTTP Request 的参数cdn
终端接入认证(auth_req)server
判断是否为超级用户(super_req)blog
ACL请求(acl_req)教程
其中,咱们以认证为例,其每项分别表明了:事件
而对于其中 params 项中,支持参数占位符 %u %c %a %P ,好比以下配置 auth.http.auth_req.params = clientid=%c,username=%u,password=%P 其表明的含义是,auth_req 包括三个参数,这个三个参数的 key 分别是 clientid username password 其值分别会替换为终端在接入时其真实的 ClientId Username Passwordip
默认的全部配置以下:
Authentication request. Variables:
Value: post | get | put auth.http.auth_req.method = post
Value: Params auth.http.auth_req.params = clientid=%c,username=%u,password=%P
Superuser request. Variables:
Value: post | get | put auth.http.super_req.method = post
Value: Params auth.http.super_req.params = clientid=%c,username=%u
ACL request. Variables:
Value: post | get | put auth.http.acl_req.method = get
Value: Params auth.http.acl_req.params = access=%A,username=%u,clientid=%c,ipaddr=%a,topic=%t
在了解了如何配置 emqx_auth_http 插件后,剩下关键的是Webserver 如何返回成功或者失败。
认证
认证成功:
忽略这次认证
错误
超级用户
确认为超级用户:
非超级用户
ACL鉴权
容许PUBLISH/SUBSCRIBE:
忽略这次鉴权:
拒绝该次PUBLISH/SUBSCRIBE: