A wrapper around the Keycloak javascript adapter using ES6 Promises
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
LICENSE
README.md
keycloak-promise.js

README.md

keycloak-promise.js

Provides a wrapper around the Keycloak javascript adapter using ES6 native Promise objects instead of the homegrown Keycloak promise objects.

Installation

Copy the keycloak-promise.js file into your web root.

Add the keycloak-promise.js script after the Keycloak javascript adapter script in your HTML:

<script type="text/javascript" src="http://localhost:8080/auth/js/keycloak.js"></script>
<script type="text/javascript" src="keycloak-promise.js"></script>

Usage

The KeycloakPromise class provides an interface identical to the Keycloak javascript adapter, except that it returns ES6 native Promise instances whenever the adapter would return a promise. Refer to the Keycloak documentation for details on using the javascript adapter.

Example

The following example shows creating the KeycloakPromise instance, initializing, logging in (if necessary) and then loading the user's profile:

var kcp = new KeycloakPromise();
kcp.init({"onLoad": "check-sso"}).then(function(authenticated) {
    if (!authenticated) {
        return kcp.login();
    }
}).then(function() {
    return kcp.loadUserProfile();
}).then(function(profile) {
    console.log(profile);
    // Do something with profile
}).catch(function(error) {
    console.log(error);
});

Details

The current version of Keycloak as of this writing is 3.3.0.CR1. The KeycloakPromise class was written against the 3.3 version of the Keycloak javascript adapter.