Closed pinanklakhani closed 1 year ago
mod_register says "trusted network" so only "loopback"
Where are you registering from?
Trying to register by 2 ways
1.) Command line
ejabberdctl register user1 localhost password
2.) API
curl --location 'http://localhost:5443/api/register' \
--header 'Content-Type: application/json' \
--data '{
"user": "user1",
"password": "password",
"host": "localhost"
}'
None of the ways are working
@licaon-kter Trying to access from local only
Remove auth method and auth opts, reload, then test via ejabberdctl, does that work?
What do the logs say?
Please notice that the register query should return 201 in case of success, not 200. See https://github.com/processone/ejabberd-contrib/tree/master/ejabberd_auth_http#register
This is what the query sent by ejabberd and the response that your HTTP service in port 8080 should provide:
POST /auth/register HTTP/1.1
Host: localhost:8080
Content-Length: 36
Authorization: Basic
Content-Type: application/x-www-form-urlencoded
user=user6&server=localhost&pass=asd
HTTP/1.1 201 Created
Content-Length: 1
Access-Control-Allow-Headers: Content-Type, Authorization, X-Admin
Access-Control-Allow-Origin: *
Content-Type: application/json
0
Notice the 201 response that your HTTP service should provide to ejabberd.
@badlop It worked but it didnt create entry in users table of ejabberd database like it does with auth_method: sql.
So with auth_method: sql
, it is creating entry in following tables,
2023-02-21 10:30:23.989562+05:30 [debug] <0.490.0>@ejabberd_sql:sql_query_internal/1:713 SQL: "select password, serverkey, salt, iterationcount from users where username='user4' and 0=0"
2023-02-21 10:30:24.014507+05:30 [debug] <0.491.0>@ejabberd_sql:sql_query_internal/1:713 SQL: "INSERT INTO users(username, password, serverkey, salt, iterationcount) VALUES ('user4', 'GY3eRi8XlqIlwbkmLbhvq/dfWwg=', 'yaGm/HxK/LU5hHuNI4RhVDmlopQ=', 'ZYqvUUoF9oJze+eFCJoYrQ==', 4096);"
2023-02-21 10:30:24.016637+05:30 [debug] <0.598.0>@ejabberd_hooks:safe_apply/4:315 Running hook register_user: mod_last:register_user/2
2023-02-21 10:30:24.016870+05:30 [debug] <0.492.0>@ejabberd_sql:sql_query_internal/1:713 SQL: "INSERT INTO last(username, seconds, state) VALUES ('user4', '1676955624', 'Registered but didn''t login') ON DUPLICATE KEY UPDATE seconds=VALUES(seconds), state=VALUES(state)"
2023-02-21 10:30:24.017902+05:30 [debug] <0.598.0>@ejabberd_hooks:safe_apply/4:315 Running hook register_user: mod_shared_roster:register_user/2
2023-02-21 10:30:24.018167+05:30 [debug] <0.488.0>@ejabberd_sql:sql_query_internal/1:713 SQL: "select grp from sr_user where jid='user4@localhost' and 0=0"
And with auth_method: http
, the execution flow is as below
2023-02-21 10:31:05.089474+05:30 [debug] <0.598.0>@ejabberd_auth_http:make_req/5:215 Making request 'user_exists' for user user5@localhost...
2023-02-21 10:31:05.091527+05:30 [debug] <0.598.0>@ejabberd_auth_http:make_req/5:223 Request result: 200: <<"false">>
2023-02-21 10:31:05.091708+05:30 [debug] <0.598.0>@ejabberd_auth_http:make_req/5:215 Making request 'register' for user user5@localhost...
2023-02-21 10:31:05.093234+05:30 [debug] <0.598.0>@ejabberd_auth_http:make_req/5:223 Request result: 201: <<"true">>
2023-02-21 10:31:05.093372+05:30 [debug] <0.598.0>@ejabberd_hooks:safe_apply/4:315 Running hook register_user: mod_last:register_user/2
2023-02-21 10:31:05.093636+05:30 [debug] <0.490.0>@ejabberd_sql:sql_query_internal/1:713 SQL: "INSERT INTO last(username, seconds, state) VALUES ('user5', '1676955665', 'Registered but didn''t login') ON DUPLICATE KEY UPDATE seconds=VALUES(seconds), state=VALUES(state)"
2023-02-21 10:31:05.097776+05:30 [debug] <0.598.0>@ejabberd_hooks:safe_apply/4:315 Running hook register_user: mod_shared_roster:register_user/2
2023-02-21 10:31:05.098036+05:30 [debug] <0.491.0>@ejabberd_sql:sql_query_internal/1:713 SQL: "select grp from sr_user where jid='user5@localhost' and 0=0"
So its calling webhook methods and not creating entry in users table. So do we have to write that code in webhook register method or something is missing in config?
Not sure it should create in sql since you tell it to use that http to auth, meaning users are kept elsewhere.
Does messaging work?
@licaon-kter @badlop Also i wanted to authenticate my external JWT token at the time of connection and registration. So i tried to take JWT token in password field but its throwing an error
{
"status": "error",
"code": 10001,
"message": "Can't register user user7@localhost at node ejabberd@localhost: The password contains unacceptable characters"
}
Any alternate way?
Also what should i do with password? As chat is a feature in my platform and we already have a login page
First test that everything works BEFORE jwt and http auth.
Then try http...
Then JWT...
Mixing 3 ways to auth will not help.
First test that everything works BEFORE jwt and http auth.
Then try http...
Then JWT...
Mixing 3 ways to auth will not help.
Yes rest things are working fine. Some issue was there from my end it is resolved. Now how to deal with JWT for auth and register?
Not sure it should create in sql since you tell it to use that http to auth, meaning users are kept elsewhere.
Does messaging work?
Yes Working
@badlop @licaon-kter I am using ejabberd to develop a feature in my platform so there is already login, register page and also JWT. So now how can i pass token while connecting to xmpp server for the first time or at the time of register using curl request
curl --location 'http://localhost:5443/api/register' \
--header 'Content-Type: application/json' \
--data '{
"user": "user1",
"password": "password",
"host": "localhost"
}'
I don't need password field. i have JWT instead.
I tried by passing jwt token in password field but its giving following error
{
"status": "error",
"code": 10001,
"message": "Can't register user user7@localhost at node ejabberd@localhost: The password contains unacceptable characters"
}
Sorry, I missed this question. Did you already solve the problem and this issue can be closed? Or is the problem still present?
Sorry, I missed this question. Did you already solve the problem and this issue can be closed? Or is the problem still present?
Np @badlop We can close the issue. It is solved.
Updated auth method to http and configured the external webhooks. But since after that i am unable to register via command line or api. Using this plugin for webhook callbacks: https://github.com/processone/ejabberd-contrib/tree/master/ejabberd_auth_http
My ejabberd.yml file is as below:
Please help me with the solution.