Currently, I am performing performance testing of API and it is required a dynamic JWT token of RSA 256 private key . I didn't find any solution. Can anyone provide me with any JWT jar file and groove code
I believe you will need to go for Groovy scripting for this
Get a JWT client library , for instance this guy will be a good choice and drop it toJMeter Classpath (make sure to include all the dependencies )
Restart JMeter to pick up the.jar
Add JSR223 Sampler to your Test Plan
The example code would be something like:
def keyPayr = io.jsonwebtoken.security.Keys.keyPairFor(io.jsonwebtoken.SignatureAlgorithm.RS256) def now = java.time.Instant.now() def clientId = 'foo' def jwt = io.jsonwebtoken.Jwts.builder().setAudience('https://example.com').setIssuedAt(Date.from(now)).setExpiration(Date.from(now.plus(5L, java.time.temporal.ChronoUnit.MINUTES))).setIssuer(clientId).setSubject(clientId).setId(UUID.randomUUID().toString()).signWith(keyPayr.private).compact() log.info('Token: ' + jwt)
Demo:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.