WireMock request query param is empty

45 Views Asked by At

I am trying to configure wiremock but for some reason the request.query.state remain empty. If i change it to {{now}} it will insert the current date so the templating is working.

upStreamIDPMock.stubFor(
    get(urlPathEqualTo("/oauth/authorize")).willReturn(status(302))
        .withServeEventListener(
            "webhook", webhook()
                .withMethod(RequestMethod.GET)
                .withUrl("http://localhost:8082/oidc/callback?code=$code&state={{request.query.state}}")
        )
)
userService.stubFor(get("/callback").willReturn(ok()))

This is my request URL: /oauth/authorizescope=openid+profile+email&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8082%2Foidc%2Fcallback&state=UHq4_t4jedo3-gtO2uPqNGemeWf-au9yceyrKVPLN7Y&nonce=FnioULWSy-Hd4mmlC6o15d_BOg49MJlZzi3on7ts_PQ

This is the response: http://localhost:8082/oidc/callback?code=QxyTZeVACxRxzcJmRB4xQciCApy2aNQsbyDg5-sIU7w&state=

1

There are 1 best solutions below

0
user2340612 On

I debugged it and found out that you need to use originalRequest in the webhook, i.e. .withUrl("http://localhost:8082/oidc/callback?code=$code&state={{originalRequest.query.state}}")

After finding out what the parameter is actually called, I could find a reference in the documentation – I now it's done backwards, but I missed it the first time:

Similarly to response templates the original request data is available, although in this case it is named originalRequest.

If you're curious, it's done here