简体   繁体   中英

How to generate JWT token on JMETER using a RSA 256 private key Required library or jar file?

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

  1. 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 )

  2. Restart JMeter to pick up the.jar

  3. Add JSR223 Sampler to your Test Plan

  4. 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM