Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

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

NotificationsYou must be signed in to change notification settings

authbroker/authbroker

Repository files navigation

Open Source LoveBuild 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

  • InstallKeycloak locally. Make sure it's working.
  • If you want to run a test locally, clone this repo.
git clone https://github.com/authbroker/authbrokercd authbrokernpm installbash run-test.sh# visit http://localhost:8080# with username 'admin' and password 'admin'npm runtest# for stopping docker instance you use thisdocker 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 adminmosquitto_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 likeAedes.

constaedes=require("aedes")({persistence:newrequire("aedes-persistence")()});constserver=require("net").createServer(aedes.handle);constport=1883;constauthBroker=require('@authbroker/authbroker');constconfig={"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};constauthbroker=newauthBroker(config)// hook it upaedes.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 visithttp://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 theTelegram group here for Devs and say Hello!

Authors / Contributors

Credits / Inspiration

Copyright

MIT - Copyright (c) 2019-2022 ioKloud

About

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

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp