Nerzal / gocloak

golang keycloak client
Apache License 2.0
1.03k stars 283 forks source link

Add missing endpoints for client scopes -> scope mappings -> client roles #348

Closed literalplus closed 2 years ago

literalplus commented 2 years ago

Summary: A few endpoints were missing from the client.

Thanks for this useful library! During usage, I noticed that some of the endpoints from the Keycloak Admin API were missing, which I added to a temporary fork & now want to contribute to upstream :)

Namely, the ones where you can assign client roles to a client scope. Realm roles were already implemented, so addition & testing was rather straightforward. The application we're developing requires these endpoints, so I can also confirm that it works in practice. Nevertheless, I added tests for the endpoints to the existing suite.

Reference for API spec: https://www.keycloak.org/docs-api/15.0/rest-api/index.html#_scope_mappings_resource

Regarding the change in the unrelated test: It seems that Keycloak requires the client roles to be passed in the format "client name/role", whereas previously it was only passed as "role". This might be a recent improvement/non-improvement in validation: I noticed that the Keycloak image in docker-compose it set to the "latest" tag. The old version consistently failed on my machine and on GitHub Actions. I confirmed that this seems to be the intended way to do it using this utility method in the Keycloak source. I haven't in detail looked up which commit would have introduced such a change as it didn't seem necessary (but I can check it out if required).

Thank you!

Nerzal commented 2 years ago

Hi! Thank you for the contribution!

Could you please try and update your branch using the current main branch? That should fix the CI Pipeline :)

literalplus commented 2 years ago

Thanks for the hint! I rebased :)

codecov[bot] commented 2 years ago

Codecov Report

Merging #348 (517425d) into main (c740220) will increase coverage by 0.11%. The diff coverage is 85.18%.

@@            Coverage Diff             @@
##             main     #348      +/-   ##
==========================================
+ Coverage   76.85%   76.96%   +0.11%     
==========================================
  Files           4        4              
  Lines        2005     2032      +27     
==========================================
+ Hits         1541     1564      +23     
- Misses        320      322       +2     
- Partials      144      146       +2     
Impacted Files Coverage Δ
client.go 75.32% <85.18%> (+0.14%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c740220...517425d. Read the comment docs.