fix(jwt): simplify binary_to_number function

This commit is contained in:
firest 2022-09-01 16:27:15 +08:00
parent c999b43144
commit ddc25fc5c2
1 changed files with 10 additions and 16 deletions

View File

@ -90,22 +90,16 @@ is_expired(Exp) ->
description() -> "Authentication with JWT". description() -> "Authentication with JWT".
binary_to_number(Bin) -> binary_to_number(Bin) ->
Checker = fun([], _) -> try
false; {ok, erlang:binary_to_integer(Bin)}
([H | T], Self) -> catch _:_ ->
try try
{ok, H(Bin)} Val = erlang:binary_to_float(Bin),
catch _:_ -> {ok, erlang:round(Val)}
Self(T, Self) catch _:_ ->
end false
end, end
end.
Checker([fun erlang:binary_to_integer/1,
fun(In) ->
Val = erlang:binary_to_float(In),
erlang:round(Val)
end],
Checker).
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
%% Verify Claims %% Verify Claims