Hi everyone, I’m working on a WireMock Mapping and...
# help
m
Hi everyone, I’m working on a WireMock Mapping and would be super grateful for some help. The WireMock receives a Request with a JWT as query parameter
code
. I use
serveEventListeners
to trigger a call. This call needs to extract the
sub
claim from the JWT and include it as
user_id
to body. I tried it with the jwt plugin like this
{{jwt path='sub' token=originalRequest.query.code}}
but it generated a new jwt, what is not really what I need. Is there any way to only extract that claim from the token?
Here is the
serveEventListeners
part of my mapping:
Copy code
"serveEventListeners": [
    {
      "name": "webhook",
      "parameters": {
        "method": "POST",
        "url": "<https://example.org/event-listener>",
        "body": "{\"id\": \"{{randomValue type='UUID'}}\", \"user_id\": \"{{jwt path='sub' token=originalRequest.query.code}}\""
      }
    }
  ]
t
It’s fiddly to deconstruct JWTs at the moment, but it can be done:
Copy code
{{#formatJson}}
{{regexExtract request.query.code '(.*?)\.(.*?)\.(.*?)' 'parts'}}
{{val (base64 parts.1 decode=true) assign='jwtBody'}}
{{val (jsonPath jwtBody '$.sub') assign='sub'}}
{
  "user_id": "{{sub}}"
}
{{/formatJson}}
m
Hey Tom, thanks for your help. That worked 👌
🎉 2