经纪人认证和授权模块
HTTP/MQTT/CoAP经纪公司基于IOT或物联网的NodeJS认证和授权模块. 此还款正在开发中.
开始
- 安装 键盘 当地。 定能通达.
- 如果您想要在本地进行测试, 请复制此 repo .
git clone https://github.com/authbroker/authbroker
cd authbroker
npm install
bash run-test.sh
# visit http://localhost:8080
# with username 'admin' and password 'admin'
npm run test
# for stopping docker instance you use this
docker stop $(docker ps -a -q --filter ancestor=authbroker:test --format="{{.ID}}")
它通过多克运行Keycloak并导入演示数据到IOT Realm域. 一个使用 auhtBroker 的 Broker 运行的例子 :
node ./example/broker.js
下面这些命令将订阅和发布到经纪人.
mosquitto_sub -h localhost -p 1883 -t garden/fan -u admin -P admin
mosquitto_pub -h localhost -p 1883 -t garden/fan -m "hello world" -u admin -P admin
如果 Keycloak 中的用户名/ 密码或授权更改, AuthBroker 的授权将不会被允许代理 。 例如,将主题改为未经授权的主题,如花园/未拆卸,看看经纪人如何拒绝.
如何运用它
这个模块使用节点风格的回调,可以和不同的经纪人使用,比如: 亚得斯。 。 。 .
const aedes = require("aedes")({
persistence: new require("aedes-persistence")()
});
const server = require("net").createServer(aedes.handle);
const port = 1883;
const authBroker = require('@authbroker/authbroker');
const config = {
"realm": "IOT_Realm",
"authUrl": "http://localhost:8080/auth",
"sslRequired": "external",
"clientId": "authBroker",
"verifyTokenAudience": true,
"credentials": {
"secret": "secret"
},
"confidentialPort": 0,
"policyEnforcer": {},
"mqttpubScope": "scopes:mqttpub", // scope text for pub permission
"mqttsubScope": "scopes:mqttsub", // scope text for pub permission
"mqttResPerfix": "res:" // prefix text for resource or topic
};
const authbroker = new authBroker(config)
// hook it up
aedes.authenticate = authbroker.authenticate();
aedes.authorizeSubscribe = authbroker.authorizeSubscribe();
aedes.authorizePublish = authbroker.authorizePublish();
server.listen(port, function () {
console.log("server listening on port", port);
});
有必要在凯克洛克的授权部分设置这些范围. 通过去fualt'scope:mqttpub'设定用于出版许可,而"scope:mqttsub"设定用于订阅许可.

用户可以发布或订阅具有"范围:mqttpub"或"范围:mqttsub"的资源.

run-test.sh 脚本运行一个预配置的 Keycloak Demo 版本,可以用作模板.
bash run-test.sh
然后访问 http://localhost:8080, 用户名“ admin” 和密码“ admin” 在管理控制台.
捐款
鼓励对下列技术有兴趣或有经验的任何人加入该项目. 如果你喜欢它,加入 电报组 给德夫斯打个招呼!
作者/贡献者
信用/灵感
- 马特奥·科利纳代表莫斯卡、埃德斯、庞特(签名)https://github.com/moscajs/aedes (中文(简体) )(中文(简体) )
- Eugenio Pace for Auth0 Mosca 靈感 (英语:https://github.com/eugeniop/auth0mosca 互联网档案馆的存檔,存档日期2013-12-02(中文(简体) )
版权
MIT - 版权(c) 2019-2022 ioKloud