TNG / keycloak-mock

A Java library to test REST endpoints secured by Keycloak via OpenID connect.
Apache License 2.0
120 stars 27 forks source link

Feature/Added support for client_credentials grant type #85

Closed alexisgra closed 3 years ago

alexisgra commented 3 years ago

Hi! This PR integrates the grant type client_credentials to allow to use keycloak-mock to test a service account integration. Service accounts are often used to authenticate (micro)services between them.

Typical use case : I have several services that communicate with each other. Each service is a Keycloak client, I authenticate requests between services via service accounts. I want to test this integration with keycloak-mock.

Keycloak service accounts doc : https://www.keycloak.org/docs/latest/server_admin/index.html#_service_accounts According to the documentation, there is no session created with the grant type client_credentials, nor refresh token returned.

I can add an example in example-backend projet if you want. This is my first open source contribution, I tried to do my best, it's with pleasure that I will take into account your feedback!

Thank you for this super useful lib!

alexisgra commented 3 years ago

@ostrya Thank you for your feedback ! I will make the changes as soon as possible

ostrya commented 3 years ago

One more hint: I have just created #88 where I already added support for basic auth credentials within the token route for password grant flow. It may be best if you rebase to that branch to avoid merge conflicts. You should then be able to access username and password from the routing context using (omitting null checks) ctx.user().get("username") and ctx.user().get("password").

alexisgra commented 3 years ago

@ostrya Thank you! I try to fix your reviews this week!

ostrya commented 3 years ago

Hi @alexisgra, I rebased your changes to the latest master because I want to avoid merge commits. Please check that all required changes are still present and pull the changes on your side.

alexisgra commented 3 years ago

Hi @ostrya ! I'll have a look at it, I had already rebased the PR #88 yesterday, I started the modifications. Thanks

ostrya commented 3 years ago

Hi @alexisgra , are you making progress on the review comments? If not, I can also address the open points myself, as I'd like to merge this and release a new version today.

alexisgra commented 3 years ago

Hi @ostrya, Sorry I have a lot of work to do right now... I can't do the fix today, can I try to do it in the weekend ? I had made a number of changes related to your review. I can push them today if you want.

ostrya commented 3 years ago

It would be great if you could finish the change this weekend. In this case I will wait with the release. Take your time and push the changes when you are ready :)

alexisgra commented 3 years ago

@ostrya Thanks! I do this asap in the weekend

alexisgra commented 3 years ago

Hi @ostrya, I pushed my changes. Let me know if its good, I hope I haven't forgotten anything :)

ostrya commented 3 years ago

Looks good now, thanks for your effort :)