Comments (26)
Are you using mod_restful_admin? Did you add the command you wish to use to the authorized commands? See the "allowed_commands" option. Also make sure you have the correct shared secret (the "key" parameter).
from mod_restful.
Hello here are the parts of the ejabberd.cfg.
{{8088, {0, 0, 0, 0}}, ejabberd_http,[{request_handlers, [{["api"], mod_restful}]}]},
{mod_restful, [
{api,
[
{["admin"], mod_restful_admin,[
{key, "secret"},
{allowed_commands, [register, unregister]}
]},
{["register"], mod_restful_register, [{key, "secret"}]
}
]
}
]},
an here are the actions:
REQUEST:
POST /api/register HTTP/1.1
Host: vAir.box.private:8088
Accept: /
Content-type: application/json
Content-Length: 83
{"key":"secret","username":"test4","host":"vAir.box.private","password":"test4"}
RESPONSE:
HTTP/1.1 401 Unauthorized
Content-Type: text/html; charset=utf-8
Content-Length: 337
from mod_restful.
It should be POST /api/register/register HTTP/1.1, and not POST /api/register HTTP/1.1.
mod_restful works by separating different modules by paths. mod_restful_register is a module that, according to your config, has commands under /api/register/. the "register" command is then accessed as /api/register/register.
from mod_restful.
yeah that was a typo.. but its the same.
POST /api/register/register HTTP/1.1
Host: vAir.box.private:8088
Accept: /
Content-type: application/json
Content-Length: 83
{"key":"secret","username":"test4","host":"vAir.box.private","password":"test4"}
HTTP/1.1 401 Unauthorized
Content-Type: text/html; charset=utf-8
Content-Length: 337
from mod_restful.
After i saw that yesterday, i compiled taybin's fork, and i am receiving now some errors in ejabberd.log
=ERROR REPORT==== 2013-04-16 15:46:26 ===
E(<0.587.0>:mod_restful:153) : Error in mod_restful:process: {badmatch,false}
[{mod_restful,handle_request,3,[{file,"src/mod_restful.erl"},{line,162}]},
{mod_restful,process,2,[{file,"src/mod_restful.erl"},{line,149}]},
{ejabberd_http,process,2,[{file,"ejabberd_http.erl"},{line,335}]},
{ejabberd_http,process_request,1,[{file,"ejabberd_http.erl"},{line,453}]},
{ejabberd_http,process_header,2,[{file,"ejabberd_http.erl"},{line,269}]},
{ejabberd_http,receive_headers,1,[{file,"ejabberd_http.erl"},{line,173}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,227}]}]
from mod_restful.
If I read that trace correctly, it fails on the following line:
true = lists:member(Host, ejabberd_config:get_global_option(hosts)),
This would mean that the host specified is not the same as the jabber domain.
from mod_restful.
yeah, i also thought so, but then why /api/register/is_registered is returning the admin user that is already created ?
%% Admin user
{acl, admin, {user, "christian", "vAir.box.private"}}.
%% Hostname
{hosts, ["localhost","vAir","vAir.box.private"]}.
I am stuck here.
from mod_restful.
well it returns true.
from mod_restful.
is returning
{"error":"not_allowed"}
from mod_restful.
I wonder if it has anything to do with your capitalization, i.e. vAir.b... vs vair.b...
from mod_restful.
yes. that was the case, i just found the same, thx really for support.
from mod_restful.
it had to be all lowercase
from mod_restful.
Would probably make sense to add some to_lower to mod_restful somewhere then, to avoid this issue in the future.
from mod_restful.
Hello, I'm facing the same issue.
2014-02-03 20:36:40.152 [error] <0.447.0> Processing throwed error {badmatch,false}
trace: [{mod_restful,handle_request,3,[{file,"src/mod_restful.erl"},{line,179}]},{mod_restful,process,2,[{file,"src/mod_restful.erl"},{line,161}]},{ejabberd_http,process,2,[{file,"src/ejabberd_http.erl"},{line,356}]},{ejabberd_http,process_request,1,[{file,"src/ejabberd_http.erl"},{line,462}]},{ejabberd_http,process_header,2,[{file,"src/ejabberd_http.erl"},{line,288}]},{ejabberd_http,receive_headers,1,[{file,"src/ejabberd_http.erl"},{line,182}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]
The stacktrace point to the same line:
true = lists:member(Host, ejabberd_config:get_global_option(hosts))
However, my host does not have any capital letter.
Here is the request:
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,pt;q=0.6
Connection:keep-alive
Content-Length:92
Content-Type:text/plain;charset=UTF-8
Host:54.208.69.134:8088
Origin:chrome-extension://cokgbflfommojglbmbpenpphppikmonn
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.58 Safari/537.36
{"key":"secret","username":"test4","host":"ip-172-31-9-188.ec2.internal","password":"test4"}
Here is my ejabberd.cfg
{8088, ejabberd_http, [
{request_handlers, [{["api"], mod_restful}]}
]},
...
{mod_restful, [
{api,
[
{["admin"], mod_restful_admin, [
{key, "secret"},
{allowed_commands, [register, unregister]}
]},
{["register"], mod_restful_register, [{key, "secret"}]}
]}
]}
...
{hosts, ["ip-172-31-9-188.ec2.internal"]}.
I alway got error 401 Unauthorized. Can you please help me on this? Thanks in advanced!
from mod_restful.
If i set the Host header of the request, i got this error:
=CRASH REPORT==== 4-Feb-2014::03:03:23 ===
crasher:
initial call: mod_restful:init/1
pid: <0.417.0>
registered_name: 'mod_restful_ip-172-31-9-188.ec2.internal'
exception exit: {function_clause,
[{proplists,get_value,
[path,
{[<<"register">>],
mod_restful_register,
[{key,<<"secret">>}]},
undefined],
[{file,"proplists.erl"},{line,225}]},
{mod_restful,get_api_mod,2,
[{file,"src/mod_restful.erl"},{line,117}]},
{mod_restful,handle_call,3,
[{file,"src/mod_restful.erl"},{line,124}]},
{gen_server,handle_msg,5,
[{file,"gen_server.erl"},{line,585}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,239}]}]}
in function gen_server:terminate/6 (gen_server.erl, line 744)
ancestors: [ejabberd_sup,<0.38.0>]
messages: []
links: [<0.297.0>]
dictionary: []
trap_exit: false
status: running
heap_size: 610
stack_size: 27
reductions: 155
neighbours:
from mod_restful.
@guitcastro what version (commit) are you using?
from mod_restful.
The last one.
from mod_restful.
The master branch is being ported to ejabberd 13.* so if you run ejabberd-2.1.x you need to check out the 0.1.x branch.
from mod_restful.
I'm using ejabberd 13.2
from mod_restful.
Hmm. If you're using ejabberd 13.x, how is it possible that you have the ejabberd 2.1.x style configuration? 13.x uses the yaml syntax.
from mod_restful.
To be honesty, I don`t know.
I Just download ejabberd 13.12 from http://www.process-one.net/en/ejabberd/downloads/
from mod_restful.
If you want to try the in-progress port, then I suggest you read the commit message here: 4869c9c
from mod_restful.
Ok, Thanks very much.
It seems you have to manual change the config file from .cfg to .yml using:
bin/ejabberdctl convert_to_yaml $PWD/conf/ejabberd.cfg $PWD/conf/ejabberd.yml
Then edit the ejabberdctl spring to search for the yml config.
I did that and then I tried the config you show me on the commit, but I got this error:
2014-02-04 13:38:25.934 [error] <0.38.0>@ejabberd_config:get_plain_terms_file:170 Syntax error on line 69 at position 11: did not find expected key
mod_restful:
api:
- path: ["admin"]
module: mod_restful_admin -> Line 69
params:
key: "secret"
allowed_commands: [register, unregister]
- path: ["register"]
module: mod_restful_register
params:
key: "secret"```
from mod_restful.
Try instead:
mod_restful:
api:
- path: ["admin"]
module: mod_restful_admin -> Line 69
params:
key: "secret"
allowed_commands: [register, unregister]
- path: ["register"]
module: mod_restful_register
params:
key: "secret"
from mod_restful.
Awesome! Thanks very much!
I know that I already bothered you a lot, but now I'm getting:
{"error": "not_allowed"}
Can you help me with this, too ?
EDIT:
NVM, I was passing the wrong host on register. Thanks so much for your help and your module!
Cheers!
from mod_restful.
Great! If you find bugs any bugs, feel free to open a new issue.
from mod_restful.
Related Issues (20)
- AJAX Cross Domain POST
- Port to ejabberd 13.10 HOT 1
- Unable to compile mod_restful in Ubuntu HOT 3
- ejabberd_config:get_plain_terms_file:170 Syntax error on line 363 at position 3: did not find expected key HOT 2
- can you offer a yaml config example? HOT 6
- 401 Unauthorized HOT 3
- unregister requires the user password? HOT 2
- 401 Unauthorized HOT 1
- How to add mod_restfull HOT 6
- error bad request HOT 6
- probably a bug
- How to compile this under windows? HOT 2
- Is it compatible with ejabberd 15? HOT 2
- mod_restful on ejabberd_16.01 - Problem with module mod_restful HOT 3
- can't change password
- ejabbered 16.04 cannot start
- 401 Unauthorized HOT 2
- Error occured while unregister a user using mod_restful
- Installation issue on ejabberd 17.04 HOT 1
- updating vcard using the http rest API
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mod_restful.