User IP inside JWT

Hello, community.

How I can get user IP inside JWT?

I have a task to extend JWT by custom fields. The most confusing field displays user IP inside the payload. I do it through admin REST inside OIDC. After get JWT I going inside a keycloak, catch user IP by session. Then insert it inside the session. But it looks like a bad decision.

Please advise me on how I can do it highly correctly. If I should change source code, every advice will be best.

Thank u

How I catch IP:
url --location --request GET ‘http://0.0.0.0:8080/auth/admin/realms/master/users/64f225e2-2d1e-4a00-a2aa-d96bcc93f395/sessions’ --header ‘Authorization: bearer’ | | jq ‘.[0].ipAddress’

Hello, I have a similar requirement, did you ever figure out another way of passing IP into the JWT?

You could create a custom even listener and add the ip address on a login event as a user attribute.
An example can be found on https://github.com/zonaut/keycloak-extensions/tree/master/spi-event-listener