-
Notifications
You must be signed in to change notification settings - Fork 5
Using the KeycloakService
Stan Silvert edited this page Feb 5, 2018
·
3 revisions
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.
Just import and add to the constructor of your class.
import { KeycloakService } from './keycloak-service/keycloak.service';
.
.
constructor(private kcSvc: KeycloakService) {}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
client(): KeycloakClientThe KeycloakService does not expose everything you might need for more advanced usage. If you want to use the javascript adapter directly, you can call the client() method:
import { KeycloakService, KeycloakClient } from './keycloak-service/keycloak.service';
...
constructor(private kcSvc: KeycloakService) {
const kcClient:KeycloakClient = kcSvc.client();
this.isPowerUser = kcClient.hasRealmRole('PowerUser');
}For details on using the Keycloak javascript adapter, see the 'Securing Apps' document from Keycloak.