Skip to content

Commit 47c7494

Browse files
committed
MojoAuth module
Permits use of MojoAuth (http://mojoauth.mojolingo.com/) in ejabberd. MojoAuth is a set of standard approaches to cross-app authentication based on HMAC which is specified in RFC2104.
1 parent 6946a34 commit 47c7494

File tree

3 files changed

+101
-1
lines changed

3 files changed

+101
-1
lines changed

rebar.config.script

+1
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

+1-1
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

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
46+
%%%----------------------------------------------------------------------
47+
%%% API
48+
%%%----------------------------------------------------------------------
49+
start(Host) ->
50+
ejabberd_auth_internal:start(Host).
51+
52+
plain_password_required() -> true.
53+
54+
store_type() -> external.
55+
56+
secret(Server) ->
57+
LServer = jlib:nameprep(Server),
58+
ejabberd_config:get_option(
59+
{mojoauth_secret, LServer},
60+
fun(V) -> iolist_to_binary(V) end,
61+
"mojoauth").
62+
63+
check_password(User, AuthzId, Server, Password) ->
64+
case mojoauth:test_credentials([{username, User}, {password, Password}], secret(Server)) of
65+
{ok, AuthzId} -> true;
66+
_ -> false
67+
end.
68+
69+
check_password(User, AuthzId, Server, Password, _Digest, _DigestGen) ->
70+
check_password(User, AuthzId, Server, Password).
71+
72+
set_password(_User, _Server, _Password) -> {error, not_allowed}.
73+
74+
try_register(_User, _Server, _Password) -> {error, not_allowed}.
75+
76+
dirty_get_registered_users() ->
77+
ejabberd_auth_internal:dirty_get_registered_users().
78+
79+
get_vh_registered_users(Server) ->
80+
ejabberd_auth_internal:get_vh_registered_users(Server).
81+
82+
get_vh_registered_users(Server, Data) ->
83+
ejabberd_auth_internal:get_vh_registered_users(Server, Data).
84+
85+
get_vh_registered_users_number(Server) ->
86+
ejabberd_auth_internal:get_vh_registered_users_number(Server).
87+
88+
get_vh_registered_users_number(Server, Data) ->
89+
ejabberd_auth_internal:get_vh_registered_users_number(Server, Data).
90+
91+
get_password(_User, _Server) -> false.
92+
93+
get_password_s(_User, _Server) -> <<"">>.
94+
95+
is_user_exists(_User, _Server) -> true.
96+
97+
remove_user(_User, _Server) -> false.
98+
99+
remove_user(_User, _Server, _Password) -> false.

0 commit comments

Comments
 (0)