emq Client ID 认证

       Client ID 认证使用配置文件预设客户端 Client ID 与密码,支持通过 HTTP API 管理认证数据。
         Client ID 认证不依赖外部数据源,使用上足够简单轻量,使用该种认证方式时需要开启 emqx_auth_clientid 插件,直接在 DashBoard 中开启即可,

哈希方法
配置哈希方法后,新增的预设认证数据与通过 HTTP API 添加的认证数据将以哈希密文存储在 EMQ X 内置数 据库中。

2.3.1 预设认证数据
可以通过配置文件预设认证数据,编辑配置文件: etc/plugins/emqx_auth_clientid.conf
# etc/plugins/emqx_auth_clientid.conf 
##-------------------------------------------------------------------- 
## ClientId Authentication Plugin 
##--------------------------------------------------------------------

## Examples ##auth.client.1.clientid = id 
##auth.client.1.password = passwd 
##auth.client.2.clientid = dev:devid 
##auth.client.2.password = passwd2 
##auth.client.3.clientid = app:appid 
##auth.client.3.password = passwd3 
##auth.client.4.clientid = client~!@#$%^&*()_+ 
##auth.client.4.password = passwd~!@#$%^&*()_+ 
## Password hash. 
#### Value: plain | md5 | sha | sha256 
auth.client.password_hash = sha256

插件启动时将读取预设认证数据并加载到 EMQ X 内置数据库中,节点上的认证数据会在此阶段同步至集群 中。
预设认证数据在配置文件中使用了明文密码,出于安全性与可维护性考虑应当避免使用该功能
2.3.2 HTTP API 管理认证数据
我们使用 VSCode 来通过 EMQ X API 来添加和查看 Client ID 的认证数据。
1 :添加认证数据 API 定义: POST api/v4/auth_clientid{ "clientid": "emqx_c", "password": "emqx_p"}

@hostname = 192.168.112.112
@port=8081
@contentType=application/json
@userName=admin
@password=public



####添加clientId和密码##### 
POST http://{{hostname}}:{{port}}/api/v4/auth_clientid HTTP/1.1 
Content-Type: {{contentType}} 
Authorization: Basic {{userName}}:{{password}} 

{ "clientid": "emq-client1", "password": "123456" }


####查看已经添加的认证数据API 定义: GET api/v4/auth_clientid

#############获取所有详细信息######## 
GET http://{{hostname}}:{{port}}/api/v4/auth_clientid HTTP/1.1 
Content-Type: {{contentType}} 
Authorization: Basic {{userName}}:{{password}} 



#############更改指定 Client ID 的密码######## 
PUT http://{{hostname}}:{{port}}/api/v4/auth_clientid/emq-client1 HTTP/1.1 
Content-Type: {{contentType}} 
Authorization: Basic {{userName}}:{{password}} 
{ "password": "654321" }



#############获取指定ClientId详细信息######## 
GET http://{{hostname}}:{{port}}/api/v4/auth_clientid/emq-client1 HTTP/1.1 
Content-Type: {{contentType}} 
Authorization: Basic {{userName}}:{{password}} 


#############删除指定的client信息######## 
DELETE http://{{hostname}}:{{port}}/api/v4/auth_clientid/emq-client1 HTTP/1.1
Content-Type: {{contentType}} 
Authorization: Basic {{userName}}:{{password}}

效果

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值