简体   繁体   English

如何使用 RSA 256 私钥所需的库或 jar 文件在 JMETER 上生成 JWT 令牌?

[英]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 .目前,我正在对 API 进行性能测试,它需要RSA 256 private key的动态 JWT 令牌。 I didn't find any solution.我没有找到任何解决方案。 Can anyone provide me with any JWT jar file and groove code谁能给我提供任何 JWT jar 文件和凹槽代码

I believe you will need to go for Groovy scripting for this我相信您将需要 go 来为此编写Groovy脚本

  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 )获取一个JWT 客户端库,例如这个家伙将是一个不错的选择并将其放到JMeter 类路径(确保包含所有依赖项)

  2. Restart JMeter to pick up the.jar重启JMeter 捡起.jar

  3. Add JSR223 Sampler to your Test PlanJSR223 采样器添加到您的测试计划中

  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:演示:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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