Bas64 encoding bug when using JWT service

78 views
Skip to first unread message

Flo Baum

unread,
Nov 13, 2018, 9:05:19 AM11/13/18
to html5-chat
I'm using the chat integration like described here: https://html5-chat.com/blog/jwt-a-quicker-and-simpler-version-using-the-html5-service/

Whih works fine for some users and some not.
Now I found out why:

I'm creating my data structure like this

$json = json_encode(array('username'=>'myUsername', 'password'=>'myChatAccountPassword', 'gender'=>'male', 'role'=>'user', 
'image'=>base64_encode('https://html5-chat.com/img/malecostume.svg'), 'profile'=>'https://monsite.com/profile/myUserername'));

Than before sending it to the JWT service I have to bas64 encode it.
BUT the bas64 coding also uses the / character. And for some users the Base64 encoded string has a / in it. 

And here the problem begin.
As this created string is part of the URL the JWT service does not get the complete encoded string. 

$encoded = file_get_contents("https://jwt.html5-chat.com/protect/".base64_encode($json));

for Example:
the Base 64 encoded string looks something like "sfeDf/fdsafsaw234"
the JWT URL is:

In this case the JWT service does not return the Token. It returns the follwoing error message

Array
(
    [0] => sfeDf
    [1] => fdsafsaw234
)
Bad count parameter:2

For using base64 encoded strings in a URL there is workaround to replace the / 
like this:

function base64url_encode($data) { 
 return rtrim(strtr(base64_encode($data), '+/', '-_'), '='); 
}

But of course than the JWT service is not working


Does anybody know how to use the JWT service so that it's really working .....
Reply all
Reply to author
Forward
0 new messages