ngx-keycloak-authz-lib
Version:
Bibliothèque d'authorisation Keycloak pour Angular
113 lines (112 loc) • 4.1 kB
TypeScript
import { HttpClient } from '@angular/common/http';
import { KeycloakAuthzOptions } from '../interfaces/keycloak-authz-options';
import { KeycloakAuthorizationRequest } from '../interfaces/keycloak-authorization-request';
import { KeycloakResourcePermission, KeycloakResourcePermissionsCheck } from '../interfaces/keycloak-permissions';
import * as i0 from "@angular/core";
export declare class KeycloakAuthorizationService {
private http;
private authConfig;
private keycloakConfig;
/**
* Indicates that the permission for the default resource server be loaded at the adapter initialization
*/
private _loadPermissionsInStartup;
/**
* Defines the resource-server of which the permissions are loaded at adpater initialization
*/
private _defaultResourceServerId;
/**
* Contains the RPT-Token after successfull Get-Entitlement-Call
*/
private _rpt;
/**
* Contains all permissions decoded from the RPT-Token after successful Get-Entitlement-Call
*/
private _permissions;
constructor(http: HttpClient);
private newParams;
/**
* Handles the class values initialization.
*
* @param options
*/
private initServiceValues;
/**
* KeycloakAuthorization initialization. It should be called to initialize the adapter.
* Options is a object with 2 main parameters: config and initOptions. The first one
* will be used to connect to Keycloak. The second one are options to initialize the
* keycloak authorization instance.
*
* @param options
* config: an object with the following content:
* - url: Keycloak json URL
* - realm: realm name
* - clientId: client id
*
* initOptions:
* - defaultResourceServerId: specifies the default resource-server
* - loadPermissionsInStartup: if set to true, load all permissions for default resource-server at initializiation of adapter
*
*
*/
init(options: KeycloakAuthzOptions): Promise<unknown>;
/**
* Checks if user has the required access to a resource and/or scope.
*
* @param authorization-check object
* - rsname : Name of the resource
* - scope : name of the scope
*
*
* @returns boolean true if user has access, false if not
*/
checkAuthorization(authorization: KeycloakResourcePermissionsCheck): boolean;
/**
* Internal method to check if user has the required access to a resource and/or scope
*
* @param authorization
*
* @returns boolean true if user has access, false if not
*/
private hasAuthorization;
/**
* Return an array of all permissions present for the logged-in user
*
* @returns Array of permissions
*/
getPermissions(): KeycloakResourcePermission[];
/**
* Gets authorizations for resource-server from keycloak. Also stores the permissions for future use
*
* @param resourceServerId
* The resource server for which the entitlements of the current user are checked
*
* @param authorizationRequest
*
* @returns Authorizations-Object
*/
getAuthorizations(resourceServerId: any, authorizationRequest: KeycloakAuthorizationRequest): Promise<unknown>;
/**
* Gets entitlement fron resource-server from keycloak
*
* @param resourceServerId
* The resource server for which the entitlements of the current user are checked
*
* @param authorizationRequest
*
* @returns Object with RPT-Token containing the authorizations/entitlement
*/
private getEntitlement;
/**
* Decodes RPT-Token
*
* @param str - enoded token string
*
* @returns Decoded jwt-token object
*
*/
private decodeToken;
private handleError;
static ɵfac: i0.ɵɵFactoryDeclaration<KeycloakAuthorizationService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<KeycloakAuthorizationService>;
}