Skip to content

Commit 126c942

Browse files
committed
Basic working version of MojoAuth module
1 parent 5263ee9 commit 126c942

File tree

3 files changed

+103
-1
lines changed

3 files changed

+103
-1
lines changed

rebar.config.script

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Deps = [{p1_cache_tab, ".*", {git, "git://github.com/processone/cache_tab"}},
6262
{p1_stun, ".*", {git, "git://github.com/processone/stun"}},
6363
{p1_yaml, ".*", {git, "git://github.com/processone/p1_yaml"}},
6464
{ehyperloglog, ".*", {git, "https://github.com/vaxelfel/eHyperLogLog.git"}},
65+
{mojoauth, ".*", {git, "https://github.com/mojolingo/mojoauth.erl.git"}},
6566
{p1_utils, ".*", {git, "git://github.com/processone/p1_utils"}}],
6667

6768
ConfigureCmd = fun(Pkg, Flags) ->

src/ejabberd_auth.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ check_password(User, AuthzId, Server, Password, Digest,
134134
%% {true, AuthModule} | false
135135
%% where
136136
%% AuthModule = ejabberd_auth_anonymous | ejabberd_auth_external
137-
%% | ejabberd_auth_internal | ejabberd_auth_ldap
137+
%% | ejabberd_auth_internal | ejabberd_auth_ldap | ejabberd_auth_mojoauth
138138
%% | ejabberd_auth_odbc | ejabberd_auth_pam | ejabberd_auth_riak
139139
-spec check_password_with_authmodule(binary(), binary(), binary(), binary()) -> false |
140140
{true, atom()}.

src/ejabberd_auth_mojoauth.erl

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
%%%----------------------------------------------------------------------
2+
%%% File : ejabberd_auth_mojoauth.erl
3+
%%% Author : Ben Langfeld <[email protected]>
4+
%%% Purpose : Authentication via MojoAuth (http://mojoauth.mojolingo.com/)
5+
%%% Created : 18 February 2015 by Ben Langfeld <[email protected]>
6+
%%%
7+
%%%
8+
%%% ejabberd, Copyright (C) 2002-2015 ProcessOne
9+
%%%
10+
%%% This program is free software; you can redistribute it and/or
11+
%%% modify it under the terms of the GNU General Public License as
12+
%%% published by the Free Software Foundation; either version 2 of the
13+
%%% License, or (at your option) any later version.
14+
%%%
15+
%%% This program is distributed in the hope that it will be useful,
16+
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18+
%%% General Public License for more details.
19+
%%%
20+
%%% You should have received a copy of the GNU General Public License along
21+
%%% with this program; if not, write to the Free Software Foundation, Inc.,
22+
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23+
%%%
24+
%%%----------------------------------------------------------------------
25+
26+
-module(ejabberd_auth_mojoauth).
27+
28+
-author('[email protected]').
29+
30+
-behaviour(ejabberd_auth).
31+
32+
%% External exports
33+
-export([start/1, set_password/3, check_password/4,
34+
check_password/6, try_register/3,
35+
dirty_get_registered_users/0, get_vh_registered_users/1,
36+
get_vh_registered_users/2,
37+
get_vh_registered_users_number/1,
38+
get_vh_registered_users_number/2, get_password/2,
39+
get_password_s/2, is_user_exists/2, remove_user/2,
40+
remove_user/3, store_type/0,
41+
plain_password_required/0]).
42+
43+
-include("ejabberd.hrl").
44+
-include("logger.hrl").
45+
-include_lib("mojoauth/include/mojoauth.hrl").
46+
47+
%%%----------------------------------------------------------------------
48+
%%% API
49+
%%%----------------------------------------------------------------------
50+
start(Host) ->
51+
ejabberd_auth_internal:start(Host).
52+
53+
plain_password_required() -> true.
54+
55+
store_type() -> external.
56+
57+
secret(Server) ->
58+
LServer = jlib:nameprep(Server),
59+
ejabberd_config:get_option(
60+
{mojoauth_secret, LServer},
61+
fun(V) -> iolist_to_binary(V) end,
62+
"mojoauth").
63+
64+
check_password(User, AuthzId, Server, Password) ->
65+
AuthzIdList = binary_to_list(AuthzId),
66+
case mojoauth:test_credentials([{username, binary_to_list(User)}, {password, Password}], secret(Server)) of
67+
AuthzIdList -> true;
68+
_ -> false
69+
end.
70+
71+
check_password(User, AuthzId, Server, Password, _Digest, _DigestGen) ->
72+
check_password(User, AuthzId, Server, Password).
73+
74+
set_password(_User, _Server, _Password) -> {error, not_allowed}.
75+
76+
try_register(_User, _Server, _Password) -> {error, not_allowed}.
77+
78+
dirty_get_registered_users() ->
79+
ejabberd_auth_internal:dirty_get_registered_users().
80+
81+
get_vh_registered_users(Server) ->
82+
ejabberd_auth_internal:get_vh_registered_users(Server).
83+
84+
get_vh_registered_users(Server, Data) ->
85+
ejabberd_auth_internal:get_vh_registered_users(Server, Data).
86+
87+
get_vh_registered_users_number(Server) ->
88+
ejabberd_auth_internal:get_vh_registered_users_number(Server).
89+
90+
get_vh_registered_users_number(Server, Data) ->
91+
ejabberd_auth_internal:get_vh_registered_users_number(Server, Data).
92+
93+
get_password(_User, _Server) -> false.
94+
95+
get_password_s(_User, _Server) -> <<"">>.
96+
97+
is_user_exists(_User, _Server) -> true.
98+
99+
remove_user(_User, _Server) -> false.
100+
101+
remove_user(_User, _Server, _Password) -> false.

0 commit comments

Comments
 (0)