Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keycloak user attributes with multiple values (list)

I'm having a Keycloak use case where single user may have multiple customer numbers. These customer numbers would need to be sent to service provider / client and also be easily updated by administrators. Some users may have hundreds of customer numbers. Currently I'm using single user attribute named "customerNumbers" where the customer numbers are separated by comma but I'd like:

  1. To offer the administrators possibility to see each customer number in its own field
  2. To send the customer numbers as an JSON array instead of comma separated claim

So instead of this: enter image description here

I'd like something like this:

enter image description here

And instead of this

"customers": {
"customerNumbers": "140661,140662"
},

I'd like something like this:

"customers": [
    {"customerNumber": "140661"},
    {"customerNumber": "140662"}
],

How should one approach this kind of situation?

like image 744
Jukka Hämäläinen Avatar asked Apr 10 '20 01:04

Jukka Hämäläinen


1 Answers

Keyclaok use a custom format to save multiple value in the same field by separating multiple value with ##

key: customerNumbers      value: 140661##140662

if you want to show that field on your jwt access token you can do it by creating a client scope -> protocol mapper (user attribute) for custom attribute making sure to set multivalued on

set custom attribute on protocol mapper:

set custom attribute on protocol mapper

After that you can add those mapper to your client so it will appear on your access token

set custom attribute on jwt token:

set custom attribute on jwt token

like image 154
alberto.bobice Avatar answered Oct 01 '22 23:10

alberto.bobice