Open atrauzzi opened 4 years ago
I suspect something like this is necessary:
unpadded_base64_decode(Base64) ->
try base64:decode(Base64) catch
error:_ -> try base64:decode(<<Base64/binary, "=">>) catch
error:_ try base64:decode(<<Base64/binary, "==">>) catch
error:_ -> error
end
end
end.
@atrauzzi thanks for the report! but there's better solution, length of base64 string with padding should be multiple of four, so I prefer write it like this:
unpadded_base64_decode(Base64) ->
case rem(byte_size(Base64), 4) of
0 -> base64:decode(Base64);
N -> base64:decode(<<Base64, binary:copy(<<"=">>, N)>>)
end.
alternatively, we can take base64 impl that doesn't require padding at the end of a string and just put it directly into library :)
I believe at the following line: https://github.com/artemeff/jwt/blob/master/src/jwt.erl#L146
...an error is occurring when attempting to decode un-padded base64 values.
As per the spec,
I think this library needs to allow for un-padded base64 encoded JWT parts?