Hi,
I'm currently developing a REST API with Ratpack. I have to secure it by integrating with a separate Keycloak server (
http://www.keycloak.org/) via OpenID Connect.
The model I'd like to implement is as follows:
An API client asks Keycloak for an access token it can use to invoke the API on behalf of the user. Keycloak authenticates the user and then asks the user for consent to grant access to the client requesting it. The client receives the access token. This access token is digitally signed by the realm. The client can then make calls to the API with the token. The API extracts the token, verifies its signature with Keycloak and decides whether or not to allow the request.
Keycloak has many adapter libraries but unfortunately Ratpack is not among them. As such I'm investigating Pac4j and the part highlighted in bold above is what I need to implement. I understand that I require a direct client but am unsure how exactly to go about it for OpenID Connect.
The relevant handler section of the the Ratpack app that I'd like to secure is as follows:
prefix('api') {
// Add CORS headers to all api responses
all new CORSHandler()
// Index: list all endpoints
all chain(registry.get(IndexEndpoint))
// Specific endpoints
prefix('users') {
all chain(registry.get(UsersRestEndpoint))
} ...
}
Any pointers/help on how best to do this with Pac4j would be very much appreciated!
Kind regards,
Tom