# VerneMQ webhooks with diversity plugin

**URL:** <https://erlangforums.com/t/vernemq-webhooks-with-diversity-plugin/2862>\
**Category:** VerneMQ Questions\
**Tags:** vernemq-questions, webhooks, diversity-plugin\
**Created:** [September 6, 2023, 11:35am UTC](https://erlangforums.com/t/vernemq-webhooks-with-diversity-plugin/2862 "2023-09-06T11:35:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MIHAIL33](https://erlangforums.com/user_avatar/erlangforums.com/mihail33/32/2073_2.png) [@MIHAIL33](https://erlangforums.com/u/MIHAIL33)\
**Post date:** [September 6, 2023, 11:35am UTC](https://erlangforums.com/t/vernemq-webhooks-with-diversity-plugin/2862/1 "2023-09-06T11:35:34Z")

</div>

Hello! I’m using VErneMQ 1.12.1 broker, was successfully able to setup diversity plugin for postgres and tls to connect clients.  
I need to get the data of clients (username and client\_id) that failed to pass authorization, or get all the data of clients that tried to pass authorization successfully or not.  
I found information about webhooks in the documentation, but for auth\_on\_register, auth\_on\_subscribe, auth\_on\_publish hooks work interchangeably. That is, after I answer status 200, authorization through posgres does not work.  
Ideally what I want is:

1. The client logs in to VerneMQ.
2. The hook fires, I get the client data.  
3.1) If I answer status 200, then authorization continues through the diversity plugin postgres, otherwise authorization is not passed.  
3.2) Or whatever I answer, the authorization continues through the deversity plugin postgres.

Example my docker environment:  
DOCKER\_VERNEMQ\_PLUGINS\_\_VMQ\_WEBHOOKS: ‘on’  
DOCKER\_VERNEMQ\_VMQ\_WEBHOOKS\_\_AUTH\_ON\_REGISTER1\_\_HOOK: ‘auth\_on\_register’  
DOCKER\_VERNEMQ\_VMQ\_WEBHOOKS\_\_AUTH\_ON\_REGISTER1\_\_ENDPOINT: ‘[http://127.0.0.1:8008/hooks/test](http://127.0.0.1:8008/hooks/test)’  
DOCKER\_VERNEMQ\_VMQ\_WEBHOOKS\_\_AUTH\_ON\_PUBLISH1\_\_HOOK: ‘auth\_on\_publish’  
DOCKER\_VERNEMQ\_VMQ\_WEBHOOKS\_\_AUTH\_ON\_PUBLISH1\_\_ENDPOINT: ‘[http://127.0.0.1:8008/hooks/test](http://127.0.0.1:8008/hooks/test)’  
DOCKER\_VERNEMQ\_VMQ\_WEBHOOKS\_\_AUTH\_ON\_SUBSCRIBE1\_\_HOOK: ‘auth\_on\_subscribe’  
DOCKER\_VERNEMQ\_VMQ\_WEBHOOKS\_\_AUTH\_ON\_SUBSCRIBE1\_\_ENDPOINT: ‘[http://127.0.0.1:8008/hooks/test](http://127.0.0.1:8008/hooks/test)’  
DOCKER\_VERNEMQ\_PLUGINS\_\_VMQ\_WEBHOOKS\_\_PRIORITY: 10  
DOCKER\_VERNEMQ\_ACCEPT\_EULA: ‘yes’  
DOCKER\_VERNEMQ\_ALLOW\_ANONYMOUS: ‘off’  
DOCKER\_VERNEMQ\_PLUGINS\_\_VMQ\_PASSWD: ‘off’  
DOCKER\_VERNEMQ\_PLUGINS\_\_VMQ\_ACL: ‘off’  
DOCKER\_VERNEMQ\_VMQ\_ACL\_\_ACL\_RELOAD\_INTERVAL: 10  
DOCKER\_VERNEMQ\_PLUGINS\_\_VMQ\_DIVERSITY: ‘on’  
DOCKER\_VERNEMQ\_VMQ\_DIVERSITY\_\_AUTH\_POSTGRES\_\_ENABLED: ‘on’

I will be grateful for any help!

---

<div class="post-metadata">

**Author:** ![afa](https://erlangforums.com/user_avatar/erlangforums.com/afa/32/298_2.png) [@afa](https://erlangforums.com/u/afa)\
**Post date:** [September 6, 2023, 11:44am UTC](https://erlangforums.com/t/vernemq-webhooks-with-diversity-plugin/2862/2 "2023-09-06T11:44:24Z")

</div>

If I understand correctly, you want to use a WebHooks plugin as some sort of logging plugin, and then use a vmq\_diversity (database) plugin to do the actual authentication/authorization.

This should be possible when your `auth_on_register` WebHook returns `{"result": "next"}` so that we pass data to the next plugin in the chain.  
You might need to set a priority level for each plugin in the `vernemq.conf` to ensure the WebHooks plugin is called first.

I hope this helps a bit.

---

<div class="post-metadata">

**Author:** ![MIHAIL33](https://erlangforums.com/user_avatar/erlangforums.com/mihail33/32/2073_2.png) [@MIHAIL33](https://erlangforums.com/u/MIHAIL33)\
**Post date:** [September 6, 2023, 12:08pm UTC](https://erlangforums.com/t/vernemq-webhooks-with-diversity-plugin/2862/3 "2023-09-06T12:08:47Z")

</div>

Thanks a lot! This is exactly what I needed, now everything working for me, as I wanted.  
Everything is very conveniently done.
