1

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

1
  • Required JWT client library because I am unable to build the JAR, already see the solution in other post Commented Apr 6, 2021 at 7:56

1 Answer 1

1

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 to JMeter 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:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.