Add custom key/value to JWT token payload or user with keycloak
Asked Answered
P

1

5

I have keycloak running in localhost. I want to

  • add a key/value pair to the token payload
  • or add a key/value pair related to the user (payload again)

Can you suggest me a way to do this and a way to verify that it has been added?

(I guess with https://jwt.io/)

Pantheas answered 24/5, 2017 at 9:38 Comment(4)
A key/value pair ? What do you mean ? You want to add some payload in the claims of the JWT ? Only the keycloak server can add custom payload, if you do it outside, the signature will become invalid. To add custom claims check this keycloak.gitbooks.io/documentation/content/server_admin/topics/…Thea
Yes, I want to add a key/value pair to the payload of the token, exactly, I am the administrator of the keycloak server so I can do that.Pantheas
Okay, then the solution is explained in the link of my previous comment.Thea
I tried to add a key/value pair in the mappers sections as user attribute and user property. When I copy paste the access token in jwt.io to verify its payload, I do not see my custom key/value pairsPantheas
P
8

As mentioned above by Sébastien, a mapper should be added. So I have added a mapper user attribute and then I went to users->attributes and added the same key name with its value. I verified it afterwards, the key/value pair is included in the payload

Pantheas answered 29/5, 2017 at 8:52 Comment(2)
The doc link in the comment is dead. Is there a current doc/ article about the solution?Eyeleen
what if i want to add list of strings in one keyDarkness

© 2022 - 2024 — McMap. All rights reserved.