how to get the Map from claims during parsing?
See original GitHub issueI have set-up custom claims as map during jwt generation. when decoding jwt, I want to retrieve the map.
I am trying to do this;
Jws<Claims> jwsClaims = Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token);
Claims claims = jwsClaims.getBody();
how to get Map<String,Object>
from claims?
This is how I set custom claims
Jwts.builder()
.setClaims(getMapFromResponseObject(myObj))
.setIssuedAt(now)
.setExpiration(expiration)
.setIssuer(ISSUER)
.signWith(SignatureAlgorithm.HS512, secretKey)
.compact();
private Map<String,Object> getMapFromResponseObject(MyObject myObj){
ObjectMapper m = new ObjectMapper();
Map<String,Object> props = m.convertValue(myObj, Map.class);
return props;
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
How to convert from io.jsonwebtoken.Claims to java.util.Map ...
I am able to create a JWT token with custom payloads successfully. Now while i am going to parse it, I need Map<String,...
Read more >Go Notes: Parsing Claims in Firebase JWT Token
I struggled to parse the Firebase JWT Claims. Because claims may contain strings, maps, and arrays, the claims field type is an []interface{}....
Read more >Spring Security – Map Authorities from JWT | Baeldung
In this tutorial, we'll show how to customize the mapping from JWT (JSON Web Token) claims into Spring Security's Authorities.
Read more >Parsing and producing JSON - Apache Groovy
It parses a JSON String and recursively converts it to a list or map of objects. The other parse* methods are similar in...
Read more >JOSE object / JSON Web Token (JWT) parsing - Connect2id
Parsing JOSE objects or JWTs of a certain expected type (plain, ... e) { // Invalid plain JWT encoding } // continue with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As @dogeared said just use
JwtBuilder#claim
method :The JSON representation will be:
When you deserialize the Jwt body, just get “myPrivateClaimKey”:
Does it make sense?
Just as I cited above.
now when I parse, I would like to get back the map which i set as claims i.e
Map<String,String> map = (Map<String,String>) claims;
The claims by itself contains expiration, iss, subject etc which I do not want. Just the map which I set as claims. The reason I ask this, I have a mapper which coverts this map to java object and vice-versa.