authenik8-core 1.0.3 → 1.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/auth/guestModeService.d.ts +4 -1
- package/dist/auth/guestModeService.d.ts.map +1 -1
- package/dist/auth/guestModeService.js +31 -20
- package/dist/auth/guestModeService.js.map +1 -1
- package/dist/auth/jwtAuth.d.ts +2 -1
- package/dist/auth/jwtAuth.d.ts.map +1 -1
- package/dist/auth/jwtAuth.js +26 -8
- package/dist/auth/jwtAuth.js.map +1 -1
- package/dist/auth/refreshService.d.ts +2 -0
- package/dist/auth/refreshService.d.ts.map +1 -1
- package/dist/auth/refreshService.js +12 -5
- package/dist/auth/refreshService.js.map +1 -1
- package/dist/createAuthenik8.d.ts.map +1 -1
- package/dist/createAuthenik8.js +31 -13
- package/dist/createAuthenik8.js.map +1 -1
- package/dist/middleware/adminService.d.ts +1 -1
- package/dist/middleware/adminService.d.ts.map +1 -1
- package/dist/middleware/adminService.js +6 -10
- package/dist/middleware/adminService.js.map +1 -1
- package/dist/oauth/adapters/redisAdapter.d.ts +23 -0
- package/dist/oauth/adapters/redisAdapter.d.ts.map +1 -0
- package/dist/oauth/adapters/redisAdapter.js +116 -0
- package/dist/oauth/adapters/redisAdapter.js.map +1 -0
- package/dist/oauth/brain/identityEngine.d.ts.map +1 -1
- package/dist/oauth/brain/identityEngine.js +26 -7
- package/dist/oauth/brain/identityEngine.js.map +1 -1
- package/dist/oauth/identity/types.d.ts +6 -1
- package/dist/oauth/identity/types.d.ts.map +1 -1
- package/dist/oauth/providers/github.d.ts.map +1 -1
- package/dist/oauth/providers/github.js +6 -7
- package/dist/oauth/providers/github.js.map +1 -1
- package/dist/oauth/providers/google.d.ts.map +1 -1
- package/dist/oauth/providers/google.js +3 -28
- package/dist/oauth/providers/google.js.map +1 -1
- package/dist/oauth/types.d.ts +1 -0
- package/dist/oauth/types.d.ts.map +1 -1
- package/dist/redis/redisService.js +7 -8
- package/dist/redis/redisService.js.map +1 -1
- package/dist/security/ipService.d.ts +3 -0
- package/dist/security/ipService.d.ts.map +1 -1
- package/dist/security/ipService.js +30 -9
- package/dist/security/ipService.js.map +1 -1
- package/dist/security/limiter.d.ts +12 -1
- package/dist/security/limiter.d.ts.map +1 -1
- package/dist/security/limiter.js +29 -10
- package/dist/security/limiter.js.map +1 -1
- package/dist/storage/RedisTokenStore.d.ts.map +1 -1
- package/dist/storage/RedisTokenStore.js +3 -2
- package/dist/storage/RedisTokenStore.js.map +1 -1
- package/dist/storage/userStorage.js +1 -2
- package/dist/storage/userStorage.js.map +1 -1
- package/dist/types/config.d.ts +3 -0
- package/dist/types/config.d.ts.map +1 -1
- package/package.json +23 -13
- package/dump.rdb +0 -0
- package/jest.config.js +0 -11
- package/src/auth/guestModeService.ts +0 -31
- package/src/auth/jwtAuth.ts +0 -99
- package/src/auth/refreshService.ts +0 -157
- package/src/createAuthenik8.ts +0 -135
- package/src/dump.rdb +0 -0
- package/src/index.ts +0 -2
- package/src/middleware/adminService.ts +0 -50
- package/src/oauth/adapters/memoryAdapter.ts +0 -74
- package/src/oauth/brain/identityEngine.ts +0 -141
- package/src/oauth/brain/identityPolicy.ts +0 -4
- package/src/oauth/brain/identityResolver.ts +0 -43
- package/src/oauth/brain/types.ts +0 -9
- package/src/oauth/core.ts +0 -19
- package/src/oauth/identity/1 +0 -44
- package/src/oauth/identity/types.ts +0 -44
- package/src/oauth/providers/github.ts +0 -154
- package/src/oauth/providers/google.ts +0 -189
- package/src/oauth/types/identity.ts +0 -17
- package/src/oauth/types.ts +0 -24
- package/src/oauth/userStore.ts +0 -73
- package/src/redis/redisService.ts +0 -137
- package/src/security/ipService.ts +0 -180
- package/src/security/limiter.ts +0 -116
- package/src/storage/RedisTokenStore.ts +0 -110
- package/src/storage/userStorage.ts +0 -16
- package/src/tests/con.test.ts +0 -76
- package/src/tests/dump.rdb +0 -0
- package/src/tests/full.intergration.test.ts +0 -100
- package/src/tests/oauth.intergration.test.ts +0 -39
- package/src/tests/oauth1.test.ts +0 -145
- package/src/tests/oauth2.test.ts +0 -158
- package/src/tests/oauth3.test.ts +0 -171
- package/src/tests/testApp.ts +0 -56
- package/src/types/admin.ts +0 -7
- package/src/types/config.ts +0 -17
- package/src/types/public.ts +0 -48
- package/src/types/storage.ts +0 -15
- package/src/types/tokens.ts +0 -10
- package/src/utility/lockHelper.ts +0 -33
- package/tsconfig.json +0 -51
package/src/tests/oauth2.test.ts
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import dotenv from "dotenv";
|
|
2
|
-
import express, { Request, Response, NextFunction } from "express";
|
|
3
|
-
import { createAuthenik8 } from "../createAuthenik8";
|
|
4
|
-
import { TokenPayload } from "../types/tokens";
|
|
5
|
-
import { createIdentityEngine } from "../oauth/brain/identityEngine";
|
|
6
|
-
import { memoryAdapter } from "../oauth/adapters/memoryAdapter";
|
|
7
|
-
|
|
8
|
-
dotenv.config();
|
|
9
|
-
|
|
10
|
-
const app = express();
|
|
11
|
-
|
|
12
|
-
// =========================
|
|
13
|
-
// TOKEN SERVICE (TEST)
|
|
14
|
-
// =========================
|
|
15
|
-
const tokenService = {
|
|
16
|
-
signAccessToken: (payload: any) => {
|
|
17
|
-
return `test_access_token_${payload.userId}`;
|
|
18
|
-
},
|
|
19
|
-
generateRefreshToken: async (payload: any) => {
|
|
20
|
-
return `test_refresh_token_${payload.userId}`;
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const identityEngine = createIdentityEngine(memoryAdapter, tokenService);
|
|
25
|
-
|
|
26
|
-
// =========================
|
|
27
|
-
// AUTH INIT
|
|
28
|
-
// =========================
|
|
29
|
-
async function start() {
|
|
30
|
-
const auth = await createAuthenik8({
|
|
31
|
-
jwtSecret: "test",
|
|
32
|
-
refreshSecret: "test",
|
|
33
|
-
oauth: {
|
|
34
|
-
google: {
|
|
35
|
-
clientId: process.env.GOOGLE_CLIENT_ID!,
|
|
36
|
-
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
|
|
37
|
-
redirectUri: "http://localhost:4000/callback",
|
|
38
|
-
},
|
|
39
|
-
github: {
|
|
40
|
-
clientId: process.env.GITHUB_CLIENT_ID!,
|
|
41
|
-
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
|
|
42
|
-
redirectUri: "http://localhost:4000/auth/github/callback",
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// =========================
|
|
48
|
-
// AUTH MIDDLEWARE
|
|
49
|
-
// =========================
|
|
50
|
-
function requireAuth(req: Request, res: Response, next: NextFunction) {
|
|
51
|
-
const token = req.headers.authorization?.split(" ")[1];
|
|
52
|
-
|
|
53
|
-
if (!token) return res.status(401).json({ error: "Unauthorized" });
|
|
54
|
-
|
|
55
|
-
try {
|
|
56
|
-
req.user = auth.verifyToken(token);
|
|
57
|
-
next();
|
|
58
|
-
} catch {
|
|
59
|
-
return res.status(401).json({ error: "Invalid token" });
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// =====================================================
|
|
64
|
-
// STEP 1: GOOGLE LOGIN (CREATE USER)
|
|
65
|
-
// =====================================================
|
|
66
|
-
app.get("/auth/google", (req, res) => {
|
|
67
|
-
auth.oauth!.google!.redirect(req, res);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
app.get("/callback", async (req, res) => {
|
|
71
|
-
try {
|
|
72
|
-
const { profile, mode, userId } =
|
|
73
|
-
await auth.oauth!.google!.handleCallback(req);
|
|
74
|
-
|
|
75
|
-
const result = await identityEngine.resolveOAuth({
|
|
76
|
-
profile,
|
|
77
|
-
mode,
|
|
78
|
-
userId,
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
return res.json({
|
|
82
|
-
step: "google-login",
|
|
83
|
-
...result,
|
|
84
|
-
});
|
|
85
|
-
} catch (err) {
|
|
86
|
-
return res.status(500).json({
|
|
87
|
-
error: err instanceof Error ? err.message : "Unknown error",
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
// =====================================================
|
|
93
|
-
// STEP 2: GITHUB LOGIN (SEPARATE LOGIN FLOW)
|
|
94
|
-
// =====================================================
|
|
95
|
-
app.get("/auth/github", (req, res) => {
|
|
96
|
-
auth.oauth!.github!.redirect(req, res);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
app.get("/auth/github/callback", async (req, res) => {
|
|
100
|
-
try {
|
|
101
|
-
const { profile, mode, userId } =
|
|
102
|
-
await auth.oauth!.github!.handleCallback(req);
|
|
103
|
-
|
|
104
|
-
const result = await identityEngine.resolveOAuth({
|
|
105
|
-
profile,
|
|
106
|
-
mode,
|
|
107
|
-
userId,
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
return res.json({
|
|
111
|
-
step: "github-login",
|
|
112
|
-
...result,
|
|
113
|
-
});
|
|
114
|
-
} catch (err) {
|
|
115
|
-
return res.status(500).json({
|
|
116
|
-
error: err instanceof Error ? err.message : "Unknown error",
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
// =====================================================
|
|
122
|
-
// STEP 3: GITHUB LINK FLOW (LINK TO SAME USER)
|
|
123
|
-
// =====================================================
|
|
124
|
-
app.get("/auth/github/link", requireAuth, (req, res) => {
|
|
125
|
-
auth.oauth!.github!.redirect(req, res);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
app.get("/auth/github/link/callback", requireAuth, async (req, res) => {
|
|
129
|
-
try {
|
|
130
|
-
const { profile, mode } =
|
|
131
|
-
await auth.oauth!.github!.handleCallback(req);
|
|
132
|
-
|
|
133
|
-
const result = await identityEngine.resolveOAuth({
|
|
134
|
-
profile,
|
|
135
|
-
mode: "link",
|
|
136
|
-
userId: req.user!.userId,
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
return res.json({
|
|
140
|
-
step: "github-link",
|
|
141
|
-
...result,
|
|
142
|
-
});
|
|
143
|
-
} catch (err) {
|
|
144
|
-
return res.status(400).json({
|
|
145
|
-
error: err instanceof Error ? err.message : "Linking error",
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// =========================
|
|
152
|
-
// START SERVER
|
|
153
|
-
// =========================
|
|
154
|
-
start().then(() => {
|
|
155
|
-
app.listen(4000, () => {
|
|
156
|
-
console.log("OAuth test server running on http://localhost:4000");
|
|
157
|
-
});
|
|
158
|
-
});
|
package/src/tests/oauth3.test.ts
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import dotenv from "dotenv";
|
|
2
|
-
import express from "express";
|
|
3
|
-
import { createAuthenik8 } from "../createAuthenik8";
|
|
4
|
-
import { createIdentityEngine } from "../oauth/brain/identityEngine";
|
|
5
|
-
import { memoryAdapter } from "../oauth/adapters/memoryAdapter";
|
|
6
|
-
|
|
7
|
-
dotenv.config();
|
|
8
|
-
|
|
9
|
-
const app = express();
|
|
10
|
-
app.use(express.json());
|
|
11
|
-
|
|
12
|
-
// =========================
|
|
13
|
-
// TOKEN SERVICE (TEST)
|
|
14
|
-
// =========================
|
|
15
|
-
const tokenService = {
|
|
16
|
-
signAccessToken: (payload: any) =>
|
|
17
|
-
`test_access_${payload.userId}`,
|
|
18
|
-
|
|
19
|
-
generateRefreshToken: async (payload: any) =>
|
|
20
|
-
`test_refresh_${payload.userId}`,
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const identityEngine = createIdentityEngine(memoryAdapter, tokenService);
|
|
24
|
-
|
|
25
|
-
// =========================
|
|
26
|
-
// SIMPLE AUTH PARSER (NO req.user TYPE ISSUES)
|
|
27
|
-
// =========================
|
|
28
|
-
function getUserFromHeader(req: any) {
|
|
29
|
-
const header = req.headers["x-user-id"];
|
|
30
|
-
if (!header) return null;
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
userId: header as string,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// =========================
|
|
38
|
-
// INIT AUTH
|
|
39
|
-
// =========================
|
|
40
|
-
async function start() {
|
|
41
|
-
const auth = await createAuthenik8({
|
|
42
|
-
jwtSecret: "test",
|
|
43
|
-
refreshSecret: "test",
|
|
44
|
-
oauth: {
|
|
45
|
-
google: {
|
|
46
|
-
clientId: process.env.GOOGLE_CLIENT_ID!,
|
|
47
|
-
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
|
|
48
|
-
redirectUri: "http://localhost:4000/callback",
|
|
49
|
-
},
|
|
50
|
-
github: {
|
|
51
|
-
clientId: process.env.GITHUB_CLIENT_ID!,
|
|
52
|
-
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
|
|
53
|
-
redirectUri: "http://localhost:4000/auth/github/callback",
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// =====================================================
|
|
59
|
-
// STEP 1: GOOGLE LOGIN (CREATE USER)
|
|
60
|
-
// =====================================================
|
|
61
|
-
app.get("/auth/google", (req, res) => {
|
|
62
|
-
auth.oauth!.google!.redirect(req, res);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
app.get("/callback", async (req, res) => {
|
|
66
|
-
try {
|
|
67
|
-
const { profile, mode, userId } =
|
|
68
|
-
await auth.oauth!.google!.handleCallback(req);
|
|
69
|
-
|
|
70
|
-
const result = await identityEngine.resolveOAuth({
|
|
71
|
-
profile,
|
|
72
|
-
mode,
|
|
73
|
-
userId,
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
return res.json({
|
|
77
|
-
step: "google-login",
|
|
78
|
-
...result,
|
|
79
|
-
});
|
|
80
|
-
} catch (err) {
|
|
81
|
-
return res.status(500).json({
|
|
82
|
-
error: err instanceof Error ? err.message : "Unknown error",
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
// =====================================================
|
|
88
|
-
// STEP 2: GITHUB LOGIN (DIRECT LOGIN)
|
|
89
|
-
// =====================================================
|
|
90
|
-
app.get("/auth/github", (req, res) => {
|
|
91
|
-
console.log("🔥 HIT /auth/github");
|
|
92
|
-
|
|
93
|
-
auth.oauth!.github!.redirect(req, res);
|
|
94
|
-
return
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
app.get("/auth/github/callback", async (req, res) => {
|
|
98
|
-
try {
|
|
99
|
-
const { profile, mode, userId } =
|
|
100
|
-
await auth.oauth!.github!.handleCallback(req);
|
|
101
|
-
|
|
102
|
-
const result = await identityEngine.resolveOAuth({
|
|
103
|
-
profile,
|
|
104
|
-
mode,
|
|
105
|
-
userId,
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
return res.json({
|
|
109
|
-
step: "github-login",
|
|
110
|
-
...result,
|
|
111
|
-
});
|
|
112
|
-
} catch (err) {
|
|
113
|
-
return res.status(500).json({
|
|
114
|
-
error: err instanceof Error ? err.message : "Unknown error",
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
// =====================================================
|
|
120
|
-
// STEP 3: LINK GITHUB TO EXISTING USER (NO req.user)
|
|
121
|
-
// =====================================================
|
|
122
|
-
app.get("/auth/github/link",(req, res) => {
|
|
123
|
-
// auth.oauth!.github!.redirect(req, res);
|
|
124
|
-
console.log("🔥 HIT /auth/github/link");
|
|
125
|
-
const user = getUserFromHeader(req); // ✅ REQUIRED HERE
|
|
126
|
-
|
|
127
|
-
if (!user) {
|
|
128
|
-
return res.status(401).json({ error: "Unauthorized" });
|
|
129
|
-
}
|
|
130
|
-
(req as any).user = user;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
auth.oauth!.github!.redirect(req, res, "link");
|
|
134
|
-
return
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
app.get("/auth/github/link/callback", async (req, res) => {
|
|
138
|
-
try{
|
|
139
|
-
const { profile ,mode,userId} =
|
|
140
|
-
await auth.oauth!.github!.handleCallback(req);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const result = await identityEngine.resolveOAuth({
|
|
146
|
-
profile,
|
|
147
|
-
mode,
|
|
148
|
-
userId,
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
return res.json({
|
|
152
|
-
step: "github-link",
|
|
153
|
-
...result,
|
|
154
|
-
});
|
|
155
|
-
} catch (err) {
|
|
156
|
-
return res.status(400).json({
|
|
157
|
-
error: err instanceof Error ? err.message : "Link error",
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// =========================
|
|
164
|
-
// START SERVER
|
|
165
|
-
// =========================
|
|
166
|
-
console.log("USERS:", memoryAdapter.dump());
|
|
167
|
-
start().then(() => {
|
|
168
|
-
app.listen(4000, () => {
|
|
169
|
-
console.log("OAuth test running on http://localhost:4000");
|
|
170
|
-
});
|
|
171
|
-
});
|
package/src/tests/testApp.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
// tests/testApp.ts
|
|
2
|
-
import express from "express";
|
|
3
|
-
import request from "supertest";
|
|
4
|
-
import { createAuthenik8 } from "../createAuthenik8";
|
|
5
|
-
|
|
6
|
-
export const createTestApp = async () => {
|
|
7
|
-
const auth = await createAuthenik8({
|
|
8
|
-
jwtSecret: "test-secret",
|
|
9
|
-
refreshSecret: "refresh-secret",
|
|
10
|
-
jwtExpiry: "15m"
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
const app = express();
|
|
14
|
-
app.use(express.json());
|
|
15
|
-
|
|
16
|
-
// 🔐 Login (simulate user)
|
|
17
|
-
app.post("/login", async(req, res) => {
|
|
18
|
-
const user = { userId: "user_1", email:"test@test.com" };
|
|
19
|
-
|
|
20
|
-
const accessToken = auth.signToken(user);
|
|
21
|
-
const refreshToken = await auth.generateRefreshToken(user);
|
|
22
|
-
|
|
23
|
-
res.json({ accessToken, refreshToken });
|
|
24
|
-
console.log("Refresh Token",refreshToken)
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// 🔒 Protected route
|
|
28
|
-
app.get("/protected", (req, res) => {
|
|
29
|
-
const token = req.headers.authorization?.split(" ")[1];
|
|
30
|
-
|
|
31
|
-
if(!token){
|
|
32
|
-
return res.status(401).json({error:"Invalid token"})
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const decoded = auth.verifyToken(token);
|
|
36
|
-
|
|
37
|
-
if (!decoded) {
|
|
38
|
-
return res.status(401).json({ error: "Unauthorized" });
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
res.json({ data: "secure data", user: decoded });
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// 🔄 Refresh
|
|
45
|
-
app.post("/refresh", async (req, res) => {
|
|
46
|
-
try {
|
|
47
|
-
const result = await auth.refreshToken(req.body.refreshToken);
|
|
48
|
-
res.json(result);
|
|
49
|
-
} catch (err) {
|
|
50
|
-
res.status(401).json({ error: "Invalid refresh token" });
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
return { app, auth, request: request(app) };
|
|
56
|
-
};
|
package/src/types/admin.ts
DELETED
package/src/types/config.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { SignOptions } from "jsonwebtoken";
|
|
3
|
-
import { Redis } from "ioredis";
|
|
4
|
-
import { GoogleOAuthConfig } from "../oauth/types";
|
|
5
|
-
import { OAuthConfig } from "../oauth/types";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export interface Authenik8Config {
|
|
10
|
-
jwtSecret: string;
|
|
11
|
-
jwtExpiry?: SignOptions["expiresIn"];
|
|
12
|
-
refreshSecret: string;
|
|
13
|
-
oauth?:OAuthConfig
|
|
14
|
-
|
|
15
|
-
redis?: Redis;
|
|
16
|
-
}
|
|
17
|
-
|
package/src/types/public.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { TokenPayload, TokenPair } from "./tokens";
|
|
2
|
-
import { OAuthProfile } from "../oauth/types";
|
|
3
|
-
|
|
4
|
-
type GitHubProvider = {
|
|
5
|
-
redirect: (req:any, res: any,mode?: "login" | "link") =>Promise<void>;
|
|
6
|
-
handleCallback: (req: any) => Promise<{
|
|
7
|
-
profile: OAuthProfile ;
|
|
8
|
-
mode: "login" | "link";
|
|
9
|
-
userId: string | null}>;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
type GoogleProvider = {
|
|
13
|
-
redirect: (req: any, res: any,mode?: "login" | "link") => Promise<void>;
|
|
14
|
-
handleCallback: (req: any) => Promise<{
|
|
15
|
-
profile: OAuthProfile;
|
|
16
|
-
mode: "login" | "link";
|
|
17
|
-
userId: string | null }>;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export interface Authenik8Instance {
|
|
22
|
-
signToken: (payload: any) => string;
|
|
23
|
-
verifyToken: (token: string) => any;
|
|
24
|
-
guestToken: () => string;
|
|
25
|
-
|
|
26
|
-
refreshToken: (token: string) => Promise<any>;
|
|
27
|
-
generateRefreshToken: (payload: any) => Promise<string>;
|
|
28
|
-
|
|
29
|
-
rateLimit: any;
|
|
30
|
-
ipWhitelist: any;
|
|
31
|
-
helmet: any;
|
|
32
|
-
|
|
33
|
-
addIP: (ip: string) => Promise<void>;
|
|
34
|
-
removeIP: (ip: string) => Promise<void>;
|
|
35
|
-
listIPs: () => Promise<string[]>;
|
|
36
|
-
|
|
37
|
-
requireAdmin: any;
|
|
38
|
-
incognito: any;
|
|
39
|
-
|
|
40
|
-
redis?: any;
|
|
41
|
-
oauth?: {
|
|
42
|
-
google?: GoogleProvider;
|
|
43
|
-
github?: GitHubProvider;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
issueTokens: (payload: TokenPayload) => Promise<TokenPair>;
|
|
47
|
-
issueTokensFromProfile: (profile: OAuthProfile) => Promise<TokenPair>;
|
|
48
|
-
}
|
package/src/types/storage.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export interface User{
|
|
2
|
-
id:string;
|
|
3
|
-
email:string;
|
|
4
|
-
password:string;
|
|
5
|
-
role?:string;
|
|
6
|
-
type?:string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface UserStore{
|
|
10
|
-
findByEmail(email:string):Promise<User | null>;
|
|
11
|
-
findById(id:string):Promise<User | null>;
|
|
12
|
-
create(user: Partial<User>):
|
|
13
|
-
Promise<User>;
|
|
14
|
-
update(id:string, data:Partial<User>):Promise<User>;
|
|
15
|
-
}
|
package/src/types/tokens.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "crypto";
|
|
2
|
-
|
|
3
|
-
export class RedisLock {
|
|
4
|
-
constructor(private redis: any) {}
|
|
5
|
-
|
|
6
|
-
async acquire(key: string, ttl = 5000): Promise<string | null> {
|
|
7
|
-
const value = randomUUID();
|
|
8
|
-
|
|
9
|
-
const result = await this.redis.set(
|
|
10
|
-
key,
|
|
11
|
-
value,
|
|
12
|
-
"PX",
|
|
13
|
-
ttl,
|
|
14
|
-
"NX"
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
if (result !== "OK") return null;
|
|
18
|
-
|
|
19
|
-
return value;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async release(key: string, value: string): Promise<void> {
|
|
23
|
-
const luaScript = `
|
|
24
|
-
if redis.call("GET", KEYS[1]) == ARGV[1] then
|
|
25
|
-
return redis.call("DEL", KEYS[1])
|
|
26
|
-
else
|
|
27
|
-
return 0
|
|
28
|
-
end
|
|
29
|
-
`;
|
|
30
|
-
|
|
31
|
-
await this.redis.eval(luaScript, 1, key, value);
|
|
32
|
-
}
|
|
33
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Visit https://aka.ms/tsconfig to read more about this file
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
// File Layout
|
|
5
|
-
"rootDir": "./src",
|
|
6
|
-
"outDir": "./dist",
|
|
7
|
-
"strict": true,
|
|
8
|
-
"esModuleInterop": true,
|
|
9
|
-
|
|
10
|
-
"declaration": true,
|
|
11
|
-
"sourceMap": true,
|
|
12
|
-
|
|
13
|
-
"skipLibCheck": true,
|
|
14
|
-
"forceConsistentCasingInFileNames": true,
|
|
15
|
-
// Environment Settings
|
|
16
|
-
// See also https://aka.ms/tsconfig/module
|
|
17
|
-
"module": "CommonJS",
|
|
18
|
-
"target": "ES2019",
|
|
19
|
-
"types": [],
|
|
20
|
-
// For nodejs:
|
|
21
|
-
// "lib": ["esnext"],
|
|
22
|
-
"types": ["node","jest"],
|
|
23
|
-
// and npm install -D @types/node
|
|
24
|
-
|
|
25
|
-
// Other Outputs
|
|
26
|
-
"sourceMap": true,
|
|
27
|
-
"declaration": true,
|
|
28
|
-
"declarationMap": true,
|
|
29
|
-
|
|
30
|
-
// Stricter Typechecking Options
|
|
31
|
-
"noUncheckedIndexedAccess": true,
|
|
32
|
-
//"exactOptionalPropertyTypes": true,
|
|
33
|
-
|
|
34
|
-
// Style Options
|
|
35
|
-
// "noImplicitReturns": true,
|
|
36
|
-
// "noImplicitOverride": true,
|
|
37
|
-
// "noUnusedLocals": true,
|
|
38
|
-
// "noUnusedParameters": true,
|
|
39
|
-
// "noFallthroughCasesInSwitch": true,
|
|
40
|
-
// "noPropertyAccessFromIndexSignature": true,
|
|
41
|
-
|
|
42
|
-
// Recommended Options
|
|
43
|
-
"strict": true,
|
|
44
|
-
"jsx": "react-jsx",
|
|
45
|
-
//"verbatimModuleSyntax": true,
|
|
46
|
-
"isolatedModules": true,
|
|
47
|
-
"noUncheckedSideEffectImports": true,
|
|
48
|
-
"moduleDetection": "force",
|
|
49
|
-
"skipLibCheck": true,
|
|
50
|
-
}
|
|
51
|
-
}
|