UNPKG

4.57 kBTypeScriptView Raw
1export declare abstract class NbAuthToken {
2 protected payload: any;
3 abstract getValue(): string;
4 abstract isValid(): boolean;
5 abstract getOwnerStrategyName(): string;
6 abstract getCreatedAt(): Date;
7 abstract toString(): string;
8 getName(): string;
9 getPayload(): any;
10}
11export declare class NbAuthTokenNotFoundError extends Error {
12 constructor(message: string);
13}
14export declare class NbAuthIllegalTokenError extends Error {
15 constructor(message: string);
16}
17export declare class NbAuthEmptyTokenError extends NbAuthIllegalTokenError {
18 constructor(message: string);
19}
20export declare class NbAuthIllegalJWTTokenError extends NbAuthIllegalTokenError {
21 constructor(message: string);
22}
23export interface NbAuthRefreshableToken {
24 getRefreshToken(): string;
25 setRefreshToken(refreshToken: string): any;
26}
27export interface NbAuthTokenClass<T = NbAuthToken> {
28 NAME: string;
29 new (raw: any, strategyName: string, expDate?: Date): T;
30}
31export declare function nbAuthCreateToken<T extends NbAuthToken>(tokenClass: NbAuthTokenClass<T>, token: any, ownerStrategyName: string, createdAt?: Date): T;
32export declare function decodeJwtPayload(payload: string): any;
33/**
34 * Wrapper for simple (text) token
35 */
36export declare class NbAuthSimpleToken extends NbAuthToken {
37 protected readonly token: any;
38 protected readonly ownerStrategyName: string;
39 protected createdAt?: Date;
40 static NAME: string;
41 constructor(token: any, ownerStrategyName: string, createdAt?: Date);
42 protected parsePayload(): any;
43 protected prepareCreatedAt(date: Date): Date;
44 /**
45 * Returns the token's creation date
46 * @returns {Date}
47 */
48 getCreatedAt(): Date;
49 /**
50 * Returns the token value
51 * @returns string
52 */
53 getValue(): string;
54 getOwnerStrategyName(): string;
55 /**
56 * Is non empty and valid
57 * @returns {boolean}
58 */
59 isValid(): boolean;
60 /**
61 * Validate value and convert to string, if value is not valid return empty string
62 * @returns {string}
63 */
64 toString(): string;
65}
66/**
67 * Wrapper for JWT token with additional methods.
68 */
69export declare class NbAuthJWTToken extends NbAuthSimpleToken {
70 static NAME: string;
71 /**
72 * for JWT token, the iat (issued at) field of the token payload contains the creation Date
73 */
74 protected prepareCreatedAt(date: Date): Date;
75 /**
76 * Returns payload object
77 * @returns any
78 */
79 protected parsePayload(): void;
80 /**
81 * Returns expiration date
82 * @returns Date
83 */
84 getTokenExpDate(): Date;
85 /**
86 * Is data expired
87 * @returns {boolean}
88 */
89 isValid(): boolean;
90}
91/**
92 * Wrapper for OAuth2 token whose access_token is a JWT Token
93 */
94export declare class NbAuthOAuth2Token extends NbAuthSimpleToken {
95 static NAME: string;
96 constructor(data: {
97 [key: string]: string | number;
98 } | string, ownerStrategyName: string, createdAt?: Date);
99 /**
100 * Returns the token value
101 * @returns string
102 */
103 getValue(): string;
104 /**
105 * Returns the refresh token
106 * @returns string
107 */
108 getRefreshToken(): string;
109 /**
110 * put refreshToken in the token payload
111 * @param refreshToken
112 */
113 setRefreshToken(refreshToken: string): void;
114 /**
115 * Parses token payload
116 * @returns any
117 */
118 protected parsePayload(): void;
119 /**
120 * Returns the token type
121 * @returns string
122 */
123 getType(): string;
124 /**
125 * Is data expired
126 * @returns {boolean}
127 */
128 isValid(): boolean;
129 /**
130 * Returns expiration date
131 * @returns Date
132 */
133 getTokenExpDate(): Date;
134 /**
135 * Convert to string
136 * @returns {string}
137 */
138 toString(): string;
139}
140/**
141 * Wrapper for OAuth2 token embedding JWT tokens
142 */
143export declare class NbAuthOAuth2JWTToken extends NbAuthOAuth2Token {
144 static NAME: string;
145 protected accessTokenPayload: any;
146 protected parsePayload(): void;
147 protected parseAccessTokenPayload(): any;
148 /**
149 * Returns access token payload
150 * @returns any
151 */
152 getAccessTokenPayload(): any;
153 /**
154 * for Oauth2 JWT token, the iat (issued at) field of the access_token payload
155 */
156 protected prepareCreatedAt(date: Date): Date;
157 /**
158 * Is token valid
159 * @returns {boolean}
160 */
161 isValid(): boolean;
162 /**
163 * Returns expiration date :
164 * - exp if set,
165 * - super.getExpDate() otherwise
166 * @returns Date
167 */
168 getTokenExpDate(): Date;
169}