Announcements
This site is in read only until July 22 as we migrate to a new platform; refer to this community post for more details.
Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Apigee JWT Policy Custom Claim Query

What I am Doing:

  • I am generating an array in javascript
  • Serialising it using JSON. Stringify() in javascript
  • Setting that in context in javascript
var myArr= [];

for (var i=0; i<1; i++) {
	var eachElement = {};
        eachElement.Atr1= SourceArray1[i];
        eachElement.Atr2 = SourceArray2[i];
        eachElement.Atr3 = SourceArray3[i];
        eachElement.Attr4 = 'abcd';
        myArr.push(eachElement); 
}

context.serVariable("myArr", JSON.stringify(myArr));
  • Then I am setting myArr as an custom claim in generate JWT Policy
    <CustomClaims>
        <Claim name="myArr" ref="myArr" />
    </CustomClaims>

What I am expecting:

I am expecting to get the following JSON object after decoding the jwt

  "myArr": [
    {
      "Atr1": "abcd",
      "Attr2": "abcd@example.com",
      "Attr3": "+11111111",
      "Attr4": "abcd"
    }
  ] 

What results I am getting:

I am getting following string after decoding the jwt

 "myArr":
"[{\"Attr1\":\"abcd\",\"Attr2\":\"abcd@example.com\",\"Attr3\":\"+11111111\",\"Attr4\":\"abcd\"}]"

Can any one please help me in understanding what I am doing wrong here ?

Solved Solved
1 4 869
1 ACCEPTED SOLUTION

yes - I think what you want is to tell the CustomClaim that it should find a map. So something like this:

    <CustomClaims>
        <Claim name="myArr" ref="myArr" type='map'/>
    </CustomClaims>

Can you try? and LMK ?

View solution in original post

4 REPLIES 4