From 90d1eaad4643fdc55deccf6e30d4a302315e8808 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 27 Mar 2020 12:02:35 +0000 Subject: [PATCH] [4.3] add support for authn with jsonnrpc (#6417) --- applications/ecallmgr/src/ecallmgr_fs_authn.erl | 3 +++ applications/ecallmgr/src/ecallmgr_fs_xml.erl | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/applications/ecallmgr/src/ecallmgr_fs_authn.erl b/applications/ecallmgr/src/ecallmgr_fs_authn.erl index 915d7c30f55..b2ed6c7b06e 100644 --- a/applications/ecallmgr/src/ecallmgr_fs_authn.erl +++ b/applications/ecallmgr/src/ecallmgr_fs_authn.erl @@ -165,6 +165,7 @@ handle_directory_lookup(Id, Props, Node) -> case props:get_value(<<"action">>, Props, <<"sip_auth">>) of <<"reverse-auth-lookup">> -> lookup_user(Node, Id, <<"reverse-lookup">>, Props); <<"sip_auth">> -> maybe_sip_auth_response(Id, Props, Node); + <<"jsonrpc-authenticate">> -> maybe_sip_auth_response(Id, Props, Node); _Other -> directory_not_found(Node, Id) end. @@ -191,9 +192,11 @@ kamailio_association(Id, Props, Node) -> Password = kz_binary:rand_hex(12), Realm = props:get_value(<<"domain">>, Props), Username = props:get_value(<<"user">>, Props, props:get_value(<<"Auth-User">>, Props)), + Action = props:get_value(<<"action">>, Props, <<"sip_auth">>), CCVs = [{Key, Value} || {<<"X-ecallmgr_", Key/binary>>, Value} <- Props], JObj = kz_json:from_list_recursive([{<<"Auth-Method">>, <<"password">>} ,{<<"Auth-Password">>, Password} + ,{<<"Auth-Action">>, Action} ,{<<"Domain-Name">>, Realm} ,{<<"User-ID">>, Username} ,{<<"Custom-Channel-Vars">>, CCVs} diff --git a/applications/ecallmgr/src/ecallmgr_fs_xml.erl b/applications/ecallmgr/src/ecallmgr_fs_xml.erl index 3f070ee9c2f..b68355ac60c 100644 --- a/applications/ecallmgr/src/ecallmgr_fs_xml.erl +++ b/applications/ecallmgr/src/ecallmgr_fs_xml.erl @@ -105,7 +105,7 @@ authn_resp_xml(<<"gsm">>, JObj) -> {'ok', [VariablesEl, ParamsEl, HeadersEl]}; authn_resp_xml(<<"password">>, JObj) -> PassEl = param_el(<<"password">>, kz_json:get_value(<<"Auth-Password">>, JObj)), - ParamsEl = params_el([PassEl]), + ParamsEl = params_el([PassEl | authn_resp_params(JObj)]), VariableEls = [variable_el(K, V) || {K, V} <- get_channel_params(JObj)], VariablesEl = variables_el(VariableEls), @@ -125,6 +125,19 @@ authn_resp_xml(_Method, _JObj) -> lager:debug("unknown method ~s", [_Method]), empty_response(). +-spec authn_resp_params(kz_json:object()) -> list(). +authn_resp_params(JObj) -> + Action = kz_json:get_value(<<"Auth-Action">>, JObj), + authn_resp_params(Action, JObj). + +-spec authn_resp_params(kz_term:ne_binary(), kz_json:object()) -> list(). +authn_resp_params(<<"jsonrpc-authenticate">>, _JObj) -> + [param_el(<<"jsonrpc-allowed-methods">>, <<"verto">>) + ,param_el(<<"jsonrpc-allowed-event-channels">>, <<"conference">>) + ]; +authn_resp_params(_, _JObj) -> + []. + -spec reverse_authn_resp_xml(kz_term:api_terms()) -> {'ok', iolist()}. reverse_authn_resp_xml([_|_]=RespProp) -> reverse_authn_resp_xml(props:get_value(<<"Auth-Method">>, RespProp)