Closed rakesh850gs closed 2 years ago
jwt-cpp doesn't do json serialization itself, instead it delegates this task to a json library. In your case thats picojson. Forward slashes are not a json reserved character so I am a bit surprised it excapes them.
EDIT: I just tried your code and indeed it seems to escape the string. I've never seen a json parser that does not accept this escaped syntax, since according to the Json RFC Any character may be escaped.
, so your json parser is technically not standards compliant. This obviously doesn't solve your issue right now though. You also can't replace it in the resulting token cause then the signature is no longer valid. Going forward I'd recommend opening two issues:
As a hotfix you could try running a different json library for now if you dont use picojson anywhere else.
This is an actual output .
sub = "12345@someorg" aud = ["https:\/\/www.google.com","https:\/\/www.facebook.com"] -- Here it's escaping like "httpsW" exp = 1662663456 iat = 1654023456 iss = "12345@someorg" eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiaHR0cHM6XC9cL3d3dy5nb29nbGUuY29tIiwiaHR0cHM6XC9cL3d3dy5mYWNlYm9vay5jb20iXSwiZXhwIjoxNjYyNjYzNDU2LCJpYXQiOjE2NTQwMjM0NTYsImlzcyI6IjEyMzQ1QHNvbWVvcmciLCJzdWIiOiIxMjM0NUBzb21lb3JnIn0.rWRps6QP7WJuU4IOdC4f9xmrRCaAefWl8HyhHd11AvmIpybBGSHu2e4pEQRTpxKsK1t-SFJ44RHTLmevR0V5VZKv2hup4ZeGP2AvOGKxT6fpIhbjSrGepnDSclXHCMeJvz39oAnUffpobWNPkv9FGD2el-N4vq6Coe1Vn7ITRd6bM_ArgQ33yKdh3I62Wm58jG9ffO7Sn2Shr2eFaexSFNFy2lszaMNoZ2no0qPrcFiXhoST4UIIE8Mzg8DWG1lZrY5WRF7Z9ikEZ9E1m-TaV3yDxDlf3SIV7kb8ULvWhZ9HlDpOXzV7UXlk7GraIukkRzkoCDLxp1ttwkznAuA9LA
See edit above, you where too quick :)
Yeah , Thanks for your response , I shall raise those 2 issues in respective repos and try changing the JSON parser and check .
Thank you :-)
And this library uses PicoJson right ? because the .setAudience method expects a picojson array !!!!
It's a design of picojson https://github.com/kazuho/picojson/pull/26... sadly the author is inactive so we added support for other JSON libraries! For reasons exactly like this
https://github.com/Thalhammer/jwt-cpp#overview has a list of support libraries but you can also check out https://github.com/Thalhammer/jwt-cpp/tree/master/example/traits
You might be interested in using https://github.com/nlohmann/json which is my go to for C++ JSON
I'm trying your suggestion , let me see
Did you have any luck solving your problem?
I followed your answer and I was able to solve the issue , thanks , changing the library , worked . Thanks .
What's your question?
While adding audience in JWT payload , the url FW slashes gets added with escape characters , and server throws "Audience error"
Additional Context
while creating a JWT and decoding it , the forward slashes gets escaped , is that expected behavior ?
OUTPUT
the server with which I'm exchanging this is throwing a audience claim exception , please help .
Thanks