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

Server config doc for anything but SpringBoot? #71

Closed mohamnag closed 3 years ago

mohamnag commented 3 years ago

I landed here as I was searching for a mock implementation of an OpenID auth server. This project seems promising not only as a Keycloak mock but exactly as a generic OpenID mock. However I can't find any straight forward instruction on how to configure any other server than SpringBoot for using against this mock.

Does your server support OIDC too? if so what is the discovery URL?

PS: fun fact, I'm using vertx on my server side and I just saw that this uses vertx internally!

ostrya commented 3 years ago

When this project was initially created, we thought about supporting generic OpenID functionality. But since the OpenIDConnect standard is pretty vague and e.g. gives no limitation on what to use as an access token, and we really wanted to support Keycloak-style JWT access tokens, we restricted this project to be Keycloak compatible.

As such, the mock supports parts of the OIDC specifications. E.g. auto-configuration is already available, but auto-discovery is currently not supported.

As for how to configure a service to use the mock, this should be done in the same way as you configure it to connect to a regular Keycloak (see https://www.keycloak.org/docs/latest/securing_apps/index.html#openid-connect-3). Though I admit that there is no explicit support for the more modern Microframeworks like vert.x.

But from the documentation, this seems feasible using the Keycloak authentication provider (https://vertx.io/docs/apidocs/io/vertx/ext/auth/oauth2/providers/KeycloakAuth.html) in combination with configuring an authentication handler (https://vertx.io/docs/vertx-web/java/#_authentication_authorization).

Does this help you? Or can you describe in more detail what setup you want to connect to the mock?

mohamnag commented 3 years ago

Thanks for reply. In my case I wanted to have a mock which allows me test my services which are dependent on Auth0 as auth provider. Actually after some short readings of Keycloak docs I managed to connect to your lib and it almost works same as how I have Auth0 configured.

I don't use any vendor specific provider but OpenID for auto config. This allowed me to use your lib as a drop in replacement of Auth0 for my tests. Your access tokens have some additional claims but its safe to ignore them.

So in my case just the proper OIDC endpoint was required (http://localhost:8090/auth/realms/master) and everything worked as I expected.