[keycloak-user] Script Mapper can not create json arrays?
Lengenfeld, Jan
jan.lengenfeld at gbtec.de
Mon Nov 26 09:00:12 EST 2018
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
More information about the keycloak-user
mailing list