Skip to content

Latest commit

 

History

History
43 lines (32 loc) · 1.85 KB

File metadata and controls

43 lines (32 loc) · 1.85 KB

keycloak-jaxrs-client-authfilter

Build Status

This library provides a basic Jaxrs client interceptor that makes accessing keycloak secured services easy.

Quick Start

The simplest way to use the library is to add the following dependency into the build system. i.e.

<dependency>
    <groupId>org.realityforge.keycloak.client.authfilter</groupId>
    <artifactId>keycloak-jaxrs-client-authfilter</artifactId>
    <version>1.04</version>
</dependency>

Then you set up an instance of Keycloak that will be used to authenticate with keycloak. Make sure that the client configured is one that allows log in via password (and not a "bearer-only" client).

final KeycloakConfig config =
  KeycloakConfig.createPasswordConfig( "https://id.example.com", "MyRealm", "MyClient", "MyUser", "MyPass" );
final Keycloak keycloak = new Keycloak( config );

Then ensure that a BearerAuthFilter is attached to jaxrs client setup when accessing secured services. i.e.

final Client client =
  ClientBuilder.newClient().register( new BearerAuthFilter( keycloak ) );
...

Credit

This code was inspired by a post by Thomas Darimont and draws heavily on the admin-client code from the main keycloak project.