Keycloak: I can't add custom user attribute into the token?

Viewed 199

My users has a birthDate attribute:

enter image description here

I created a mapper in client:

enter image description here enter image description here

Yet it can't be seen in access token:

{
  "exp": 1646589516,
  "iat": 1646589216,
  "jti": "7cee1468-8d80-4f14-a118-b07477c1e1e7",
  "iss": "http://localhost:8080/realms/...",
  "aud": "account",
  "sub": "f:fd2a5a5a-c7a0-4e74-81a8-916a85885f98:...",
  "typ": "Bearer",
  "azp": "...",
  "session_state": "efce7a63-2a8f-438d-b4a1-f5d979a00c81",
  "acr": "1",
  "realm_access": {
    "roles": [
      "offline_access",
      "uma_authorization"
    ]
  },
  "resource_access": {
    "account": {
      "roles": [
        "manage-account",
        "manage-account-links",
        "view-profile"
      ]
    }
  },
  "scope": "openid profile email",
  "sid": "efce7a63-2a8f-438d-b4a1-f5d979a00c81",
  "email_verified": false,
  "preferred_username": "..."
}

Can it happen that the keycloak caching somewhere? (I cleared the caches at Realm --> Caches)

I am desperate... Every tutorial does this and it is not working for me.

Update: I could test it on a server that is remote and it is working. Where the hell the keycloak is caching and screwing me?

---------------------------------------------------------------------------

Update2: deleted the keycloak & reinstalled so start from 0:

  1. created realm: ep

  2. created client: ep 3)

  3. Here we can see the user has an attribute birthDate with value my-custom-birth-date: enter image description here

  4. I go Clients --> ep client --> Mappers and create a mapper like this:

enter image description here

  1. Clients --> ep --> Client Scopes --> Evaluate --> Evaluate button we can see that the birthDate can be found there (last row, also the default birthdate can be seen):

enter image description here

  1. If I evaluate on the user P...o then you can see the access token does not contains the birthDate attribute:

enter image description here

  1. If I use postman to request a token for this user, the access_token looks like this:

enter image description here enter image description here

Still missing the attribute birthDate.

I repeated every action I did above and in the remote keycloak the attribute can be seen (the last one on the image):

enter image description here

---------------------------------------------------------------------------

So I found the problem:

Here is my keycloak folder and the path to it:

enter image description here

I copied the data folder to here thinking I won't need to recreate the realm/client/etc:

enter image description here

Whenever I reinstalled the keycloak, I deleted the keycloak-17.0.0 folder and reinstalled to the same place:

enter image description here

After I deleted both data and keycloak-17.0.0 and recreate the realm/client/mappers/etc, it is working perfectly...

No idea why did the keycloak checked for configurations/settings/caches a folder above in the tree...

0 Answers
Related