zak905 / keycloak-api-key-demo

Demonstration on how to add an API key authentication feature to keycloak
MIT License
110 stars 21 forks source link

Display attribute to user within keycloak #4

Open Jarvvski opened 3 years ago

Jarvvski commented 3 years ago

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

zak905 commented 3 years ago

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 commented 3 years ago

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

Jarvvski commented 3 years ago

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!