kilork / keycloak

Keycloak REST API Client
The Unlicense
61 stars 32 forks source link

URL-encoding for Path parameters #124

Open j-hellenberg opened 3 months ago

j-hellenberg commented 3 months ago

Hello, thank you for providing this library!

In our Keycloak instance, we have some roles that contain special characters (like aaa/bbb). I just ran into an issue while trying to query the users associated to such a role with the KeycloakAdmin::realm_roles_with_role_name_users_get method.

Because the generated code constructs URLs using a simple format!, this failed because this resulted in a call to <keycloak_url>/admin/realms/<realm>/roles/aaa/bbb/users, which causes a 404. For this to work, the role_name would need to be URL-encoded, resulting in a URL like <keycloak_url>/admin/realms/<realm>/roles/aaa%2Fbbb/users instead.

Currently, we simply resolve this issue by manually ensuring the parameters are properly encoded when passing them to the library calls. Still, I think it would be nice if the library takes care of proper encoding itself :)

kilork commented 3 months ago

Nice opportunity to practice format_arg! 👍

kilork commented 3 months ago

@j-hellenberg could you please test the branch 124-url-encoding-for-path-parameters from #125 with your application?

j-hellenberg commented 3 months ago

It appears to be working fine now :+1: Now, if I go too crazy with the special characters, it breaks our own application instead, but that is not your fault :grin:

kilork commented 3 months ago

Forgot to mention : this is going to be released as soon as keycloak 26.x would be released. The change here is a breaking change, as there could be a lot of users relying on w/a.

j-hellenberg commented 3 months ago

Ah, that's true, good that you noticed. No worries, our workaround will do for now :)