Question

I am using ejabberd in one of my project, which is itself implemented in erlang. I am interested in gaining access to the authentication flow, so that i can integrate my user db without having to register them separately in ejabberd.

I have got most of the things right as described here: https://git.process-one.net/ejabberd/mainline/blobs/raw/2.1.x/doc/dev.html#htoc8

However, seemingly ejabberd never receive response from my escript. Below is a part of the code responsible for sending resopnse:

process_data(["auth", _User, _Server, _Pass]) ->
    BB = <<1:16>>, %% result code 1 coded as short
    AA = byte_size(BB), %% AA is byte length of result
    Bin = <<AA:16,BB/binary>>, %% finally packing AA as short along with BB
    io:put_chars(Bin);

From my logs i end up sending:

=DEBUG== 2011-05-25 21:05:15 == <0.2.0> == extauth:53 ===
sent <<0,2,0,1>>

which is exactly similar to what i used to do inside PHP:

fwrite($out, pack("nn", 2, $result_code));

I m not sure where i m messing up.

Also i am interested if there is a better way to integrate my user db, since my app is itself in erlang and i would probably like to take advantage of erlang message passing instead of reading/writing stdin/stdout inside extauth

Was it helpful?

Solution

Two ideas:

1) Does your database support SQL? If so, enable {auth_method, odbc} as described in https://support.process-one.net/doc/display/MESSENGER/Using+ejabberd+with+MySQL+native+driver You can create views to mirror your internal DB structure into what ejabberd expects.

2) You could always create your own auth_method. If you are already skilled in Erlang, the code of Ejabberd is not hard to understand. I just glanced through the code for ejabberd_auth at https://github.com/processone/ejabberd/blob/2.1.x/src/ejabberd_auth.erl and it's fairly simple actually. Just create a module called ejabberd_auth_abhinav, export the necessary functions, and then enabled {auth_method, abhinav} and you're good to go.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top