Configuring the keycloak provider

Hello, I need some help.

I’m configuring keycloak, but I identified some problems, but I can debug.

I followed the documentation: Users & Permissions | Strapi Documentation

The first problem I had was that the subdomain always redirected to https, but my environment was not on https, so I had to put my keycloak behind nginx and it solved the problem.

Now I can use the keycloak login, but when I log in to the keycloak I identified a possible problem.

Looking at Strapi’s request logs, the flow that is happening is as follows:

I receive the request and it is redirected:
[2024-08-04 19:13:01.017] http: GET /api/connect/keycloak (24 ms) 302

I receive the request and it is redirected:
[2024-08-04 19:14:54.097] http: GET /api/connect/keycloak/callback?session_state=e763c1ad-249f-4edf-a05d-f66378689e45&iss=https%3A%2F%2Flocalhost%2Frealms%2Fmyrealm&code=mycode (16 ms) 302

I receive the request and it is redirected with error:
[2024-08-04 19:14:54.278] http: GET /api/auth/keycloak/callback?error=connect%20ECONNREFUSED%20%3A%3A1%3A443 (10 ms) 400

What I noticed was that in connect I’m receiving the iss in the wrong format:

it’s coming like this with &, this way I have a page not found in keycloak:
https://localhost/realms/myrealm&code=mycode

the correct one would be with ?, this way I have the correct json in keycloak:
https://localhost/realms/myrealm?code=mycode

I would like to know where I can debug this piece of code, I tried in:
node_modules/@strapi/plugin-users-permissions but without success.

Unfortunately I didn’t find any updated material on how to use keycloack with srtapi.

Thank you for your help.

2 Likes

I found the problem, as my Strapi is inside a Container it does not have access to Keycloak, so the error is because of that, I will create an example repo and I will post it here soon.

1 Like

Hello, I created two articles on how to integrate Keycloak with Strapi and another on how to obtain valid access tokens with Insomnia, as I really didn’t find any updated documentation about it, unfortunately it is in Portuguese, if you want to translate or better translate the flow, feel free. … =)

Setup Keycloak + Strapi:

Setup Insomnia:

2 Likes