Skip to content

Commit

Permalink
Merge 6c37f73 into c7935ad
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Feb 4, 2021
2 parents c7935ad + 6c37f73 commit 572f39f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
7 changes: 3 additions & 4 deletions src/auth/ejabberd_auth_http.erl
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,9 @@ remove_user_req(LUser, LServer, Password, Method) ->
make_req(_, _, LUser, LServer, _) when LUser == error orelse LServer == error ->
{error, invalid_jid};
make_req(Method, Path, LUser, LServer, Password) ->
LUserE = list_to_binary(http_uri:encode(binary_to_list(LUser))),
LServerE = list_to_binary(http_uri:encode(binary_to_list(LServer))),
PasswordE = list_to_binary(http_uri:encode(binary_to_list(Password))),
Query = <<"user=", LUserE/binary, "&server=", LServerE/binary, "&pass=", PasswordE/binary>>,
Query = uri_string:compose_query([{<<"user">>, LUser},
{<<"server">>, LServer},
{<<"pass">>, Password}]),
Header = case ejabberd_auth:get_opt(LServer, basic_auth) of
undefined ->
[];
Expand Down
15 changes: 6 additions & 9 deletions src/mod_muc_room.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1919,12 +1919,12 @@ perform_http_auth(From, Nick, Packet, Role, Password, StateData) ->
end.

make_http_auth_request(From, RoomJid, Password, Pool) ->
FromVal = uri_encode(jid:to_binary(From)),
RoomJidVal = uri_encode(jid:to_binary(RoomJid)),
PassVal = uri_encode(Password),
Path = <<"check_password?from=", FromVal/binary,
"&to=", RoomJidVal/binary,
"&pass=", PassVal/binary>>,
Query = uri_string:compose_query(
[{<<"from">>, jid:to_binary(From)},
{<<"to">>, jid:to_binary(RoomJid)},
{<<"pass">>, Password}
]),
Path = <<"check_password", "?", Query/binary>>,
case mongoose_http_client:get(global, Pool, Path, []) of
{ok, {<<"200">>, Body}} -> decode_http_auth_response(Body);
_ -> error
Expand All @@ -1937,9 +1937,6 @@ handle_http_auth_result({invalid_password, ErrorMsg}, From, Nick, Packet, _Role,
handle_http_auth_result(error, From, Nick, Packet, _Role, StateData) ->
reply_service_unavailable(From, Nick, Packet, StateData, <<"Internal server error">>).

uri_encode(Bin) ->
list_to_binary(http_uri:encode(binary_to_list(Bin))).

decode_http_auth_response(Body) ->
try decode_json_auth_response(Body) of
{0, _} ->
Expand Down

0 comments on commit 572f39f

Please sign in to comment.