@nibssplc/cams-sdk
Version:
Central Authentication Management Service (CAMS) SDK for popup-based authentication with Azure AD + custom 2FA
48 lines (47 loc) • 1.61 kB
TypeScript
import { CAMSConfig, CAMSError } from "./types";
import { AuthFailureMessage, Profile } from "./validators";
export interface CAMSEvents {
onAuthStart?: () => void;
onAuthSuccess?: (profile: Profile) => void;
onAuthError?: (error: CAMSError) => void;
onTokenExpired?: () => void;
}
export declare class CAMSSessionManager {
private readonly storage;
private readonly keyPrefix;
private readonly events;
private token;
private profile;
constructor(storage?: StorageLike | null, keyPrefix?: string, events?: CAMSEvents);
setItem(key: string, value: string): void;
getItem(key: string): string | null;
removeItem(key: string): void;
clear(): void;
login(config: CAMSConfig): Promise<Profile>;
logout(): Promise<void>;
setToken(token: string): void;
getAccessToken(): string | null;
clearToken(): void;
private isExpired;
isPaddedExpired(): boolean;
private checkTokenExpiration;
isAuthenticated(): boolean;
getProfile(): Promise<Profile | null>;
getSessionError(): AuthFailureMessage | null;
/**
* Complete authentication in popup window
* This should be called by popup apps when authentication is successful
*/
completePopupAuth(profile: Profile, targetOrigin?: string): void;
/**
* Report authentication error in popup window
*/
errorPopupAuth(error: any, targetOrigin?: string): void;
}
interface StorageLike {
getItem(key: string): string | null;
setItem(key: string, value: string): void;
removeItem(key: string): void;
[key: string]: any;
}
export {};