Nerzal / gocloak

golang keycloak client
Apache License 2.0
1.01k stars 275 forks source link

Conditionally Setting Policies Endpoints #469

Open osamaadam opened 5 months ago

osamaadam commented 5 months ago

In Keycloak versions >= 20.0.0. The endpoint to get/create/update the policies has been changed. It no longer includes the /policy-type part.

Similar to https://github.com/Nerzal/gocloak/issues/286, I was facing this issue while running on Keycloak v24.0.1 and I couldn't use the policies endpoints.

So this PR checks the server version and conditionally adds the /policy-type part or omits it. If the Keycloak version is >=20.0.0 the part is omitted. In order to not hit the serverinfo endpoint everytime, I've added the version field to Gocloak.Config so the API would only have to be called once.

I've noticed that the tests on main are already failing so I haven't made any attempt to edit the test cases. Let me know if this will be a blocker. I've tested the policy fetching on v19.0.0 v20.0.0, v24.0.0 and it seems to work as intended in each one of these cases.