UNPKG

@pvway/alpha-oas

Version:

Alpha OAuth Service by p.v.Way

90 lines (89 loc) 4.07 kB
import { HttpClient } from "@angular/common/http"; import { Observable } from "rxjs"; import { IAlphaAuthEnvelop, IAlphaPrincipal, IAlphaUser } from "./alpha-oas-abstractions"; import * as i0 from "@angular/core"; export declare class AlphaOasService { private mHttp; private readonly mContext; private readonly mPrincipal; private mSignInUrl; private mRefreshUrl; private mGetMeUrl; private mOnPrincipalUpdated; private mPostErrorLog; get principal(): IAlphaPrincipal; constructor(); /** * Initializes the authentication process by retrieving session data, refresh data, or setting authentication to anonymous mode. * * @param httpClient - need to inject the httpClient here * @param {string} [getMeUrl] - The URL for retrieving user information. * @param {string} [refreshUrl] - The URL for refreshing authentication. * @param {string} [signInUrl] - The URL for signing in. * @param {function} [postErrorLog] - A function that handles error logging. * It accepts three parameters: context, method, and error. * @param {function} [onPrincipalUpdated] - A function that will be triggered whenever the principal is updated. * It accepts one parameter: principal of type IAlphaPrincipal. * * @return {Observable} - An Observable that emits the result of the initialization process. */ init(httpClient: HttpClient, getMeUrl?: string, refreshUrl?: string, signInUrl?: string, postErrorLog?: (context: string, method: string, error: string) => any, onPrincipalUpdated?: (principal: IAlphaPrincipal) => any): Observable<string>; private initFromSd; private initFromRd; private initAsAnonymous; /** * Inject your own signIn method */ useSignIn(signIn: (userName: string, password: string, rememberMe: boolean) => Observable<IAlphaAuthEnvelop>): void; /** * Inject your own refresh method */ useRefresh(refresh: (refreshToken: string) => Observable<IAlphaAuthEnvelop>): void; /** Inject your own authorize method */ useAuthorize(authorize: (request: Observable<any>) => Observable<any>): void; internalSignIn: (userName: string, password: string, rememberMe: boolean) => Observable<IAlphaAuthEnvelop>; /** * On successful login call storeIdentity. * Remark: there is no need to call getMe from signIn as getMe * is actually returning the same data as signIn * @param username * @param password * @param rememberMe */ signIn(username: string, password: string, rememberMe: boolean): Observable<boolean>; /** * default implementation of refresh * this implementation can be overridden by calling useRefresh */ internalRefresh: (refreshToken: string) => Observable<IAlphaAuthEnvelop>; /** * refreshes the accessToken from the refreshToken * found in the local storage data */ refresh(): Observable<boolean>; /** * called from the init() method when the session data is present */ getMe(): Observable<IAlphaUser>; editUserInfo(firstName: string, lastName: string, languageCode: string): void; signOut(): void; /** * checks that the accessToken is not expired or * expiring (expirationTime - 1 minute). * if still valid fires the request directly else inserts a * refresh before firing the request */ internalAuthorize(httpRequest: Observable<any>): Observable<any>; /** * checks the accessToken and eventually refreshes it * before calling the request */ authorize(httpRequest: Observable<any>): Observable<any>; /** * (1) stores the access token in the session storage * (2) stores the refresh token in the local storage * (3) populates the principal using the user info */ storeIdentity(authEnvelop: IAlphaAuthEnvelop, rememberMe: boolean): void; private populatePrincipal; static ɵfac: i0.ɵɵFactoryDeclaration<AlphaOasService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<AlphaOasService>; }