authenik8-core 0.1.0

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.
Files changed (98) hide show
  1. package/.env +2 -0
  2. package/README.md +93 -0
  3. package/authenik8-core-0.1.0.tgz +0 -0
  4. package/dist/auth/guestModeService.d.ts +3 -0
  5. package/dist/auth/guestModeService.d.ts.map +1 -0
  6. package/dist/auth/guestModeService.js +24 -0
  7. package/dist/auth/guestModeService.js.map +1 -0
  8. package/dist/auth/jwtAuth.d.ts +28 -0
  9. package/dist/auth/jwtAuth.d.ts.map +1 -0
  10. package/dist/auth/jwtAuth.js +67 -0
  11. package/dist/auth/jwtAuth.js.map +1 -0
  12. package/dist/auth/refreshService.d.ts +41 -0
  13. package/dist/auth/refreshService.d.ts.map +1 -0
  14. package/dist/auth/refreshService.js +77 -0
  15. package/dist/auth/refreshService.js.map +1 -0
  16. package/dist/creatAuthenik8.d.ts +2 -0
  17. package/dist/creatAuthenik8.d.ts.map +1 -0
  18. package/dist/creatAuthenik8.js +3 -0
  19. package/dist/creatAuthenik8.js.map +1 -0
  20. package/dist/createAuthenik8.d.ts +4 -0
  21. package/dist/createAuthenik8.d.ts.map +1 -0
  22. package/dist/createAuthenik8.js +58 -0
  23. package/dist/createAuthenik8.js.map +1 -0
  24. package/dist/index.d.ts +2 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +6 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/middleware/adminService.d.ts +4 -0
  29. package/dist/middleware/adminService.d.ts.map +1 -0
  30. package/dist/middleware/adminService.js +40 -0
  31. package/dist/middleware/adminService.js.map +1 -0
  32. package/dist/redis/redisService.d.ts +26 -0
  33. package/dist/redis/redisService.d.ts.map +1 -0
  34. package/dist/redis/redisService.js +104 -0
  35. package/dist/redis/redisService.js.map +1 -0
  36. package/dist/security/ipService.d.ts +36 -0
  37. package/dist/security/ipService.d.ts.map +1 -0
  38. package/dist/security/ipService.js +160 -0
  39. package/dist/security/ipService.js.map +1 -0
  40. package/dist/security/limiter.d.ts +5 -0
  41. package/dist/security/limiter.d.ts.map +1 -0
  42. package/dist/security/limiter.js +93 -0
  43. package/dist/security/limiter.js.map +1 -0
  44. package/dist/storage/RedisTokenStore.d.ts +21 -0
  45. package/dist/storage/RedisTokenStore.d.ts.map +1 -0
  46. package/dist/storage/RedisTokenStore.js +86 -0
  47. package/dist/storage/RedisTokenStore.js.map +1 -0
  48. package/dist/storage/userStorage.d.ts +7 -0
  49. package/dist/storage/userStorage.d.ts.map +1 -0
  50. package/dist/storage/userStorage.js +18 -0
  51. package/dist/storage/userStorage.js.map +1 -0
  52. package/dist/tests/full.intergration.test.d.ts +2 -0
  53. package/dist/tests/full.intergration.test.d.ts.map +1 -0
  54. package/dist/tests/full.intergration.test.js +79 -0
  55. package/dist/tests/full.intergration.test.js.map +1 -0
  56. package/dist/tests/testApp.d.ts +7 -0
  57. package/dist/tests/testApp.d.ts.map +1 -0
  58. package/dist/tests/testApp.js +53 -0
  59. package/dist/tests/testApp.js.map +1 -0
  60. package/dist/types/admin.d.ts +6 -0
  61. package/dist/types/admin.d.ts.map +1 -0
  62. package/dist/types/admin.js +3 -0
  63. package/dist/types/admin.js.map +1 -0
  64. package/dist/types/config.d.ts +9 -0
  65. package/dist/types/config.d.ts.map +1 -0
  66. package/dist/types/config.js +3 -0
  67. package/dist/types/config.js.map +1 -0
  68. package/dist/types/public.d.ts +17 -0
  69. package/dist/types/public.d.ts.map +1 -0
  70. package/dist/types/public.js +3 -0
  71. package/dist/types/public.js.map +1 -0
  72. package/dist/types/storage.d.ts +14 -0
  73. package/dist/types/storage.d.ts.map +1 -0
  74. package/dist/types/storage.js +3 -0
  75. package/dist/types/storage.js.map +1 -0
  76. package/dump.rdb +0 -0
  77. package/jest.config.js +11 -0
  78. package/package.json +56 -0
  79. package/src/1 +22 -0
  80. package/src/auth/guestModeService.ts +31 -0
  81. package/src/auth/jwtAuth.ts +99 -0
  82. package/src/auth/refreshService.ts +134 -0
  83. package/src/creatAuthenik8.ts +0 -0
  84. package/src/createAuthenik8.ts +66 -0
  85. package/src/index.ts +1 -0
  86. package/src/middleware/adminService.ts +50 -0
  87. package/src/redis/redisService.ts +137 -0
  88. package/src/security/ipService.ts +180 -0
  89. package/src/security/limiter.ts +116 -0
  90. package/src/storage/RedisTokenStore.ts +99 -0
  91. package/src/storage/userStorage.ts +16 -0
  92. package/src/tests/full.intergration.test.ts +100 -0
  93. package/src/tests/testApp.ts +56 -0
  94. package/src/types/admin.ts +7 -0
  95. package/src/types/config.ts +11 -0
  96. package/src/types/public.ts +22 -0
  97. package/src/types/storage.ts +15 -0
  98. package/tsconfig.json +51 -0
