keycloak-api-key-demo icon indicating copy to clipboard operation
keycloak-api-key-demo copied to clipboard

Display attribute to user within keycloak

Open Jarvvski opened this issue 3 years ago • 3 comments

If a user visits their account area, they're able to view details about their account:

<domain>/auth/realms/<realm>/account/

image

Is it possible to include the API attribute in here? If so, what steps should I take?

Ideally I'd like to use this instead of a separate service for displaying their API key upon a successful authentication

Jarvvski avatar Mar 08 '21 20:03 Jarvvski

Hi @Jarvvski, apologies for the late reply. Yes, this is absolutely possible. You need to override the keycloak theme, and customize the account page. All you need to do is to add the name of your attribute with and map it to a html input like:

<input  id="user.attributes.my-custom-attribute" name="user.attributes.my-custom-attribute" value="${(account.attributes.my-custom-attribute!'')}" />

where my-custom-attribute is the name of your attribute.

I will try to add an example in the coming days. In the meanwhile, you can take a look at https://www.keycloak.org/docs/latest/server_development/#creating-a-theme https://www.keycloak.org/docs/latest/server_development/#_custom_user_attributes

zak905 avatar May 30 '21 18:05 zak905

example added. Here is the commit for more details: 9d816c5f605a9420d4cc07158ef01245bd09e04c

zak905 avatar May 31 '21 14:05 zak905

Thanks @zak905

I ended up figuring this out in the end, through a lot of trial and error.

Though it's great to keep it here as a reference to anyone else who comes across the same problem!

Jarvvski avatar Jun 12 '21 15:06 Jarvvski