Reputation: 308
I am using Keycloak for authentication.
I used the user id in the access token as a user identity and stored it in some tables when users did some actions. I have some counters relying on user-id.
But recently, I found that the Keycloak user id is dynamic and it is changed after some time(I am not sure how long a user-id is kept) that making my counters counted improperly.
So I wonder is there a way that we set the user id static? And how can I get the user email from the user-id that had been changed in the past?
I am really appreciated your help and suggestions. Thank you so much.
Upvotes: 1
Views: 981
Reputation: 308
Answer: it was my mistake. I used two accounts with the same username and different email IDs. When I ran the query with username filter, it returned 2 user id. That's why I think the user id generated by Keycloak is dynamic.
Confirm again: the user-id is fixed.
Upvotes: 1
Reputation: 51453
I am not 100 % sure about:
But recently, I found that the Keycloak user id is dynamic and it is changed after some time( I am not sure how long a user-id is kept) that making my counters counted improperly.
You can use the claim sub
in combination with a public subject identifier types. Have a look a this answer for a more detailed explanation.
Upvotes: 2