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