Hi, wondering if I really need a JavaScript policy for what I’m doing. I’m taking some claims from one JWT and put them into another, but having issues with claims that are an array.
So, my first attempt was to use the outputs from DecodeJWT to pass the “roles” claim across to a GenerateJWT policy and create the new JWT:
<GenerateJWT name="CreateNewJwt">
<!-- other settings omitted for brevity -->
<AdditionalClaims>
<Claim name="roles" array="true" ref="jwt.GetClaims.decoded.claim.roles" />
</AdditionalClaims>
<OutputVariable>my-new-token</OutputVariable>
</GenerateJWT>
However, it seems that even though DecodeJWT outputs the array in JSON notation, GenerateJWT expects the array to be provided as a comma separate list with no quotes. i.e.
DecodeJWT outputs the roles claim as: [“role1”,“role2”]
GenerateJWT needs me to pass it as: role,role2
In the end I got it working with a JavaScript policy in between the two, but it feels strange that I need to do that… am I missing something in the docs?
If you happen to need to use XML-sensitive characters in your JS, like ampersand (&) or angle brackets, then you need to embed the contents of the Source into a cdata section, like so: