import { RendererFactory2 } from '@angular/core'; import { Observable } from 'rxjs'; import { AuthConfig } from './auth.config'; import { TokenService } from './token.service'; export interface LoginOptions { [key: string]: string; } export interface Credentials { realname: string; username: string; token: string; } export declare class AuthService { private _rendererFactory; private _tokenService; private config; private _credentials; private _loginCallbacks; private _logoutCallbacks; private _timeoutID; private readonly _domain; private readonly _appURL; private readonly _storageUpdater; private readonly _storageRemover; private readonly _commKeyName; private readonly _commKeyUpdater; constructor(_rendererFactory: RendererFactory2, _tokenService: TokenService, config: AuthConfig); isAuthenticated(): Observable; credentials(): Observable; realname(): Observable; username(): Observable; token(): Observable; /** * Functions that opens a window instead of a tab. * * See method _filterLoginOptions regarding security risks of certain * LoginOptions. * * @param loginOptions Options passed as URL parameters to the SSO. * @param width Pixel width of the login window. * @param height Pixel height of the login window. * @param top Position of the top corners. If it is a negative * number it centres the login window on the screen. * @param left Position of the left corners. If it is a negative * number it centres the login window on the screen. */ windowOpen(loginOptions?: LoginOptions, width?: number, height?: number, top?: number, left?: number): void; /** * Functions that opens a tab (in modern browser). * * See method _filterLoginOptions regarding security risks of certain * LoginOptions. * * @param loginOptions Options passed as URL parameters to the SSO. */ tabOpen(loginOptions?: LoginOptions): void; /** * Produces a URL that allows logging into the single sign on (SSO) page. * The URL cans be opened in a new tab using target="_blank", * or in a new window using window.open(). * * See method _filterLoginOptions regarding security risks of certain * LoginOptions. * * @param loginOptions Options passed as URL parameters to the SSO. * * @returns The SSO URL. * */ getSSOURL(options?: LoginOptions): string; /** * Filters options that are unsecure. * * See the advance options that can be requested through the options parameter: * https://api.aai.ebi.ac.uk/docs/authentication/authentication.index.html#_common_attributes * * The time to live paramenter (ttl) default value is 60 minutes. It is a * big security risk to request longer ttl. If a third party gets hold of * such token, means that they could use it for a day, week, year * (essentially, like having the username/password). * * @param loginOptions Options passed as URL parameters to the SSO. * * */ _filterLoginOptions(options: LoginOptions): void; /** * Functions that logs out the user. * It triggers the logout callbacks. * It is an arrow function (lambda) because in that way it has a reference * to 'this' when used in setTimeout call. */ logOut(): void; /** * Add a callback to the LogIn event. * * @param callback The Function called when the login event is triggered and the * JWT token is received and accepted. * * @returns The event registration id (necessary to unregister the event). */ addLogInEventListener(callback: Function): number; /** * Remove a callback from the LogIn event. * * @param id The id given when event listener was added. * * @returns true when remove successfully, false otherwise. */ removeLogInEventListener(id: number): boolean; /** * Add a callback to the LogOut event. * * @param callback The Function called when the logout event is triggered and the * JWT token is received and accepted. * * @returns The registration id (necessary to unregister the event). */ addLogOutEventListener(callback: Function): number; /** * Remove a callback from the LogOut event. * * @param id The id given when event listener was added. * * @returns true when remove successfully, false otherwise. */ removeLogOutEventListener(id: number): boolean; /** * Listen for login messages from other windows. * These messages contain the tokens from the AAP. * If a token is received then the callbacks are triggered. */ private _listenLoginMessage(renderer); /** Listen to changes in the token from *other* windows. * * For inter-window communication messages are transmitted trough changes * on a dummy storage key property: '_commKeyName'. * * Notice that changes in the '_commKeyName' produced by this class doesn't * trigger this event. */ private _listenChangesFromOtherWindows(renderer); /** * Check if the message is coming from the same domain we use to generate * the SSO URL, otherwise it's iffy and shouldn't trust it. */ private messageIsAcceptable(event); private _updateCredentials(); /** * Check if there's a user logging on and whether the token is still valid. * * @returns Whether the user user is authenticated or not. */ private _loggedIn(); private _getToken(); private _getUserName(); private _getRealName(); }