jadahl / mod_restful

RESTful interface to ejabberd
84 stars 34 forks source link

401 Unauthorized #20

Closed dirkmoors closed 10 years ago

dirkmoors commented 10 years ago

Unfortunatly, I run into the same as stated here: https://github.com/jadahl/mod_restful/issues/11, which is already closed.

I've created a gist with my ejabberd.yml, the console output and the request I make, which results in an 401 Unauthorized error: https://gist.github.com/dirkmoors/4b60c9573d3d49cbf1cd

My modules section in ejabberd.yml looks like:

modules:
  mod_restful:
    api:
      - path: ["admin"]
        module: mod_restful_admin
        params:
          key: "secret"
          allowed_commands: [register, unregister]
      - path: ["register"]
        module: mod_restful_register
        params:
          key: "secret"
  ...

As you can see in the console output, there are no issues loading the module itself. Obviously, the user I use in the example; "admin@service.vrijhof.com" is an existing user.

I've compiled ejabberd Community (13.12) from source on Ubuntu 14.04 LTS, and I've used the master branch of mod_restful. What could be wrong here?

jadahl commented 10 years ago

It looks like it fails when verifying that the host of the HTTP request is one of the configured ones. Could it be that its missing from the GET request? The host of the HTTP request is used for internal routing of packets to the corresponding per-ejabberd-host module.

dirkmoors commented 10 years ago

You are correct. When I updated my request url to:

http://service.vrijhof.com:8088/api/register/is_registered?username=marc&host=service.vrijhof.com&key=secret

Everything works. It seems a bit odd that this is required for it to work, but I can work with that.

Thank you for your quick response!

jadahl commented 10 years ago

Indeed. The host parameter is a bit redundant and could probably be made optional. The host of the URL as I mentioned is used for routing to ejabberd modules processes and could be reused instead of the parameter.