3

I am making a storage provider that federated user from my local database my question I need to set the attributes of my custom user in the returning JWT.

I need to carry the user from customStorageProvider to JWTMapper to map the attributes to JWT

dreamcrash
  • 47,137
  • 25
  • 94
  • 117
David Smith
  • 31
  • 1
  • 3

1 Answers1

3

I am making a storage provider that federated user from my local database my question I need to set the attributes of my custom user in the returning JWT.

I need to carry the user from customStorageProvider to JWTMapper to map the attributes to JWT

That can be achieved with protocol mappers; they can map user-related attributes into the token. To create them via Admin Console, go to your realm:

  • then to clients, and select the client that you will be authenticating against

Afterwards:

(For the OLD Keycloak UI)

  • go to Mappers
  • click on:
    • either Create (right side) to create your mapper
    • or Add Builtin to add a Keycloak's built-in mapper

(For the NEW Keycloak UI)

  • go to the tab Client Scopes
  • click on the client scope <the client ID of your client>-dedicated (e.g., test-dedicated in the picture below)

enter image description here

  • if you have never created a mapper for this client before, click on:

    • either Configure a new mapper to create your mapper
    • or click on Add predefined mapper to add a Keycloak's built-in mapper
  • if you have already created mappers for this client before, click on Add mapper and select:

    • either From predefined mappers to create your mapper
    • By configuration to add a Keycloak's built-in mapper

Those mappers can also be automatically created with the Keycloak Admin REST API. To understand how check this SO answer on "how o create mapper for each user attribute in Keycloak via REST API".

dreamcrash
  • 47,137
  • 25
  • 94
  • 117