Reply To: integrate PHP with Erlang

Home Forums Basic Erlang integrate PHP with Erlang Reply To: integrate PHP with Erlang

#46127

pzel
Member

@Aliraza149, you will want to write a ejabberd_auth_yourmodule.erl module that implements the ejabberd_auth callbacks. Inside this module, you can perform your required business logic.

So, for example, you can have the following workflow:

* Client logs in via HTTP call to your backend, gets AUTH-TOKEN
* Client logs in to MongooseIM with ClientID, AUTH-TOKEN as the password
* ejabberd_auth_yourmodule:check_password/3 gets called with ClientID, XMPPDomain, AUTH-TOKEN
* ejabberd_auth_yourmodule calls your PHP backend and verifies that the AUTH-TOKEN is valid
* check_password returns true if valid, false if invalid.

This module is a very featureful implementation of a scenario like the one above. You don’t have to implement all the functions. The most basic implementation would require check_password/3 to work and all the other functions to return some sane defaults, like the ones below:


%%% ----------------------------------------------------------------------------
%%% ejabberd_auth API
%%% ----------------------------------------------------------------------------
-spec check_password(binary(), binary(), binary()) -> true | false.
check_password(User, Server, Token) ->
  %% perform your backend calls here
  true.

plain_password_required() ->
    true.

store_type() ->
    plain.

set_password(_User, _Server, _Password) ->
    ok.

try_register(_User, _Server, _Password) ->
    {aborted, unsupported_op}.

dirty_get_registered_users() ->
    [].

get_vh_registered_users(_Server) ->
    [].

get_vh_registered_users(Server, _) ->
    get_vh_registered_users(Server).

get_vh_registered_users_number(_Server) ->
    0.

get_vh_registered_users_number(Server, _) ->
    get_vh_registered_users_number(Server).

get_password(_User, _Server) ->
    false.

get_password_s(_User, _Server) ->
    [].

is_user_exists(_User, _Server) ->
    %% Just assume every user is legal for starters
    true.

remove_user(_User, _Server) ->
    ok.

remove_user(_User, _Server, _Password) ->
    ok.
  • This reply was modified 2 months, 3 weeks ago by  pzel.