I’m having trouble verifying JWT tokens from Atlassian webhook notifications in my Java application. The verification keeps failing and I get this error:
JWT signature does not match locally computed signature. JWT validity cannot be asserted and should not be trusted.
Here’s what I did:
- Set up a webhook endpoint for issue comment events using the REST API at
/rest/api/2/webhook - Configured it with a symmetric key:
"secret": "MyWebhookSecret" - The webhook triggers correctly and I receive events at my endpoint
- The Authorization header contains a JWT token that I’m trying to validate
My validation code looks like this:
public static boolean verifyWebhookToken(String token, String sharedSecret) {
try {
JwtParser parser = Jwts.parser()
.setSigningKey(Keys.hmacShaKeyFor(sharedSecret.getBytes()))
.build();
Jws<Claims> parsedJwt = parser.parseClaimsJws(token);
Claims payload = parsedJwt.getBody();
// Check if token is expired
if (payload.getExpiration().before(new Date())) {
System.out.println("Token expired");
return false;
}
// Verify issuer
String tokenIssuer = payload.getIssuer();
if (!"jira".equals(tokenIssuer)) {
System.out.println("Wrong issuer");
return false;
}
return true;
} catch (Exception ex) {
ex.printStackTrace();
System.out.println(ex.getMessage());
return false;
}
}
The signature verification keeps failing. What could be wrong with my approach?