[英]Generate a JWT token on jmeter using an RSA-256 private key
So the thing is I want to run some test cases on jmeter that require a jwt authorization.所以问题是我想在 jmeter 上运行一些需要 jwt 授权的测试用例。 That jwt must be generated using a private key (RSA-256).
必须使用私钥 (RSA-256) 生成 jwt。
Is there any way I can do this on jMeter?有什么办法可以在 jMeter 上做到这一点?
You can do it using:您可以使用:
Example approach assuming having JJWT library with dependencies inJMeter Classpath示例方法假设在 JMeter 类路径中具有依赖关系的JJWT库
def generator = java.security.KeyPairGenerator.getInstance("RSA");
generator.initialize(2048, new java.security.SecureRandom())
def keyPayr = generator.generateKeyPair()
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.