在閱讀該教程以前,假定你已經瞭解 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: