EMQX 5.x HTTP ACL-Server mit NodeJS
English
Deutsch
In unserem vorherigen Post EMQX 5.x HTTP-Passwort-Authentifizierungsserver minimales Beispiel mit NodeJS haben wir ein vollständiges Beispiel zur Implementierung der EMQX-HTTP-Authentifizierung bereitgestellt.
Dieser Post bietet eine Erweiterung unserer vorherigen HTTP-Authentifizierung durch Hinzufügen eines Koa-Routers (d. h. eines HTTP-Endpunkts / URL), um ACL-Authentifizierung bereitzustellen, d. h. Topic-Level-Zugriff mit benutzerdefinierter Logik zu erlauben oder abzulehnen.
emqx-5-x-http-acl-server-using-nodejs.js
router.post('/emqx/acl', async ctx => {
const body = ctx.request.body;
console.log(body)
// TODO: This example always returns true
// You need to implement your authentication logic
ctx.body = {
result: "allow",
};
});Fügen Sie diesen Code vor app.use(router.routes()); im Skript aus EMQX 5.x HTTP-Passwort-Authentifizierungsserver minimales Beispiel mit NodeJS hinzu.
Mein empfohlener Authorization-Konfigurations-Body, den Sie im EMQX-Dashboard setzen können, ist
emqx_acl_request_body.json
{
"action": "${action}",
"client_id": "${clientid}",
"ip": "${peerhost}",
"topic": "${topic}",
"username": "${username}"
}If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow