2

I have a structure with APIM, IS and Microintegrator. Configured APIM to pass attributes to backend via X-JWT-Assertion header. Now I need to decode this JWT into Json format to use some claims.

I tried it with the function:

<property expression="base64Decode(get-property('JWT_HEADER'))" name="decoded"/> 

but it returns the scrambled data.

enter image description here

Does anyone know how I can do decoding?

Thanks.

1 Answers1

0

A JWT token contains three parts separated by dots (.) as follows [JWT.io]

  • Header
  • Body
  • Signature

If you are trying to access the claims, you have to split the body part and then decode it. Otherwise, it will result in an unreadable format as you have mentioned above.

The following is a sample expression to split and decode the Body of the JWT Token

<property name="assertion" expression="$trp:X-JWT-Assertion" />

<!-- split the body content using substring functions -->
<property name="decoded" expression="base64Decode(fn:substring-before(fn:substring-after($ctx:assertion, '.'), '.'))" />

<log level="custom">
   <property name="decoded-body" expression="$ctx:decoded" />
</log>
Athiththan
  • 1,874
  • 8
  • 18