-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
security.ts
43 lines (34 loc) · 1.07 KB
/
security.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
import { SessionInterface } from "./session/src/session.interface.ts";
import {
AuthenticationScheme,
AuthInterface,
Identity,
} from "./authentication/core/auth.interface.ts";
import { SecurityContext } from "./context/security-context.ts";
const noopIdentity = () => undefined;
export class Security {
public get session(): SessionInterface | undefined {
return this._session;
}
public set session(v: SessionInterface | undefined) {
this._session = v;
}
public readonly auth: AuthInterface;
constructor(context: SecurityContext) {
this.auth = new SecurityAuth(context);
}
private _session?: SessionInterface;
}
class SecurityAuth implements AuthInterface {
constructor(private readonly context: SecurityContext) {}
public identity = noopIdentity;
public async signInAsync<T, R>(
scheme: AuthenticationScheme,
identity: Identity<T>,
) {
return await scheme.signInAsync(this.context, identity);
}
public async signOutAsync<T, R>(scheme: AuthenticationScheme): Promise<R> {
return await scheme.signOutAsync(this.context);
}
}