processone / ejabberd-contrib

Growing and curated ejabberd contributions repository - PR or ask to join !
http://ejabberd.im
248 stars 137 forks source link

ejabberd_auth_http does not call external REST point #270

Closed vkelman closed 5 years ago

vkelman commented 5 years ago

ejabberd version: 19.02 OS: Windows 10 Installed from: official binary installer ejabberd_auth_http installed

ejabberd.yml:

language: "en"
hosts:
  - "planetrisk.com"

auth_method: http

auth_opts:
  host: "http://localhost:80"
  connection_pool_size: 10
  connection_opts: []
  basic_auth: ""
  path_prefix: "services/imd35000/api/v1/ejabberd/"

auth_use_cache: false

  ## mod_register:

So, mod_register is disabled (commented out), I implemented web service controller stub in C# which listens on http://localhost/services/imd35000/api/v1/ejabberd route. Two get methods are implemented, check_password and user_exists.

I use POSTMAN to perform calls like

http://localhost:80/services/imd35000/api/v1/ejabberd/check_password?user=testfouoles&server=planetrisk.com&pass=fsdfsddds and http://localhost/services/imd35000/api/v1/ejabberd/user_exists?user=testfouoles&server=planetrisk.com&pass=fsdfsddds

Both calls work and when running web service in a debugger, it stops on break points.

ejabberd ejabberd_auth_http does not call this API.

In ejabberd.log I see

2019-04-18 17:23:51.402 [warning] <0.534.0>@ejabberd_c2s:handle_auth_failure:452 (http_bind|<0.533.0>) Failed c2s PLAIN authentication for testfouoles@planetrisk.com from 127.0.0.1: Invalid username or password

The same thing happens if I try to login using ejabberd web admin console.

vkelman commented 5 years ago

@badlop - is there a way to turn On some tracing / debug information to determine what exact URL ejabberd + ejabberd_auth_http is trying to hit (if any)?

vkelman commented 5 years ago

@badlop, Am I required to add ejabberd_auth_http: {} Into modules: section of ejabberd.yml?

I didn't add it before. Now, after I added it I'm getting the following errors in ejabberd.log

2019-04-19 16:37:12.398 [warning] <0.367.0>@gen_mod:get_validators:506 Third-party module 'ejabberd_auth_http' doesn't export options validator; consider to upgrade the module 2019-04-19 16:37:12.399 [critical] <0.367.0>@gen_mod:start_module:228 Failed to start module ejabberd_auth_http because it doesn't export start/2 callback: is it really an ejabberd module? 2019-04-19 16:37:12.399 [critical] <0.367.0>@gen_mod:maybe_halt_ejabberd:311 ejabberd initialization was aborted because a module start failed.

And in error.log:

2019-04-19 16:37:12.399 [critical] <0.367.0>@gen_mod:start_module:228 Failed to start module ejabberd_auth_http because it doesn't export start/2 callback: is it really an ejabberd module? 2019-04-19 16:37:12.399 [critical] <0.367.0>@gen_mod:maybe_halt_ejabberd:311 ejabberd initialization was aborted because a module start failed.

zinid commented 5 years ago

@vkelman no, you should not add ejabberd_auth_http to the modules section, and ejabberd clearly complains about it.

vkelman commented 5 years ago

OK, this was my mistake: path_prefix must begin with "/" like path_prefix: "/services/imd35000/api/v1/ejabberd/".

ejabberd_auth_http joins host and path_prefix parameters together without checking slashes (which it should). As a result it was calling http://localhost:80services/imd35000/api/v1/ejabberd/check_password instead of http://localhost:80/services/imd35000/api/v1/ejabberd/check_password