Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for authn with jsonnrpc - 4.3 #6417

Merged
merged 1 commit into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions applications/ecallmgr/src/ecallmgr_fs_authn.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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}
Expand Down
15 changes: 14 additions & 1 deletion applications/ecallmgr/src/ecallmgr_fs_xml.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
Expand Down