emqx / emqx-auth-http

EMQX HTTP Authentication/ACL Plugin
https://emqx.io/
Apache License 2.0
43 stars 47 forks source link

Dynamic routing for mutualize broker #279

Open asijoumi opened 11 months ago

asijoumi commented 11 months ago

Hello,

I currently use EMQX and this plugin to authenticate my users. For that I have

auth.http.auth_req.url = https://my-first-api/broker/auth/user
auth.http.auth_req.headers.content_type = application/json
auth.http.acl_req.method = post

It's working very well if I have only one project connected to my broker.

How can I use multiple projects with the same broker ?

For example, I would like to have something like that :

If request has property `first-api` -> use `my-first-api` endpoint
If request has property `second-api` -> use `my-second-api` endpoint

Or, if it's not possible, how can I pass custom parameter ? In that case, I will create an api for routing authentication.

Thanks

id commented 11 months ago

Hi @asijoumi .

Where would emqx get first-api and second-api request properties values?

asijoumi commented 11 months ago

Hi @id,

I thought we could pass some properties in the http headers to manage the requests. I don't know Erlang enough to submit a pull request. But it could be great to have a Map to manage and distribute requests to different auth providers.

For now, and for my case, I manage the requests based on the username with a specific REST API.

So I have :

HTTP Request -> EMQX -> Rest API for routing 
-> if (username start with abc) go to first-api
-> if (username start with def) go to second-api
id commented 11 months ago

@asijoumi this use case is not very common, I'm not sure if we will be able to prioritize it. However, what you could do is to run a reverse proxy in front of your API services and do routing there. For example: https://github.com/ericminio/learning-nginx/blob/master/payload-filter/nginx/conf.d/default.conf.