Passing the regex variables in query param

Hello All,

Iam able to extract ’ code_extract’ from previous Request’s Response Header when Iam passing the same in the Next Request using .formParam then it is not passing.

… here are two requests:

Request1:

.exec(http(" req_1 “)
.get(“XXX/client_id=0oarh5q6vo6DMA9wK0h7&code_challenge=wrdfsf4244324&code_challenge_method=S256&display=page&nonce=J53d8opQzIR3HaaTzOwi079TiFeaKeTu5UYSldY5119fwxgah6cQ5SldD4Tfb5K5&redirect_uri=XXXXX%2Fweb%2Fastd%2Fanalytics-studio%2Fcallback&response_type=code&sessionToken=${ session_token }&state=Y8cJFzxt7jzs96xyzOfy4dQTYwlM4M8rH3G5JKvd82HqLjW7kuOaaGUIuojoVMpl&scope=openid+profile+email+intient+groups”)
.disableFollowRedirect
.headers(headers_4)
.check(headerRegex(“location”, “code=(.*?)\&state”).saveAs(” code_extract "))
.check(status.is(302))

Request2:

.exec(http(" req_2 ")
.post(“https://intient-dev.oktapreview.com/oauth2/ausreq4bhcWPvQgkV0h7/v1/token”)
.headers(headers_6)
.formParam(“grant_type”, “authorization_code”)
.formParam(“code”, “${ code_extract }”)
.formParam(“code_verifier”, “fgfdge55764563”)
.formParam(“redirect_uri”, “XXXX”)
.formParam(“client_id”, “0oarh5q6vo6DMA9wK0h7”)
)

how to pass the regex variable in .formParam

.check(headerRegex(“location”, “code=(.*?)\&state”).saveAs(” code_extract "))

This is wrong. You should be using a currentLocationRegex check instead.

Hi,
I have given like you said
.check(currentLocationRegex(“code=(.*?)\&state”).saveAs(“code_extract”))

but I got error like below:
“Request_04: KO currentLocationRegex(code=(.*?)&state).find.exists, found nothing”

Below Iam sending the req and response details where Iam facing issue:

Request01 :

.exec(http(“token_01”) .get(“xxxxxx.com - xxx sex videos free hd porn Resources and Information.”)

.disableFollowRedirect

.headers(headers_4)

.check(headerRegex(“location”, “code=(.*?)[\&state”).saveAs(“code_extract”)](file://&state%22).saveAs(%22code_extract%22)))

.check(currentLocationRegex(code=(.*?)&state). .saveAs(“code_ extract”))

.check(status.is(302)) )

Response details of above Request01:

Response Headers:

Connection: keep-alive
Server: nginx
x-okta-request-id: YoXLpRXqMFcm1vfphJz8VAAADT8
x-xss-protection: 0
p3p: CP=“HONK”
x-rate-limit-limit: 60
x-rate-limit-remaining: 59
referrer-policy: no-referrer
cache-control: no-cache, no-store
pragma: no-cache
expires: 0
location: https://XXXXXX/web/astd/analytics-studio/callback? code=d7bPlbfSgs_X-7SC2hM4797xiVg82B5G6ZU_ScrCGy4&state =Y8cJFzxt7jzs96xyzOfy4dQTYwlM4M8rH3G5JKvd82HqLjW7kuOaaGUIuojoVMpl
content-language: en
Strict-Transport-Security: max-age=315360000; includeSubDomains

In below request I was trying to pass that ‘code_extract’ using .formParam but it is not passing,

Request02:

.exec(http(“token_02”)
.post(“https://XXXXX/oauth2/ausreq4bhcWPvQgkV0h7/v1/token”)
.headers(headers_6)
.formParam(“grant_type”, “authorization_code”)
.formParam(“code”, “${code_extract}”)
.formParam(“code_verifier”, “950ca0a06bdsfst34598340dosjfb030fc2d5c”)
.formParam(“redirect_uri”, “https:://XXXXXX.com/web/astd/analytics-studio/callback”)
.formParam(“client_id”, “8345ajdfjskd99u”))

can you help me how to do it?

Remove this .disableFollowRedirect and use currentLocationRegex as I said.
You shouldn’t be aware of the redirects, just like any JavaScript code in your browser.