Keycloak retrieve custom attributes to KeycloakPrincipal

前端 未结 2 1639
北海茫月
北海茫月 2020-11-28 21:31

In my rest service i can obtain the principal information after authentication using

KeycloakPrincipal kcPrincipal = (KeycloakPrincipal) servletRequest.getU         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 22:21

    • Select Users > Lookup > click on ID > go to attributes tab > Add attribute > e.g.: phone > Save enter image description here

    • Select Clients > click on Client ID > go to Mappers Tab > create mapper

      enter image description here

      enter image description here

      enter image description here

    • Get custom attributes

      enter image description here

      enter image description here

    UPDATE

    • Add 'phone' attribute on Group level, assign user to that group, and you get 'phone' attribute from group level for all users

    • Go back to mapper and update 'phone' with 'Aggregate attribute values = true' and 'Multivalued=true', and you get 'phone' as list with both attributes from group and user level. If you keep 'Aggregate attribute values = false' or 'Multivalued=false', you get just one value, where 'phone' attribute from user will override 'phone' attribute from group (which make sense)

提交回复
热议问题