-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
types.ts
45 lines (37 loc) · 1.44 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
export type AuthenticationMode = 'json' | 'cookie' | 'session';
export type LoginOptions = {
/** The user's one-time-password (if MFA is enabled). */
otp?: string;
/** Whether to retrieve the refresh token in the JSON response, or in a httpOnly cookie. One of `json`, `cookie` or `session`. Defaults to `cookie`. */
mode?: AuthenticationMode;
/** Use a specific authentication provider (does not work for SSO that relies on browser redirects). */
provider?: string;
};
export interface AuthenticationData {
access_token: string | null;
refresh_token: string | null;
expires: number | null;
expires_at: number | null;
}
export interface AuthenticationStorage {
get: () => Promise<AuthenticationData | null> | AuthenticationData | null;
set: (value: AuthenticationData | null) => Promise<void> | void;
}
export interface AuthenticationConfig {
autoRefresh: boolean;
msRefreshBeforeExpires: number;
credentials?: RequestCredentials;
storage?: AuthenticationStorage;
}
export interface AuthenticationClient<_Schema extends object> {
login(email: string, password: string, options?: LoginOptions): Promise<AuthenticationData>;
refresh(): Promise<AuthenticationData>;
logout(): Promise<void>;
stopRefreshing(): void;
getToken(): Promise<string | null>;
setToken(access_token: string | null): void;
}
export interface StaticTokenClient<_Schema extends object> {
getToken(): Promise<string | null>;
setToken(access_token: string | null): void;
}