Skip to content

DominoKit/domino-keycloak

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logoimage

Development Build Status Maven Central Sonatype Nexus (Snapshots) GWT3/J2CL compatible

domino-keycloak

JsInterop wrapper for keycloak

Maven dependency

  • Release
<dependency>
    <groupId>org.dominokit</groupId>
    <artifactId>domino-keycloak</artifactId>
    <version>2.0.0</version>
</dependency>
  • Development snapshot
<dependency>
    <groupId>org.dominokit</groupId>
    <artifactId>domino-keycloak</artifactId>
    <version>HEAD-SNAPSHOT</version>
</dependency>

GWT inherits

<inherits name="org.dominokit.keycloak"/>

Usage

  • Make sure the keycloak.js adapter is loaded in your html page.

    The js file can also be loaded directly from the running keycloak instance under the path [url to your keycloak instance]/js/keycloak.js

  • Create a new keycloak instance There is two ways to create a new key cloak instance:

    • The first by passing a URL that points to the location of our desired client configuration json the json configuration itself can be found in keycloak itself by selecting the desired realm, then select clients then select the target client, then from the action menu select Download adapter config it will show a json that you can copy and put in a file that can be loaded from your application server, once you are ready you can create the keycloak instance as in the following example:
Keycloak KEYCLOAK = Keycloak.create(Keycloak.KeycloakConfigUnionType.of([The url to load the json configuration file]));
  • The second way is by passing a new configuration instance and let keycloak know how to load the json configuration, in this case you need to setup the Keycloak config with the keycloak server url, the realm Id and the client Id, and keycloak will figure out how to load the json configuration from keycloak server instance :
KeycloakConfig config = KeycloakConfig.create([Keycloak server url], [relam Id], [Client Id]);
Keycloak KEYCLOAK = Keycloak.create(Keycloak.KeycloakConfigUnionType.of(config));
  • Use the new created instance
KEYCLOAK.init(initOptions)
        .success(authenticated -> {
            if (authenticated) {
                console.info("User authenticated. :-)");
            } else {
                KEYCLOAK.login(KeycloakLoginOptions.create());
            }
        })
        .error(error -> {
            console.error("Failed to init keycloak.!");
        });