/
auth.interface.ts
50 lines (42 loc) · 1.21 KB
/
auth.interface.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
46
47
48
49
50
import { SecurityContext } from "../../context/security-context.ts";
export interface AuthClaims {
roles?: string[];
}
export interface AuthenticationScheme {
/**
* This function assign to context identity info, uses in Authorization middleware
*/
authenticate(context: SecurityContext): Promise<void>;
/**
* Create sign identity and assign to context identity info
*/
signInAsync<I, R = any>(
context: SecurityContext,
identity: Identity<I>,
): Promise<R>;
/**
* Clear sign in info and destroy identity context
*/
signOutAsync<T, R>(context: SecurityContext): Promise<R>;
/**
* Uses in Authorize decorators for handle if AuthPayload result failure
*/
onFailureResult(context: SecurityContext): void;
/**
* Uses in Authorize decorators for handle if AuthPayload result success
*/
onSuccessResult(context: SecurityContext): void;
}
export interface Identity<T> {
id: string | number;
data?: T;
readonly roles?: string[];
}
export interface AuthInterface {
identity<T>(): Identity<T> | undefined;
signInAsync<T, R>(
scheme: AuthenticationScheme,
identity: Identity<T>,
): Promise<R>;
signOutAsync<T, R>(scheme: AuthenticationScheme): Promise<R>;
}