Reputation: 11
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
Upvotes: 1
Views: 1508
Reputation: 168002
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 to JMeter 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:
Upvotes: 1