-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
app.ts
44 lines (37 loc) · 1.47 KB
/
app.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
import { App, HttpContext } from "alosaur/mod.ts";
import { AccountArea } from "./areas/account/account.area.ts";
import { HomeArea } from "./areas/home/home.area.ts";
import { AuthMiddleware } from "alosaur/src/security/authorization/src/auth.middleware.ts";
import { CookiesAuthentication } from "alosaur/src/security/authentication/cookies/src/cookies-authentication.ts";
import { SessionMiddleware } from "alosaur/src/security/session/src/session.middleware.ts";
import { MemoryStore } from "alosaur/src/security/session/src/store/memory.store.ts";
import { SecurityContext } from "alosaur/src/security/context/security-context.ts";
import { UseGoogleOAuth } from "../../src/security/oauth/mod.ts";
const DAYS_30 = 30 * 24 * 60 * 60 * 1000;
const app = new App({
areas: [AccountArea, HomeArea],
logging: false,
providers: [{
token: HttpContext,
useClass: SecurityContext,
}],
});
const sessionStore = new MemoryStore();
await sessionStore.init();
const authMiddleware = new AuthMiddleware(
[CookiesAuthentication.DefaultScheme],
);
const sessionMiddleware = new SessionMiddleware(
sessionStore,
{ secret: 1122n, maxAge: DAYS_30, path: "/" },
);
app.use(new RegExp("/"), sessionMiddleware);
app.use(new RegExp("/"), authMiddleware);
UseGoogleOAuth(app, {
hostname: "http://localhost:8000",
clientId: "<your_client_id>",
clientSecret: "<your_client_secret>",
successLoginPath: "/account/external-success",
errorLoginPath: "/account/external-error",
});
app.listen();