Skip to content
Advertisement

How do I get a custom field out of the payload using JJWT

OK, I am adding a couple of custom claims to the payload when I generate the JWT, and I can pull those out just fine in my front-end (javascript). I then have my javascript send an ajax call to a micro-service and it passes the JWT along with it. I want to get my custom claims out of the JWT in the micro-service. I’m doing the following:

JavaScript

and it throws an exception.

JavaScript

Here is how the data looks in the JWT inspector on the front-end for my custom claim.

JavaScript

What am I missing to be able to pull my custom claim out?

Advertisement

Answer

OK, so I switched to using Jose4J instead of JJWT and after working to get every thing working I realized I probably could have done something similar with JJWT. So what I ended up doing was to use Gson to perform a JSON encoding of the Object and the attaching the resulting JSON string as a claim. And so when I wanted to get a custom claim back out, I would extract the claim as a string and the use the Gson library to convert it back to a POJO.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement