@mamba-le/auth
Version:
169 lines (168 loc) • 3.86 kB
TypeScript
import jsCookie from 'js-cookie';
import jwtDecode from 'jwt-decode';
import { Subject } from 'rxjs';
export interface IAuthOptions {
/**
* 持久化 Key
* @type {Array<string>}
* @memberof IAuthOptions
*/
StorageKey?: string;
/**
* Cookie Key
* @type {Array<string>}
* @memberof IAuthOptions
*/
CookieKey?: Array<string>;
/**
* Cookie 域名
* @type {Array<string>}
* @memberof IAuthOptions
*/
CookieDomain?: Array<string>;
/**
* Token 类型
* @type {('JWT' | 'Other')}
* @memberof IPortalAuthOptions
*/
TokenType?: 'JWT' | 'Other';
}
export declare class AuthController {
constructor(options?: IAuthOptions);
/**
* 持久化初始化完成 Subject
* @type {Promise<any>}
* @memberof ControllerUser
*/
protected readonly HydrateSubject: Subject<Boolean>;
/**
* 持久化初始化完成 Promise
* @type {Promise<any>}
* @memberof ControllerUser
*/
get HydrateAsync(): Promise<this>;
/**
* 异步 HydrateSubject 已经完成
* @readonly
* @memberof PortalAuthController
*/
get HydrateisStopped(): boolean;
readonly options: IAuthOptions;
get JsCookie(): jsCookie.CookiesStatic<string> & {
noConflict?(): jsCookie.CookiesStatic<string>;
};
get JWTDecode(): typeof jwtDecode;
get IsJWT(): boolean;
/**
* 存储 key
* @readonly
* @memberof AuthController
*/
get StorageKey(): string;
/**
* CookieKey
* @readonly
* @memberof AuthController
*/
get CookieKey(): string[];
/**
* Cookie 站点信息
* @readonly
* @memberof AuthController
*/
get CookieDomain(): string[];
/**
* 所有的 Cookie
* @readonly
* @memberof AuthController
*/
get AllCookieKeys(): string[];
/**
* 重置配置
* @param options
*/
resetConfig(options?: IAuthOptions): void;
/**
* AccessToken
* @protected
* @memberof AuthController
*/
protected _AccessToken: any;
/**
* 最后一次更新 值 HydrateisStopped 未完成前 存储 用于对比变化 default 表示默认无值
* @protected
* @memberof AuthController
*/
protected lastValue: string;
/**
* 提供外部访问的 AccessToken
* @readonly
* @memberof AuthController
*/
get AccessToken(): any;
/**
* 解析后的 JWT
* @readonly
* @type {JWTDecoded}
* @memberof AuthController
*/
get JwtDecoded(): JWTDecoded;
/**
* Cookie 中存储的值
* @readonly
* @private
* @memberof AuthController
*/
private get CookieAccessToken();
/**
* 获取 JWT 解析后数据
* @returns
*/
getDecoded(AccessToken?: any): JWTDecoded;
/**
* 获取 AccessToken
* @returns
*/
getAccessToken(): any;
/**
* 保存 Token
* @param _AccessToken
* @returns
*/
onSaveAccessToken(_AccessToken?: string, setCookie?: boolean): void;
/**
* 清理所有的登录信息
* @return {*}
* @memberof AuthController
*/
onClear(): void;
private onRemove;
/**
* 创建持久化存储
* @memberof BaseModel
*/
protected createHydrate(): Promise<void>;
}
/**
* @docs https://www.jianshu.com/p/d1644e281250
*/
export interface JWTDecoded {
/** @desc 用户 */
aud: string;
/** @desc 主题 */
sub: string;
/** @desc 身份 */
identityId: string;
/** @desc 发行人 */
iss: string;
/** @desc 过期时间 */
exp: number;
expFormat: string;
/** @desc 颁发时间 */
iat: number;
iatFormat: string;
/** @desc 用户名 */
username: string;
/** @desc 过期 */
overdue: boolean;
}