@authbroker/authbroker

中文文档
0.0.12发布于 2022/03/30MITCommonJS近 30 天下载 7568

Authentication and Authorization module of HTTP/MQTT/CoAP Brokers based on NodeJS for IoT or Internet of Things.

原始使用文档
文档目录6 节
  1. Getting Started
  2. How Using it
  3. Contributing
  4. Authors / Contributors
  5. Credits / Inspiration
  6. Copyright

Authentication and Authorization Module for Brokers

Open Source Love Build Status

Authentication and Authorization module of HTTP/MQTT/CoAP Brokers based on NodeJS for IoT or Internet of Things. This repo is under development.

Getting Started

  • Install Keycloak locally. Make sure it's working.
  • If you want to run a test locally, clone this 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}}")

It runs Keycloak by docker and import demo data to IOT_Realm realm. An example Broker runs that used auhtBroker by:

node ./example/broker.js

these below commands Subscribe and Publish to broker.

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

if username/password or authorization permission in Keycloak changes, authBroker authorization will not permitted to broker. for example change topic to unauthorized topic like garden/unathorized and see how broker reject it.

How Using it

This module use Node-style callback and it can be used with different brokers like Aedes.

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);
});

It's necessary to set these scopes in Authorization section in Keycloak. By defualt 'scopes:mqttpub' is set for Publish permission and 'scopes:mqttsub' is set for Subscription permission.

Keycloak Scopes

Users can Publish or Subscribe to resources which has a scope 'scopes:mqttpub' or 'scopes:mqttsub'.

Keycloak Resource

run-test.sh script runs a preconfigured Keycloak Demo version that can be used as a template.

bash run-test.sh

then visit http://localhost:8080 with username 'admin' and password 'admin' in Admin console.

Contributing

contributions welcome

Anyone with interest in or experience with the following technologies are encouraged to join the project. And if you fancy it, join the Telegram group here for Devs and say Hello!

Authors / Contributors

Credits / Inspiration

MIT - Copyright (c) 2019-2022 ioKloud

版本与发布记录

@authbroker/authbroker 共发布 8 个版本,首次发布于 2019/06/14;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.12latest2022/03/304 年前
0.0.112022/03/304 年前
0.0.102022/03/254 年前
0.0.52021/04/205 年前
0.0.42019/07/197 年前
0.0.32019/06/177 年前

关于 @authbroker/authbroker 的常见问题

@authbroker/authbroker 是什么?

Authentication and Authorization module of HTTP/MQTT/CoAP Brokers based on NodeJS for IoT or Internet of Things.

如何安装 @authbroker/authbroker?

在项目目录运行 npm install @authbroker/authbroker,或使用 pnpm add / yarn add / bun add。

@authbroker/authbroker 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/authbroker__authbroker 是否存在。

@authbroker/authbroker 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@authbroker/authbroker 可以商用吗?

@authbroker/authbroker 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@authbroker/authbroker 的下载量有多少?

根据 npm 官方下载统计,@authbroker/authbroker 在 2026/10/07 – 2026/11/05 这 30 天内被下载 7,568 次,日均约 252 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@authbroker/authbroker 还在维护吗?

最新版本 0.0.12 发布于 2022/03/30(4 年前);至今共发布 8 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/06/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。