package/.env ADDED
@@ -0,0 +1,2 @@
1
+ REDIS_HOST="127.0.0.1"
2
+
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # Authenik8-core
2
+
3
+
4
+
5
+ ## Getting started
6
+
7
+ To make it easy for you to get started with GitLab, here's a list of recommended next steps.
8
+
9
+ Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
10
+
11
+ ## Add your files
12
+
13
+ * [Create](https://docs.gitlab.com/user/project/repository/web_editor/#create-a-file) or [upload](https://docs.gitlab.com/user/project/repository/web_editor/#upload-a-file) files
14
+ * [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
15
+
16
+ ```
17
+ cd existing_repo
18
+ git remote add origin https://gitlab.com/COD434/authenik8-core.git
19
+ git branch -M main
20
+ git push -uf origin main
21
+ ```
22
+
23
+ ## Integrate with your tools
24
+
25
+ * [Set up project integrations](https://gitlab.com/COD434/authenik8-core/-/settings/integrations)
26
+
27
+ ## Collaborate with your team
28
+
29
+ * [Invite team members and collaborators](https://docs.gitlab.com/user/project/members/)
30
+ * [Create a new merge request](https://docs.gitlab.com/user/project/merge_requests/creating_merge_requests/)
31
+ * [Automatically close issues from merge requests](https://docs.gitlab.com/user/project/issues/managing_issues/#closing-issues-automatically)
32
+ * [Enable merge request approvals](https://docs.gitlab.com/user/project/merge_requests/approvals/)
33
+ * [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
34
+
35
+ ## Test and Deploy
36
+
37
+ Use the built-in continuous integration in GitLab.
38
+
39
+ * [Get started with GitLab CI/CD](https://docs.gitlab.com/ci/quick_start/)
40
+ * [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/user/application_security/sast/)
41
+ * [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/topics/autodevops/requirements/)
42
+ * [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/user/clusters/agent/)
43
+ * [Set up protected environments](https://docs.gitlab.com/ci/environments/protected_environments/)
44
+
45
+ ***
46
+
47
+ # Editing this README
48
+
49
+ When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
50
+
51
+ ## Suggestions for a good README
52
+
53
+ Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
54
+
55
+ ## Name
56
+ Choose a self-explaining name for your project.
57
+
58
+ ## Description
59
+ Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
60
+
61
+ ## Badges
62
+ On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
63
+
64
+ ## Visuals
65
+ Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
66
+
67
+ ## Installation
68
+ Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
69
+
70
+ ## Usage
71
+ Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
72
+
73
+ ## Support
74
+ Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
75
+
76
+ ## Roadmap
77
+ If you have ideas for releases in the future, it is a good idea to list them in the README.
78
+
79
+ ## Contributing
80
+ State if you are open to contributions and what your requirements are for accepting them.
81
+
82
+ For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
83
+
84
+ You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
85
+
86
+ ## Authors and acknowledgment
87
+ Show your appreciation to those who have contributed to the project.
88
+
89
+ ## License
90
+ For open source projects, say how it is licensed.
91
+
92
+ ## Project status
93
+ If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
Binary file
@@ -0,0 +1,3 @@
1
+ import { Request, Response, NextFunction } from "express";
2
+ export declare const Incognito: (req: Request, res: Response, next: NextFunction) => void;
3
+ //# sourceMappingURL=guestModeService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guestModeService.d.ts","sourceRoot":"","sources":["../../src/auth/guestModeService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAa1D,eAAO,MAAM,SAAS,GAAI,KAAI,OAAO,EAAE,KAAI,QAAQ,EAAE,MAAK,YAAY,SAerE,CAAA"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Incognito = void 0;
4
+ const verifyToken = (token) => ({
5
+ id: "guest",
6
+ type: token === "temp-token" ? "guest-mode" : "authenticated"
7
+ });
8
+ const guestToken = () => "temp-token";
9
+ const Incognito = (req, res, next) => {
10
+ const authHeader = req.headers.authorization;
11
+ let token = authHeader === null || authHeader === void 0 ? void 0 : authHeader.split(" ")[1];
12
+ let user = token ? verifyToken(token) : null;
13
+ if (!user) {
14
+ const GToken = guestToken();
15
+ user = verifyToken(GToken);
16
+ res.setHeader("X-Guest-Token", GToken);
17
+ }
18
+ if ((user === null || user === void 0 ? void 0 : user.type) === "guest-mode") {
19
+ }
20
+ res.user = user;
21
+ next();
22
+ };
23
+ exports.Incognito = Incognito;
24
+ //# sourceMappingURL=guestModeService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guestModeService.js","sourceRoot":"","sources":["../../src/auth/guestModeService.ts"],"names":[],"mappings":";;;AASA,MAAM,WAAW,GAAG,CAAC,KAAa,EAAO,EAAE,CAAC,CAAC;IAC5C,EAAE,EAAE,OAAO;IACZ,IAAI,EAAC,KAAK,KAAI,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAE,eAAe;CAAC,CAAC,CAAC;AAC/D,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC;AAE/B,MAAM,SAAS,GAAG,CAAC,GAAW,EAAE,GAAY,EAAE,IAAiB,EAAC,EAAE;IACzE,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC;IAErC,IAAI,KAAK,GAAG,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACtC,IAAI,IAAI,GAAG,KAAK,CAAA,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAEpD,IAAG,CAAC,IAAI,EAAC,CAAC;QACV,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;QAC5B,IAAI,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;QAC3B,GAAG,CAAC,SAAS,CAAC,eAAe,EAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IACD,IAAG,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,MAAK,YAAY,EAAC,CAAC;IAChC,CAAC;IACE,GAAW,CAAC,IAAI,GAAG,IAAI,CAAC;IACzB,IAAI,EAAE,CAAC;AACT,CAAC,CAAA;AAfY,QAAA,SAAS,aAerB"}
@@ -0,0 +1,28 @@
1
+ import { Request, Response, NextFunction } from "express";
2
+ import { SignOptions } from "jsonwebtoken";
3
+ interface JwtPayload {
4
+ userId: string;
5
+ email: string;
6
+ type?: string;
7
+ id?: string;
8
+ createdAt?: number;
9
+ }
10
+ export interface JWTOptions {
11
+ jwtSecret: string;
12
+ expiry?: SignOptions["expiresIn"];
13
+ redisClient?: any;
14
+ onGuestToken?: () => void;
15
+ }
16
+ export declare class JWTService {
17
+ private jwtSecret;
18
+ private expiry?;
19
+ signToken(payload: object): string;
20
+ private redisclient?;
21
+ private onGuestToken?;
22
+ constructor(options: JWTOptions);
23
+ guestToken(): string;
24
+ verifyToken(token: string): JwtPayload | null;
25
+ authenticateJWT: (req: Request, res: Response, next: NextFunction) => Promise<Response<any, Record<string, any>> | undefined>;
26
+ }
27
+ export {};
28
+ //# sourceMappingURL=jwtAuth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwtAuth.d.ts","sourceRoot":"","sources":["../../src/auth/jwtAuth.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAC,MAAM,SAAS,CAAC;AAExD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAI1C,UAAU,UAAU;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAC,MAAM,CAAC;IACb,EAAE,CAAC,EAAC,MAAM,CAAC;IACX,SAAS,CAAC,EAAC,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IAC3B,SAAS,EAAC,MAAM,CAAC;IACjB,MAAM,CAAC,EAAC,WAAW,CAAC,WAAW,CAAC,CAAC;IACjC,WAAW,CAAC,EAAC,GAAG,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CACzB;AACD,qBAAa,UAAU;IAEvB,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,MAAM,CAAC,CAAyB;IAGxC,SAAS,CAAC,OAAO,EAAE,MAAM;IAMzB,OAAO,CAAC,WAAW,CAAC,CAAK;IACzB,OAAO,CAAC,YAAY,CAAC,CAAa;gBAGtB,OAAO,EAAC,UAAU;IAS9B,UAAU,IAAI,MAAM;IAYpB,WAAW,CAAC,KAAK,EAAC,MAAM,GAAE,UAAU,GAAG,IAAI;IAQ3C,eAAe,GACd,KAAI,OAAO,EACX,KAAI,QAAQ,EACZ,MAAK,YAAY,6DA2BjB;CACA"}
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.JWTService = void 0;
7
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
+ const crypto_1 = __importDefault(require("crypto"));
9
+ class JWTService {
10
+ signToken(payload) {
11
+ return jsonwebtoken_1.default.sign(payload, this.jwtSecret, {
12
+ expiresIn: this.expiry || "1h"
13
+ });
14
+ }
15
+ ;
16
+ constructor(options) {
17
+ this.authenticateJWT = async (req, res, next) => {
18
+ var _a;
19
+ const authHeader = req.headers.authorization;
20
+ const token = ((_a = req.cookies) === null || _a === void 0 ? void 0 : _a.token) || ((authHeader === null || authHeader === void 0 ? void 0 : authHeader.startsWith("Bearer ")) ? authHeader.split(" ")[1] : null);
21
+ if (!token) {
22
+ return res.status(401).json({ message: "Unauthorized" });
23
+ }
24
+ try {
25
+ const decoded = jsonwebtoken_1.default.verify(token, this.jwtSecret);
26
+ if (this.redisclient && decoded.userId) {
27
+ const storedToken = await this.redisclient.get(`session:${decoded.userId}`);
28
+ if (storedToken !== token) {
29
+ return res
30
+ .status(403)
31
+ .json({ success: false, message: "invalid session", errors: [] });
32
+ }
33
+ }
34
+ req.user = decoded;
35
+ next();
36
+ }
37
+ catch {
38
+ return res.status(403)
39
+ .json({ success: false, message: "invalid or expired token" });
40
+ }
41
+ };
42
+ this.jwtSecret = options.jwtSecret;
43
+ this.expiry = options.expiry;
44
+ this.redisclient = options.redisClient;
45
+ this.onGuestToken = options.onGuestToken;
46
+ }
47
+ guestToken() {
48
+ const payload = {
49
+ type: "guest",
50
+ id: crypto_1.default.randomUUID(),
51
+ createdAt: Date.now()
52
+ };
53
+ if (this.onGuestToken)
54
+ this.onGuestToken();
55
+ return jsonwebtoken_1.default.sign(payload, this.jwtSecret, { expiresIn: this.expiry });
56
+ }
57
+ verifyToken(token) {
58
+ try {
59
+ return jsonwebtoken_1.default.verify(token, this.jwtSecret);
60
+ }
61
+ catch {
62
+ return null;
63
+ }
64
+ }
65
+ }
66
+ exports.JWTService = JWTService;
67
+ //# sourceMappingURL=jwtAuth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwtAuth.js","sourceRoot":"","sources":["../../src/auth/jwtAuth.ts"],"names":[],"mappings":";;;;;;AAEA,gEAA+B;AAE/B,oDAA2B;AAiB3B,MAAa,UAAU;IAMvB,SAAS,CAAC,OAAe;QACzB,OAAO,sBAAG,CAAC,IAAI,CAAC,OAAO,EAAC,IAAI,CAAC,SAAS,EAAC;YACvC,SAAS,EAAC,IAAI,CAAC,MAAM,IAAI,IAAI;SAAC,CAAC,CAAA;IAC/B,CAAC;IAAA,CAAC;IAOF,YAAY,OAA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,CAAC,EAAC,OAAO,EAAC,KAAK,EAAE,OAAO,EAAE,0BAA0B,EAAC,CAAC,CAAC;YAC5D,CAAC;QACD,CAAC,CAAA;QA1DD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAEzC,CAAC;IAGD,UAAU;QACV,MAAM,OAAO,GAAG;YAChB,IAAI,EAAE,OAAO;YACb,EAAE,EAAC,gBAAM,CAAC,UAAU,EAAE;YACtB,SAAS,EAAC,IAAI,CAAC,GAAG,EAAE;SACnB,CAAA;QACD,IAAG,IAAI,CAAC,YAAY;YACnB,IAAI,CAAC,YAAY,EAAE,CAAC;QAErB,OAAO,sBAAG,CAAC,IAAI,CAAC,OAAO,EAAC,IAAI,CAAC,SAAS,EAAC,EAAC,SAAS,EAAC,IAAI,CAAC,MAAM,EAAC,CAAC,CAAC;IAChE,CAAC;IAED,WAAW,CAAC,KAAY;QACxB,IAAG,CAAC;YACH,OAAO,sBAAG,CAAC,MAAM,CAAC,KAAK,EAAC,IAAI,CAAC,SAAS,CAAc,CAAC;QAAA,CAAC;QAAA,MAAK,CAAC;YAC5D,OAAO,IAAI,CAAA;QAEX,CAAC;IACF,CAAC;CAiCA;AA5ED,gCA4EC"}
@@ -0,0 +1,41 @@
1
+ import { SignOptions } from "jsonwebtoken";
2
+ export declare class MissingTokenError extends Error {
3
+ constructor(message?: string);
4
+ }
5
+ export declare class InvalidTokenError extends Error {
6
+ constructor(message?: string);
7
+ }
8
+ interface TokenPayload {
9
+ userId: string;
10
+ email: string;
11
+ }
12
+ export interface TokenStore {
13
+ get(key: string): Promise<string | null>;
14
+ set?(key: string, value: string, expiry?: number): Promise<void>;
15
+ del?(key: string): Promise<void>;
16
+ }
17
+ export interface RefreshServiceOptions {
18
+ tokenStore: TokenStore;
19
+ accessTokenSecret: string;
20
+ refreshTokenSecret: string;
21
+ accessTokenExpiry: SignOptions["expiresIn"];
22
+ rotateRefreshTokens?: boolean;
23
+ refreshTokenExpiry?: string;
24
+ }
25
+ export interface RefreshResult {
26
+ accessToken: string;
27
+ refreshToken?: string;
28
+ }
29
+ export declare class RefreshService {
30
+ private tokenStore;
31
+ private accessTokenSecret;
32
+ private refreshTokenSecret;
33
+ private accessTokenExpiry;
34
+ private rotateRefreshTokens;
35
+ private refreshTokenExpiry;
36
+ constructor(options: RefreshServiceOptions);
37
+ generateRefreshToken(payload: TokenPayload): Promise<string>;
38
+ refresh(refreshToken?: string): Promise<RefreshResult>;
39
+ }
40
+ export {};
41
+ //# sourceMappingURL=refreshService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refreshService.d.ts","sourceRoot":"","sources":["../../src/auth/refreshService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAI3C,qBAAa,iBAAkB,SAAQ,KAAK;gBAChC,OAAO,SAAgB;CAKlC;AAED,qBAAa,iBAAkB,SAC/B,KAAK;gBACO,OAAO,SAA0B;CAI5C;AAGD,UAAU,YAAY;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACb;AAGD,MAAM,WAAW,UAAU;IAC3B,GAAG,CAAC,GAAG,EAAC,MAAM,GAAE,OAAO,CAAC,MAAM,GAAE,IAAI,CAAC,CAAC;IACtC,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAC,MAAM,GAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/D,GAAG,CAAC,CAAC,GAAG,EAAE,MAAM,GAAE,OAAO,CAAC,IAAI,CAAC,CAAC;CAE/B;AACD,MAAM,WAAW,qBAAqB;IACrC,UAAU,EAAC,UAAU,CAAC;IACtB,iBAAiB,EAAC,MAAM,CAAC;IACzB,kBAAkB,EAAC,MAAM,CAAC;IAC1B,iBAAiB,EAAC,WAAW,CAAC,WAAW,CAAC,CAAC;IAC3C,mBAAmB,CAAC,EAAC,OAAO,CAAC;IAC7B,kBAAkB,CAAC,EAAC,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,aAAa;IAC9B,WAAW,EAAC,MAAM,CAAC;IACnB,YAAY,CAAC,EAAC,MAAM,CAAC;CACpB;AAGD,qBAAa,cAAc;IAC3B,OAAO,CAAC,UAAU,CAAY;IAC9B,OAAO,CAAC,iBAAiB,CAAQ;IACjC,OAAO,CAAC,kBAAkB,CAAQ;IAClC,OAAO,CAAC,iBAAiB,CAA0B;IACnD,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,kBAAkB,CAAQ;gBAGtB,OAAO,EAAC,qBAAqB;IASlC,oBAAoB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;IAmB5D,OAAO,CAAC,YAAY,CAAC,EAAC,MAAM,GAAE,OAAO,CAAC,aAAa,CAAC;CA8C1D"}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RefreshService = exports.InvalidTokenError = exports.MissingTokenError = void 0;
7
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
+ const crypto_1 = require("crypto");
9
+ class MissingTokenError extends Error {
10
+ constructor(message = "Missing Token") {
11
+ super(message);
12
+ this.name = "MissingTokenError";
13
+ }
14
+ }
15
+ exports.MissingTokenError = MissingTokenError;
16
+ class InvalidTokenError extends Error {
17
+ constructor(message = "Invalid refresh token") {
18
+ super(message);
19
+ this.name = "InvalidTokenError";
20
+ }
21
+ }
22
+ exports.InvalidTokenError = InvalidTokenError;
23
+ class RefreshService {
24
+ constructor(options) {
25
+ var _a, _b, _c;
26
+ this.tokenStore = options.tokenStore;
27
+ this.accessTokenSecret = options.accessTokenSecret;
28
+ this.refreshTokenSecret = options.refreshTokenSecret;
29
+ this.accessTokenExpiry = (_a = options.accessTokenExpiry) !== null && _a !== void 0 ? _a : "15m";
30
+ this.rotateRefreshTokens = (_b = options.rotateRefreshTokens) !== null && _b !== void 0 ? _b : false;
31
+ this.refreshTokenExpiry = (_c = options.refreshTokenExpiry) !== null && _c !== void 0 ? _c : "7d";
32
+ }
33
+ async generateRefreshToken(payload) {
34
+ if (!payload.userId)
35
+ throw new Error("generateRefreshToken: payload.userId is missing");
36
+ const token = jsonwebtoken_1.default.sign({ ...payload, jti: (0, crypto_1.randomUUID)(), }, this.refreshTokenSecret, {
37
+ expiresIn: this.refreshTokenExpiry,
38
+ });
39
+ if (this.tokenStore.set) {
40
+ await this.tokenStore.set(`refresh:${payload.userId}`, token, 60 * 60 * 24 * 7);
41
+ }
42
+ console.log("Saving token to Redis:", token);
43
+ return token;
44
+ }
45
+ async refresh(refreshToken) {
46
+ if (!refreshToken) {
47
+ throw new MissingTokenError();
48
+ }
49
+ let decoded;
50
+ try {
51
+ decoded = jsonwebtoken_1.default.verify(refreshToken, this.refreshTokenSecret);
52
+ }
53
+ catch (err) {
54
+ throw new InvalidTokenError();
55
+ }
56
+ const storedToken = await this.tokenStore.get(`refresh:${decoded.userId}`);
57
+ console.log("Stored token:", storedToken);
58
+ console.log("Match:", storedToken === refreshToken);
59
+ if (storedToken !== refreshToken) {
60
+ throw new InvalidTokenError();
61
+ }
62
+ const newAccessToken = jsonwebtoken_1.default.sign({ userId: decoded.userId, email: decoded.email }, this.accessTokenSecret, { expiresIn: this.accessTokenExpiry });
63
+ let newRefreshToken;
64
+ if (this.rotateRefreshTokens && this.tokenStore.set) {
65
+ const key = `refresh:${decoded.userId}`;
66
+ newRefreshToken = jsonwebtoken_1.default.sign({ userId: decoded.userId, email: decoded.email, jti: (0, crypto_1.randomUUID)(), }, this.refreshTokenSecret, { expiresIn: this.refreshTokenExpiry });
67
+ await this.tokenStore.set(key, newRefreshToken, 60 * 60 * 24 * 7);
68
+ console.log("Stored new refresh token:", newRefreshToken);
69
+ }
70
+ return {
71
+ accessToken: newAccessToken,
72
+ refreshToken: newRefreshToken !== null && newRefreshToken !== void 0 ? newRefreshToken : refreshToken
73
+ };
74
+ }
75
+ }
76
+ exports.RefreshService = RefreshService;
77
+ //# sourceMappingURL=refreshService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refreshService.js","sourceRoot":"","sources":["../../src/auth/refreshService.ts"],"names":[],"mappings":";;;;;;AAAA,gEAA+B;AAE/B,mCAAiC;AAGjC,MAAa,iBAAkB,SAAQ,KAAK;IAC5C,YAAY,OAAO,GAAC,eAAe;QAEnC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAE,mBAAmB,CAAC;IAC/B,CAAC;CACA;AAND,8CAMC;AAED,MAAa,iBAAkB,SAC/B,KAAK;IACL,YAAY,OAAO,GAAG,uBAAuB;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAChC,CAAC;CACA;AAND,8CAMC;AA8BD,MAAa,cAAc;IAS3B,YAAY,OAA6B;;QACzC,IAAI,CAAC,UAAU,GAAI,OAAO,CAAC,UAAU,CAAC;QACtC,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC;QACnD,IAAI,CAAC,kBAAkB,GAAE,OAAO,CAAC,kBAAkB,CAAC;QACpD,IAAI,CAAC,iBAAiB,GAAE,MAAA,OAAO,CAAC,iBAAiB,mCAAI,KAAK,CAAC;QAC3D,IAAI,CAAC,mBAAmB,GAAG,MAAA,OAAO,CAAC,mBAAmB,mCAAI,KAAK,CAAC;QAChE,IAAI,CAAC,kBAAkB,GAAG,MAAA,OAAO,CAAC,kBAAkB,mCAAI,IAAI,CAAA;IAC3D,CAAC;IAED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appings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=creatAuthenik8.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"creatAuthenik8.js","sourceRoot":"","sources":["../src/creatAuthenik8.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { Authenik8Config } from "./types/config";
2
+ import { Authenik8Instance } from "./types/public";
3
+ export declare const createAuthenik8: (config: Authenik8Config) => Promise<Authenik8Instance>;
4
+ //# sourceMappingURL=createAuthenik8.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createAuthenik8.d.ts","sourceRoot":"","sources":["../src/createAuthenik8.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,eAAe,EAAC,MAAM,gBAAgB,CAAC;AAK/C,OAAO,EAAC,iBAAiB,EAAC,MAAM,gBAAgB,CAAA;AAGhD,eAAO,MAAM,eAAe,GAAU,QAAO,eAAe,KAAG,OAAO,CAAC,iBAAiB,CAuDvF,CAAA"}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAuthenik8 = void 0;
4
+ const ipService_1 = require("./security/ipService");
5
+ const refreshService_1 = require("./auth/refreshService");
6
+ const guestModeService_1 = require("./auth/guestModeService");
7
+ const adminService_1 = require("./middleware/adminService");
8
+ const jwtAuth_1 = require("./auth/jwtAuth");
9
+ const redisService_1 = require("./redis/redisService");
10
+ const RedisTokenStore_1 = require("./storage/RedisTokenStore");
11
+ const createAuthenik8 = async (config) => {
12
+ var _a;
13
+ const redisClient = (_a = config.redis) !== null && _a !== void 0 ? _a : await (0, redisService_1.initializeRedisClient)();
14
+ const tokenStore = new RedisTokenStore_1.RedisTokenStore(redisClient);
15
+ const jwtService = new jwtAuth_1.JWTService({
16
+ jwtSecret: config.jwtSecret,
17
+ expiry: config.jwtExpiry,
18
+ redisClient: redisClient
19
+ });
20
+ const refreshService = new refreshService_1.RefreshService({
21
+ tokenStore,
22
+ accessTokenSecret: config.jwtSecret,
23
+ refreshTokenSecret: config.refreshSecret,
24
+ accessTokenExpiry: config.jwtExpiry,
25
+ rotateRefreshTokens: true
26
+ });
27
+ const security = new ipService_1.SecurityModule({
28
+ redisClient: config.redis,
29
+ rateLimiterEnabled: true,
30
+ helmetEnabled: true,
31
+ whiteListEnabled: true
32
+ });
33
+ return {
34
+ //auth
35
+ redis: redisClient,
36
+ signToken: jwtService.signToken.bind(jwtService),
37
+ verifyToken: jwtService.verifyToken.bind(jwtService),
38
+ guestToken: jwtService.guestToken.bind(jwtService),
39
+ //refresh
40
+ refreshToken: refreshService.refresh.bind(refreshService),
41
+ generateRefreshToken: refreshService.generateRefreshToken.bind(refreshService),
42
+ //security
43
+ rateLimit: security.rateLimiterMiddleware(),
44
+ ipWhitelist: security.whiteListMiddleware(),
45
+ helmet: security.helmetMiddleware(),
46
+ //Whitelist management
47
+ addIP: security.addIP.bind(security),
48
+ removeIP: security.removeIP.bind(security),
49
+ listIPs: security.listIPs.bind(security),
50
+ //middleware
51
+ requireAdmin: (0, adminService_1.requireAdmin)({ jwtSecret: config.jwtSecret,
52
+ redis: redisClient
53
+ }),
54
+ incognito: guestModeService_1.Incognito
55
+ };
56
+ };
57
+ exports.createAuthenik8 = createAuthenik8;
58
+ //# sourceMappingURL=createAuthenik8.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createAuthenik8.js","sourceRoot":"","sources":["../src/createAuthenik8.ts"],"names":[],"mappings":";;;AAAA,oDAAoD;AACpD,0DAAsD;AAEtD,8DAAkD;AAClD,4DAAuD;AACvD,4CAAyC;AACzC,uDAA4D;AAE5D,+DAAyD;AAElD,MAAM,eAAe,GAAG,KAAK,EAAE,MAAsB,EAA8B,EAAE;;IAE5F,MAAM,WAAW,GAAG,MAAA,MAAM,CAAC,KAAK,mCAAI,MAAM,IAAA,oCAAqB,GAAE,CAAA;IACjE,MAAM,UAAU,GAAG,IAAI,iCA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Q,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC1C,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC;QAG3C,YAAY;QACb,YAAY,EAAE,IAAA,2BAAY,EAAC,EAAE,SAAS,EACrC,MAAM,CAAC,SAAS;YACX,KAAK,EAAC,WAAW;SACtB,CAAC;QACF,SAAS,EAAC,4BAAS;KAElB,CAAA;AACD,CAAC,CAAA;AAvDY,QAAA,eAAe,mBAuD3B"}
@@ -0,0 +1,2 @@
1
+ export { createAuthenik8 } from "./createAuthenik8";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAuthenik8 = void 0;
4
+ var createAuthenik8_1 = require("./createAuthenik8");
5
+ Object.defineProperty(exports, "createAuthenik8", { enumerable: true, get: function () { return createAuthenik8_1.createAuthenik8; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAA1C,kHAAA,eAAe,OAAA"}
@@ -0,0 +1,4 @@
1
+ import { Request, Response, NextFunction } from "express";
2
+ import { RequireAdminOptions } from "../types/admin";
3
+ export declare const requireAdmin: (options: RequireAdminOptions) => (req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined;
4
+ //# sourceMappingURL=adminService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adminService.d.ts","sourceRoot":"","sources":["../../src/middleware/adminService.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAC,MAAM,SAAS,CAAC;AAGxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAUrD,eAAO,MAAM,YAAY,GAAE,SAAQ,mBAAmB,MAE/C,KAAI,OAAO,EAAE,KAAI,QAAQ,EAAC,MAAK,YAAY,mDAiCjD,CAAA"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.requireAdmin = void 0;
7
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
+ const requireAdmin = (options) => {
9
+ const { jwtSecret, redis } = options;
10
+ return (req, res, next) => {
11
+ var _a;
12
+ const authHeader = req.headers.authorization;
13
+ const cookieToken = (_a = req.cookies) === null || _a === void 0 ? void 0 : _a.token;
14
+ let token;
15
+ if (authHeader && authHeader.startsWith("Bearer")) {
16
+ token = authHeader.split(" ")[1];
17
+ }
18
+ if (!token && cookieToken) {
19
+ token = cookieToken;
20
+ }
21
+ if (!token) {
22
+ return res.status(401).json({ error: "Unauthorized:No token provided" });
23
+ }
24
+ try {
25
+ const decoded = jsonwebtoken_1.default.verify(token, options.jwtSecret);
26
+ if (typeof decoded.role !== "string") {
27
+ res.status(403).json({ error: "Forbidden: Admin only" });
28
+ }
29
+ const payload = decoded;
30
+ req.user = decoded;
31
+ next();
32
+ }
33
+ catch (error) {
34
+ return;
35
+ res.status(401).json({ error: "Invalid or expired token" });
36
+ }
37
+ };
38
+ };
39
+ exports.requireAdmin = requireAdmin;
40
+ //# sourceMappingURL=adminService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adminService.js","sourceRoot":"","sources":["../../src/middleware/adminService.ts"],"names":[],"mappings":";;;;;;AAEA,gEAA+B;AAYxB,MAAM,YAAY,GAAC,CAAC,OAA2B,EAAC,EAAE;IACxD,MAAM,EAAC,SAAS,EAAC,KAAK,EA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AAC,CAAA;AAnCY,QAAA,YAAY,gBAmCxB"}
@@ -0,0 +1,26 @@
1
+ import { RedisStore } from "connect-redis";
2
+ import Redis from "ioredis";
3
+ interface RedisConfig {
4
+ url?: string;
5
+ host?: string;
6
+ port?: number;
7
+ password?: string;
8
+ maxRetriesPerRequest?: number;
9
+ connectTimeout: number;
10
+ }
11
+ interface RedisStoreOptions {
12
+ prefix?: string;
13
+ ttl?: number;
14
+ }
15
+ interface SetupRedisOptions {
16
+ redisConfig?: Partial<RedisConfig>;
17
+ storeOptions?: Partial<RedisStoreOptions>;
18
+ }
19
+ declare const setupRedis: (options?: SetupRedisOptions) => Promise<{
20
+ redisClient: Redis;
21
+ redisStore: RedisStore;
22
+ }>;
23
+ declare const initializeRedisClient: () => Promise<Redis>;
24
+ export { setupRedis, initializeRedisClient };
25
+ export type { RedisConfig, RedisStoreOptions, SetupRedisOptions };
26
+ //# sourceMappingURL=redisService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redisService.d.ts","sourceRoot":"","sources":["../../src/redis/redisService.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAO,eAAe,CAAC;AAC1C,OAAO,KAA4B,MAAK,SAAS,CAAC;AAMlD,UAAU,WAAW;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oBAAoB,CAAC,EAAC,MAAM,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;CACtB;AAED,UAAU,iBAAiB;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACZ;AAED,UAAU,iBAAiB;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IACnC,YAAY,CAAC,EAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACxC;AA+CD,QAAA,MAAM,UAAU,GAAU,UAAU,iBAAiB;;;EAsDpD,CAAC;AACF,QAAA,MAAM,qBAAqB,sBAM1B,CAAC;AAEF,OAAO,EAAC,UAAU,EAAE,qBAAqB,EAAC,CAAC;AAC3C,YAAY,EAAC,WAAW,EAAE,iBAAiB,EAAE,iBAAiB,EAAC,CAAA"}