[keycloak-user] Script Mapper can not create json arrays?
Dmitry Telegin
dt at acutus.pro
Mon Nov 26 10:07:02 EST 2018
Hello Jan,
This is how JavaScript arrays get serialized into JSON by default. To overcome it, you should convert it into a Java array first using Java.to(foo, "java.lang.String[]").
Check this out for a complete example of the JavaScript group mapper:
http://lists.jboss.org/pipermail/keycloak-user/2018-November/016223.html
Good luck!
Dmitry Telegin
CTO, Acutus s.r.o.
Keycloak Consulting and Training
Pod lipami street 339/52, 130 00 Prague 3, Czech Republic
+42 (022) 888-30-71
E-mail: info at acutus.pro
On Mon, 2018-11-26 at 14:00 +0000, Lengenfeld, Jan wrote:
> Hello,
>
> we want to add groups and their ids in the following format to the token:
> {
> // ... other values omitted for readability ...
> "userGroups": [
> {
> "id": "b6ebc9af-3355-462b-ab1e-583a24f094aa",
> "name": "my-group"
> },
> {
> "id": "92b0c111-510c-4da9-a978-d980c3893eac",
> "name": "my-other-group"
> }
> ]
> }
>
> But all we get is:
> {
> // ... other values omitted for readability ...
> "userGroups": {
> "0": {
> "id": "b6ebc9af-3355-462b-ab1e-583a24f094aa",
> "name": "my-group"
> },
> "1": {
> "id": "92b0c111-510c-4da9-a978-d980c3893eac",
> "name": "my-other-group"
> }
> }
> }
>
> We are using the Script Mapper with the following code:
>
> var groups = user.groups;
>
> var simplifiedGroupsForToken = [];
>
> for each (var group in groups) {
> simplifiedGroupsForToken.push({"id": group.id, "name": group.name});
> }
> simplifiedGroupsForToken;
>
>
> Do you have any suggestions how to solve our problem? Thanks in advance.
>
> Best regards,
> Jan Lengenfeld
>
> _______________________________________________
> keycloak-user mailing list
> keycloak-user at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/keycloak-user
More information about the keycloak-user
mailing list