fix(authn/http): log meaningful error message if http header is missing
This commit is contained in:
parent
4fb484d4cf
commit
2acde5a4e4
|
@ -301,7 +301,11 @@ serialize_body(<<"application/json">>, BodyTemplate, ClientInfo) ->
|
||||||
emqx_utils_json:encode(Body);
|
emqx_utils_json:encode(Body);
|
||||||
serialize_body(<<"application/x-www-form-urlencoded">>, BodyTemplate, ClientInfo) ->
|
serialize_body(<<"application/x-www-form-urlencoded">>, BodyTemplate, ClientInfo) ->
|
||||||
Body = emqx_auth_utils:render_deep_for_url(BodyTemplate, ClientInfo),
|
Body = emqx_auth_utils:render_deep_for_url(BodyTemplate, ClientInfo),
|
||||||
uri_string:compose_query(maps:to_list(Body)).
|
uri_string:compose_query(maps:to_list(Body));
|
||||||
|
serialize_body(undefined, _BodyTemplate, _ClientInfo) ->
|
||||||
|
throw(missing_content_type_header);
|
||||||
|
serialize_body(ContentType, _BodyTemplate, _ClientInfo) ->
|
||||||
|
throw({unknown_content_type_header_value, ContentType}).
|
||||||
|
|
||||||
-ifdef(TEST).
|
-ifdef(TEST).
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
|
@ -678,16 +678,28 @@ do_authenticate(
|
||||||
{stop, Result}
|
{stop, Result}
|
||||||
catch
|
catch
|
||||||
Class:Reason:Stacktrace ->
|
Class:Reason:Stacktrace ->
|
||||||
?TRACE_AUTHN(warning, "authenticator_error", #{
|
?TRACE_AUTHN(
|
||||||
exception => Class,
|
warning,
|
||||||
reason => Reason,
|
"authenticator_error",
|
||||||
stacktrace => Stacktrace,
|
maybe_add_stacktrace(
|
||||||
authenticator => ID
|
Class,
|
||||||
}),
|
#{
|
||||||
|
exception => Class,
|
||||||
|
reason => Reason,
|
||||||
|
authenticator => ID
|
||||||
|
},
|
||||||
|
Stacktrace
|
||||||
|
)
|
||||||
|
),
|
||||||
emqx_metrics_worker:inc(authn_metrics, MetricsID, nomatch),
|
emqx_metrics_worker:inc(authn_metrics, MetricsID, nomatch),
|
||||||
do_authenticate(ChainName, More, Credential)
|
do_authenticate(ChainName, More, Credential)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
maybe_add_stacktrace('throw', Data, _Stacktrace) ->
|
||||||
|
Data;
|
||||||
|
maybe_add_stacktrace(_, Data, Stacktrace) ->
|
||||||
|
Data#{stacktrace => Stacktrace}.
|
||||||
|
|
||||||
authenticate_with_provider(#authenticator{id = ID, provider = Provider, state = State}, Credential) ->
|
authenticate_with_provider(#authenticator{id = ID, provider = Provider, state = State}, Credential) ->
|
||||||
AuthnResult = Provider:authenticate(Credential, State),
|
AuthnResult = Provider:authenticate(Credential, State),
|
||||||
?TRACE_AUTHN("authenticator_result", #{
|
?TRACE_AUTHN("authenticator_result", #{
|
||||||
|
|
Loading…
Reference in New Issue