Skip to content

Using the KeycloakService

Stan Silvert edited this page Jan 29, 2018 · 3 revisions

Using the KeycloakService

keycloak-schematic installs an injectable KeycloakService. This is added to your application in exactly the same manner as any other service created with the Angular CLI.

Using in your app

Just import and add to the constructor of your class.

import { KeycloakService } from './keycloak-service/keycloak.service';
.
.
constructor(private kcSvc: KeycloakService) {}

Usage

KeycloakService is a wrapper for the Keycloak javascript adapter. The methods available are as follows:

authenticated(): boolean
login(options?: KeycloakLoginOptions) : void
logout(redirectUri?: string) : void
account(): void
authServerUrl(): string
realm(): string

Using the Keycloak javascript adapter directly

The KeycloakService does not expose everything you might need for more advanced usage. If you want to use the javascript adapter directly, add this to your code:

import * as Keycloak from './keycloak-service/keycloak';
type KeycloakClient = Keycloak.KeycloakInstance;

For details on using the Keycloak javascript adapter, see the 'Securing Apps' document from Keycloak.

Clone this wiki locally