fix(auth): authn & authz HTTP haeders without `content-type` via GET method
This commit is contained in:
parent
1fd0ce8708
commit
e4826400b8
|
@ -127,7 +127,10 @@ headers_no_content_type(desc) ->
|
||||||
?DESC(?FUNCTION_NAME);
|
?DESC(?FUNCTION_NAME);
|
||||||
headers_no_content_type(converter) ->
|
headers_no_content_type(converter) ->
|
||||||
fun(Headers) ->
|
fun(Headers) ->
|
||||||
|
maps:without(
|
||||||
|
[<<"content-type">>],
|
||||||
maps:merge(default_headers_no_content_type(), transform_header_name(Headers))
|
maps:merge(default_headers_no_content_type(), transform_header_name(Headers))
|
||||||
|
)
|
||||||
end;
|
end;
|
||||||
headers_no_content_type(default) ->
|
headers_no_content_type(default) ->
|
||||||
default_headers_no_content_type();
|
default_headers_no_content_type();
|
||||||
|
@ -156,12 +159,11 @@ create(
|
||||||
#{
|
#{
|
||||||
method := Method,
|
method := Method,
|
||||||
url := RawURL,
|
url := RawURL,
|
||||||
headers := HeadersT,
|
headers := Headers,
|
||||||
body := Body,
|
body := Body,
|
||||||
request_timeout := RequestTimeout
|
request_timeout := RequestTimeout
|
||||||
} = Config
|
} = Config
|
||||||
) ->
|
) ->
|
||||||
Headers = ensure_header_name_type(HeadersT),
|
|
||||||
{BsaeUrlWithPath, Query} = parse_fullpath(RawURL),
|
{BsaeUrlWithPath, Query} = parse_fullpath(RawURL),
|
||||||
URIMap = parse_url(BsaeUrlWithPath),
|
URIMap = parse_url(BsaeUrlWithPath),
|
||||||
ResourceId = emqx_authn_utils:make_resource_id(?MODULE),
|
ResourceId = emqx_authn_utils:make_resource_id(?MODULE),
|
||||||
|
@ -171,7 +173,7 @@ create(
|
||||||
base_query_template => emqx_authn_utils:parse_deep(
|
base_query_template => emqx_authn_utils:parse_deep(
|
||||||
cow_qs:parse_qs(to_bin(Query))
|
cow_qs:parse_qs(to_bin(Query))
|
||||||
),
|
),
|
||||||
headers => maps:to_list(Headers),
|
headers => Headers,
|
||||||
body_template => emqx_authn_utils:parse_deep(
|
body_template => emqx_authn_utils:parse_deep(
|
||||||
maps:to_list(Body)
|
maps:to_list(Body)
|
||||||
),
|
),
|
||||||
|
@ -403,14 +405,3 @@ to_bin(L) when is_list(L) ->
|
||||||
|
|
||||||
get_conf_val(Name, Conf) ->
|
get_conf_val(Name, Conf) ->
|
||||||
hocon_maps:get(?CONF_NS ++ "." ++ Name, Conf).
|
hocon_maps:get(?CONF_NS ++ "." ++ Name, Conf).
|
||||||
|
|
||||||
ensure_header_name_type(Headers) ->
|
|
||||||
Fun = fun
|
|
||||||
(Key, _Val, Acc) when is_binary(Key) ->
|
|
||||||
Acc;
|
|
||||||
(Key, Val, Acc) when is_atom(Key) ->
|
|
||||||
Acc2 = maps:remove(Key, Acc),
|
|
||||||
BinKey = erlang:atom_to_binary(Key),
|
|
||||||
Acc2#{BinKey => Val}
|
|
||||||
end,
|
|
||||||
maps:fold(Fun, Headers, Headers).
|
|
||||||
|
|
|
@ -141,7 +141,10 @@ headers_no_content_type(desc) ->
|
||||||
?DESC(?FUNCTION_NAME);
|
?DESC(?FUNCTION_NAME);
|
||||||
headers_no_content_type(converter) ->
|
headers_no_content_type(converter) ->
|
||||||
fun(Headers) ->
|
fun(Headers) ->
|
||||||
|
maps:without(
|
||||||
|
[<<"content-type">>],
|
||||||
maps:merge(default_headers_no_content_type(), transform_header_name(Headers))
|
maps:merge(default_headers_no_content_type(), transform_header_name(Headers))
|
||||||
|
)
|
||||||
end;
|
end;
|
||||||
headers_no_content_type(default) ->
|
headers_no_content_type(default) ->
|
||||||
default_headers_no_content_type();
|
default_headers_no_content_type();
|
||||||
|
|
|
@ -157,7 +157,7 @@ generate_request(
|
||||||
_ ->
|
_ ->
|
||||||
NPath = append_query(Path, NBaseQuery),
|
NPath = append_query(Path, NBaseQuery),
|
||||||
NBody = serialize_body(
|
NBody = serialize_body(
|
||||||
proplists:get_value(<<"Accept">>, Headers, <<"application/json">>),
|
proplists:get_value(<<"accept">>, Headers, <<"application/json">>),
|
||||||
Body
|
Body
|
||||||
),
|
),
|
||||||
{NPath, Headers, NBody}
|
{NPath, Headers, NBody}
|
||||||
|
|
|
@ -230,7 +230,12 @@ headers_no_content_type(desc) ->
|
||||||
?DESC(?FUNCTION_NAME);
|
?DESC(?FUNCTION_NAME);
|
||||||
headers_no_content_type(converter) ->
|
headers_no_content_type(converter) ->
|
||||||
fun(Headers) ->
|
fun(Headers) ->
|
||||||
maps:to_list(maps:merge(default_headers_no_content_type(), transform_header_name(Headers)))
|
maps:to_list(
|
||||||
|
maps:without(
|
||||||
|
[<<"content-type">>],
|
||||||
|
maps:merge(default_headers_no_content_type(), transform_header_name(Headers))
|
||||||
|
)
|
||||||
|
)
|
||||||
end;
|
end;
|
||||||
headers_no_content_type(default) ->
|
headers_no_content_type(default) ->
|
||||||
default_headers_no_content_type();
|
default_headers_no_content_type();
|
||||||
|
|
Loading…
Reference in New Issue