Help using JWT Policy In Apigee - custom claim as array

We got the JWT policy support in our orgs.

When I am trying to assign an array to our custom claims, the decoded jwt has "\", like

"software_redirect_uris": "[\"https://abcdefgh.com/cb\"]"<br>

Although the in the previous java script policy and in the JWT generate policy, we are able to see proper value in trace:

redirectUrisArray ["https//abcdefgh.com/cb"]

We are doing this in the javascript policy

    redirectUris = "https//abcdefgh.com/cb";
    var redirectUrisArray = redirectUris.split(",");
    context.setVariable("redirectUrisArray", JSON.stringify(redirectUrisArray));

And in the Generate JWT policy, we are doing this:

    <CustomClaims>
        <Claim name="software_redirect_uris" ref="redirectUrisArray"/>
    <CustomClaims>

Any pointer on this ?

Solved Solved
0 6 924
1 ACCEPTED SOLUTION

Please try the following custom claim:

<Claim name="some_arr_claim" type="string" array="true">foo,bar,baz</Claim>

You can switch to using ref for a string variable containing the comma-separated value.

View solution in original post

6 REPLIES 6

Please try the following custom claim:

<Claim name="some_arr_claim" type="string" array="true">foo,bar,baz</Claim>

You can switch to using ref for a string variable containing the comma-separated value.

After using the elements that you specified, it worked for cases, where we had the option to pass as a string.

Hi, I'm sorry you're having trouble.

I don't understand this:

there are cases, where we need to build up the array (and objects) and pass it to the JWT Policy as custom claims.

I don't know what that means.

Also, I see you've shown the output of bunch of test cases, but I don't know what the inputs to those test cases are. You are showing me what you are seeing. but I don't know what you are trying, and what you expect to see.

In general you need to supply this information in questions that you ask:

  • what you are trying. (show relevant code, policy configuration, status of variables)
  • what you expect to see
  • what results you actually are seeing

finally, this seems like a new question. Maybe you should post it as a new question.

Thanks @Dino. Yes, you are right. I should raise a new question.

Hi, what about strings including commas. What needs to be done to add them as array elements?

Can you give an example of what you want to do?

I think that you should be able to do this:

<Claim name="regular_claim" type="string" array="false">foo,bar,baz</Claim>