The example Java code for generating JWTs does not work in all cases | Community
Skip to main content
Question

The example Java code for generating JWTs does not work in all cases

  • December 30, 2025
  • 1 reply
  • 45 views

This seems like the wrong place for this, but Fin sent me, so here goes…

The example Java code shown in Intercom when going through the process to set up JWTs with Messenger does not specify the encoding.  So if your JVM uses something other than UTF-8, the generated JWT will be invalid.

I suggest it should be updated, to call the `.getBytes(StandardCharsets.UTF_8) method on the string to ensure the encoding is always properly handled.

Map<String, Object> claims = new HashMap<>();
claims.put("user_id", userId.toString());
claims.put("email", email);

String token = Jwts.builder()
.setClaims(claims)
.setExpiration(Date.from(Instant.now().plus(24, ChronoUnit.HOURS))) // Expires in 24 hours
.signWith(SignatureAlgorithm.HS256, "<YOUR TOKEN HERE>".getBytes(StandardCharsets.UTF_8)) // Set proper encoding
.compact();

 

1 reply

  • Author
  • New Participant
  • December 30, 2025

If the community forums are not the best place to ask, please recommend a better channel.  Fin insisted this is the place for bug reports/software issues.