@iotize/tap
Version:
IoTize Device client for Javascript
86 lines (85 loc) • 2.87 kB
TypeScript
import '@iotize/tap/service/impl/group';
import { Tap } from '@iotize/tap';
import { BehaviorSubject, Observable } from 'rxjs';
import { AuthMethod, UsernamePassword } from './definitions';
import { ScramAuth } from './scram-auth';
export declare namespace TapAuth {
type SessionData = ScramAuth.SessionData;
interface SessionState {
/**
* User identifier
*/
groupId: number;
/**
* Profile identifier
* If groupId === profileId, it means that user is logged with a profile
*/
profileId: number;
startTime?: Date;
lifeTime: number;
/**
* User name
*/
name: string;
/**
* Profile name (may be same as name if user is logged with a profile)
*/
profileName: string;
}
}
export declare class TapAuth implements AuthMethod<UsernamePassword, TapAuth.SessionData> {
tap: Tap;
protected _sessionState: BehaviorSubject<TapAuth.SessionState>;
protected _sessionData: BehaviorSubject<ScramAuth.SessionData>;
/**
* Get current session state snapshot
*/
get sessionStateSnapshot(): TapAuth.SessionState;
/**
* Listen to session state changed
*/
get sessionState(): Observable<TapAuth.SessionState>;
/**
* Get current session data snapshot
*/
get sessionDataSnapshot(): ScramAuth.SessionData;
/**
* Listen to session data changed
*/
get sessionData(): Observable<ScramAuth.SessionData>;
private _auth?;
private get service();
constructor(tap: Tap);
setAuthMethod(method: AuthMethod<UsernamePassword, TapAuth.SessionData>): void;
/**
* Clear auth cache.
* Usefull for example if Tap configuration has changed
*/
clearCache(): void;
login(params: UsernamePassword, options?: {
noRefreshSessionState?: boolean;
}): Promise<TapAuth.SessionData>;
/**
* Tap logout
* Reject if logout failed
*/
logout(): Promise<void>;
/**
* Read session state from the Tap
* This will perform a few tap requests
*
* TODO we should invalidate encryption key if session state changed
*/
refreshSessionState(defaults?: {
username?: string;
}): Promise<TapAuth.SessionState>;
/**
* Change password for given user. If userIdOrName is not set, it will change password for the currenty
* connected user.
* @param newPassword
* @param userIdOrUndefined user identifier for which password will be change
*/
changePassword(newPassword: string, userIdOrUndefined?: number): Promise<void>;
setupTapAuthEngineIfRequired(): Promise<AuthMethod<UsernamePassword, TapAuth.SessionData>>;
private setupTapAuthEngine;
}