What function/module that write oauth info (token, user etc) into mnesia in ejabberd_oauth.erl?

I'm trying to understand how ejabberd_oauth.erl implementing the oauth. Inside the ejabberd_oauth.erl, there is a function name associate_access_token - this is where mnesia:dirty_write(R) located. Based on my understanding, mnesia:dirty_write(R) should write the record into the DB but I totally wrong after completed the test.

Test : I've commented the whole function and run the oauth, then dump_table to check the latest DB content. The DB that I just dumped still contain the latest token. This is means that the write-into-the-db is controlled by another function.

Note : I even rename (make typo) mnesia:dirty_write(R) to be something like mnesia:dirtysz_write(R). My test proved that associate_access_token don't even detect / check the syntax error of mnesia:dirty_write(R).

Please advice.

Thanks!

I can think two

I can think two possibilities:

A) That function is not used, or is not responsible for the writting you are investigating.

B) Your are editing the source code, but you later don't run that code. Remember to compile, copy the resulting beam file (or install) to the proper place, and restart ejabberd.

I suspect you suffer problem B. To check what is going on, add those two logging lines. They will tell you if the module that you modify is really used by ejabberd, and also if the function is used when writting information:

--- a/src/ejabberd_oauth.erl
+++ b/src/ejabberd_oauth.erl
@@ -66,6 +66,7 @@
 
 start() ->
     init_db(mnesia, ?MYNAME),
+    ?INFO_MSG("staring Oauth", []),
     Expire = expire(),
     application:set_env(oauth2, backend, ejabberd_oauth),
     application:set_env(oauth2, expiry_time, Expire),
@@ -181,6 +182,7 @@ associate_access_token(AccessToken, Context, AppContext) ->
       scope = Scope,
       expire = Expire
      },
+    ?INFO_MSG("associating ~p", [{AccessToken, Context, AppContext}]),
     mnesia:dirty_write(R),
     {ok, AppContext}.

Syndicate content