[英]How to generate Authorization code in Jmeter with Oauth PKCE flow
I'm trying to generate Authorization code in Jmeter with Oauth PKCE flow could'nt extract code any thoughts here would be helpful.我正在尝试使用 Oauth PKCE 流无法提取代码在 Jmeter 中生成授权代码,这里的任何想法都会有所帮助。
Refer your application documentation as the implementations might be different.请参阅您的应用程序文档,因为实现可能会有所不同。
Some parameters cannot be "extracted", ie you need to know your client_id
beforehand.有些参数不能被“提取”,即你需要事先知道你的
client_id
。
Some parameters needs to be generated, if no documentation is available you can use ie Call Your API Using the Authorization Code Flow with PKCE which contains comprehensive explanation and example code snippets for creating code_verifier
and code_challenge
需要生成一些参数,如果没有可用的文档,您可以使用 ie Call Your API Using the Authorization Code Flow with PKCE ,其中包含用于创建
code_verifier
和code_challenge
的全面说明和示例代码片段
Example code for code_verifier
generation: code_verifier
生成的示例代码:
import java.security.SecureRandom;
SecureRandom sr = new SecureRandom();
byte[] code = new byte[32];
sr.nextBytes(code);
String verifier = Base64.getUrlEncoder().withoutPadding().encodeToString(code);
log.info('code_verifier: ' + verifier)
vars.put('verifier', verifier)
Example code for code_challenge
code_challenge
的示例代码
import java.security.MessageDigest
import org.apache.commons.codec.binary.Base64
byte[] bytes = vars.get('verifier').getBytes("US-ASCII");
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(bytes, 0, bytes.length);
byte[] digest = md.digest();
String challenge = Base64.encodeBase64URLSafeString(digest);
log.info('code_challenge: ' + challenge)
The code can be invoked from theJSR223 Test Elements using Groovy as the language可以使用Groovy作为语言从JSR223 测试元素调用代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.