@ebondu/angular2-keycloak
Version:
374 lines (358 loc) • 12.2 kB
TypeScript
import * as i0 from '@angular/core';
import { InjectionToken } from '@angular/core';
import * as _ebondu_angular2_keycloak from '@ebondu/angular2-keycloak';
import { HttpClient, HttpInterceptorFn } from '@angular/common/http';
import { Observable } from 'rxjs';
declare class AngularKeycloakService {
constructor();
static ɵfac: i0.ɵɵFactoryDeclaration<AngularKeycloakService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<AngularKeycloakService>;
}
declare class AngularKeycloakModule {
static ɵfac: i0.ɵɵFactoryDeclaration<AngularKeycloakModule, never>;
static ɵmod: i0.ɵɵNgModuleDeclaration<AngularKeycloakModule, never, never, never>;
static ɵinj: i0.ɵɵInjectorDeclaration<AngularKeycloakModule>;
}
declare const KEYCLOAK_JSON_PATH: InjectionToken<string>;
declare const KEYCLOAK_INIT_OPTIONS: InjectionToken<KeycloakInitOptions>;
declare const KEYCLOAK_CONF: InjectionToken<KeycloakConfiguration>;
declare enum KeycloakAdapterName {
CORDOVA = "cordova",
DEFAULT = "default",
ANY = "any"
}
declare enum KeycloakOnLoad {
LOGIN_REQUIRED = "login-required",
CHECK_SSO = "check-sso"
}
declare enum KeycloakResponseMode {
QUERY = "query",
FRAGMENT = "fragment"
}
declare enum KeycloakResponseType {
CODE = "code",
ID_TOKEN = "id_token token",
CODE_ID_TOKEN = "code id_token token"
}
declare enum KeycloakFlow {
STANDARD = "standard",
IMPLICIT = "implicit",
HYBRID = "hybrid"
}
declare enum LogoutMethod {
POST = "post",
GET = "get"
}
interface KeycloakInitOptions {
useNonce?: boolean;
/**
* Allows to use different adapter:
*
* - {string} default - using browser api for redirects
* - {string} cordova - using cordova plugins
* - {function} - allows to provide custom function as adapter.
*/
adapter?: KeycloakAdapterName;
/**
* Specifies an action to do on load.
*/
onLoad?: KeycloakOnLoad;
/**
* Set an initial value for the token.
*/
token?: string;
/**
* Set an initial value for the refresh token.
*/
refreshToken?: string;
/**
* Set an initial value for the id token (only together with `token` or
* `refreshToken`).
*/
idToken?: string;
/**
* Set an initial value for skew between local time and Keycloak server in
* seconds (only together with `token` or `refreshToken`).
*/
timeSkew?: number;
/**
* Set to enable/disable monitoring login state.
* @default true
*/
checkLoginIframe?: boolean;
/**
* Set the interval to check login state (in seconds).
* @default 5
*/
checkLoginIframeInterval?: number;
/**
* Set the redirect uri to silent check login state.
*/
silentCheckSsoRedirectUri?: string;
silentCheckSsoFallback?: boolean;
/**
* Set the OpenID Connect response mode to send to Keycloak upon login.
* @default fragment After successful authentication Keycloak will redirect
* to JavaScript application with OpenID Connect parameters
* added in URL fragment. This is generally safer and
* recommended over query.
*/
responseMode?: KeycloakResponseMode;
/**
* Set the OpenID Connect flow.
* @default standard
*/
flow?: KeycloakFlow;
pkceMethod?: string;
logoutMethod?: LogoutMethod;
scope?: string;
}
interface KeycloakLoginOptions {
/**
* Undocumented.
*/
scope?: string;
/**
* Specifies the uri to redirect to after login.
*/
redirectUri?: string;
/**
* By default the login screen is displayed if the user is not logged into
* Keycloak. To only authenticate to the application if the user is already
* logged in and not display the login page if the user is not logged in, set
* this option to `'none'`. To always require re-authentication and ignore
* SSO, set this option to `'login'`.
*/
prompt?: 'none' | 'login';
/**
* If value is `'register'` then user is redirected to registration page,
* otherwise to login page.
*/
action?: 'register';
/**
* Used just if user is already authenticated. Specifies maximum time since
* the authentication of user happened. If user is already authenticated for
* longer time than `'maxAge'`, the SSO is ignored and he will need to
* authenticate again.
*/
maxAge?: number;
/**
* Used to pre-fill the username/email field on the login form.
*/
loginHint?: string;
/**
* Used to tell Keycloak which IDP the user wants to authenticate with.
*/
idpHint?: string;
/**
* Sets the 'ui_locales' query param in compliance with section 3.1.2.1
* of the OIDC 1.0 specification.
*/
locale?: string;
/**
* Specifies the desired Keycloak locale for the UI. This differs from
* the locale param in that it tells the Keycloak server to set a cookie and update
* the user's profile to a new preferred locale.
*/
kcLocale?: string;
}
interface KeycloakConfiguration {
realm: string;
authServerUrl: string;
clientId: string;
clientSecret?: string;
}
/**
* Keycloak core classes to manage tokens with a keycloak server.
*
* Used for login, logout, register, account management, profile.
* Provide Angular Observable objects for initialization, authentication, token expiration.
*
*/
declare class KeycloakService {
#private;
initializedObs: Observable<boolean>;
initializedAuthzObs: Observable<boolean>;
authenticationObs: Observable<boolean>;
tokenExpiredObs: Observable<boolean>;
authenticationErrorObs: Observable<any>;
accessToken: string;
tokenParsed: any;
sessionId: any;
private initBS;
private initAuthzBS;
private authenticationsBS;
private tokenExpiredBS;
private authenticationErrorBS;
private refreshToken;
private refreshTokenParsed;
private rpt;
private idToken;
private idTokenParsed;
private umaConfig;
private adapter;
private callbackStorage;
private responseType;
private timeSkew;
private tokenTimeoutHandle;
private subject;
private realmAccess;
private resourceAccess;
private loginIframe;
keycloakConfig: _ebondu_angular2_keycloak.KeycloakConfiguration;
readonly initOptions: _ebondu_angular2_keycloak.KeycloakInitOptions;
get http(): HttpClient;
constructor();
parseCallback(url: string): any;
processCallback(oauth: any): Observable<boolean>;
login(options: any): any;
logout(options: any): any;
updateToken(minValidity: number): Observable<string>;
register(options: any): any;
accountManagement(options: any): any;
loadChangePassword(options: any): any;
loadUserProfile(): Observable<any>;
updateUserProfile(profile: any): Observable<any>;
createDeleteAccountUrl(options?: any): string;
createUpdateProfileUrl(options?: any): string;
changePassword(): string;
loadUserInfo(): Observable<any>;
hasRealmRole(role: string): boolean;
hasResourceRole(role: string, resource: string): boolean;
isTokenExpired(minValidity: number): boolean;
isRefreshTokenExpired(minValidity: number): boolean;
/**
* This method enables client applications to better integrate with resource servers protected by a Keycloak
* policy enforcer.
*
* In this case, the resource server will respond with a 401 status code and a WWW-Authenticate header holding the
* necessary information to ask a Keycloak server for authorization data using both UMA and Entitlement protocol,
* depending on how the policy enforcer at the resource server was configured.
*/
authorize(wwwAuthenticateHeader: string): Observable<string>;
/**
* Obtains all entitlements from a Keycloak Server based on a give resourceServerId.
*/
entitlement(resourceServerId: string): Observable<boolean>;
clearToken(initOptions: any): void;
createLoginUrl(options: any): string;
createLogoutUrl(options: any): string;
createRegisterUrl(options: any): string;
createAccountUrl(options: any): string;
createChangePasswordUrl(options: any): string;
getRealmUrl(): string;
private initService;
private processAuthz;
private authSuccess;
private setToken;
static ɵfac: i0.ɵɵFactoryDeclaration<KeycloakService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<KeycloakService>;
}
declare const keycloakInterceptor: HttpInterceptorFn;
/**
* Cordova adapter for hybrid apps.
*/
declare class CordovaAdapter {
private keycloak;
constructor(keycloak: KeycloakService);
login(options: any): void;
closeBrowserTab(): void;
logout(options: any): void;
register(options: any): void;
accountManagement(options: any): void;
passwordManagement(options: any): void;
redirectUri(options: any): any;
private openBrowserTab;
}
/**
* Default adapter for web browsers
*/
declare class DefaultAdapter {
private keycloak;
constructor(keycloak: KeycloakService);
login(options: any): void;
logout(options: any): void;
register(options: any): void;
accountManagement(): void;
passwordManagement(): void;
redirectUri(options: any, encodeHash: boolean): string;
}
/**
* To store Keycloak objects like tokens using a cookie.
*/
declare class CookieStorage {
getCookie: (key: any) => string;
get(state: string): any;
add(state: any): void;
removeItem(key: any): void;
cookieExpiration(minutes: number): Date;
setCookie(key: string, value: string, expirationDate: Date): void;
}
/**
* To store Keycloak objects like tokens using a localStorage.
*/
declare class LocalStorage {
clearExpired(): void;
get(state: string): string;
add(state: any): void;
}
/**
* Check login Iframe utility
*/
declare class KeycloakCheckLoginIframe {
private keycloak;
private iframe;
private interval;
private iframeSrc;
constructor(keycloak: KeycloakService, checkInterval: number);
initIframe(): void;
private checkIframe;
private processCallbackMessage;
}
/**
* Silent login check Iframe utility
*/
declare class KeycloakSilentCheckLoginIframe {
private keycloak;
private iframe;
private iframeSrc;
constructor(keycloak: KeycloakService, silentRedirectUri: string);
initIframe(): void;
private processSilentLoginCallbackMessage;
}
/**
* 3Party cookie Iframe utility
*/
declare class KeycloakCheck3pCookiesIframe {
private keycloak;
private iframe;
private interval;
private iframeSrc;
private supportedBS;
supportedObs: Observable<boolean>;
constructor(keycloak: KeycloakService);
initIframe(): void;
private process3pCookieCallbackMessage;
}
declare class Token {
static decodeToken(str: string): string;
static generateRandomData(len: any): any;
static generateCodeVerifier(len: any): any;
static generateRandomString(len: any, alphabet: any): any;
static generatePkceChallenge(pkceMethod: any, codeVerifier: any): string;
}
/**
* URI parser.
*/
declare class URIParser {
static initialParse(uriToParse: string, responseMode: string): {
baseUri: string;
queryString: string;
fragmentString: string;
};
static parseParams(paramString: string): any;
static handleQueryParam(paramName: string, paramValue: string, oauth: any): boolean;
static parseUri(uriToParse: string, responseMode: string): any;
}
export { AngularKeycloakModule, AngularKeycloakService, CookieStorage, CordovaAdapter, DefaultAdapter, KEYCLOAK_CONF, KEYCLOAK_INIT_OPTIONS, KEYCLOAK_JSON_PATH, KeycloakAdapterName, KeycloakCheck3pCookiesIframe, KeycloakCheckLoginIframe, KeycloakFlow, KeycloakOnLoad, KeycloakResponseMode, KeycloakResponseType, KeycloakService, KeycloakSilentCheckLoginIframe, LocalStorage, LogoutMethod, Token, URIParser, keycloakInterceptor };
export type { KeycloakConfiguration, KeycloakInitOptions, KeycloakLoginOptions };