@antelopejs/auth-jwt 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright (c) 2025-present - AntelopeJS Team
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,71 @@
1
+ ![Auth JWT](.github/social-card.png)
2
+
3
+ # @antelopejs/auth-jwt
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@antelopejs/auth-jwt.svg)](https://www.npmjs.com/package/@antelopejs/auth-jwt)
6
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0-blue)](https://www.typescriptlang.org/)
8
+
9
+ A flexible authentication and authorization module that implements the Auth interface of antelopejs with JWT.
10
+
11
+ For detailed documentation on the Auth interface, please refer to the [docs](https://github.com/AntelopeJS/interface-auth).
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ ajs project modules add @antelopejs/auth-jwt
17
+ ```
18
+
19
+ ## Configuration
20
+
21
+ The Auth module can be configured with the following options:
22
+
23
+ ```json
24
+ {
25
+ "secret": "your-secret-key",
26
+ "signKey": "path-to-private-key-file",
27
+ "verifyKey": "path-to-public-key-file",
28
+ "signOptions": {
29
+ "expiresIn": "1h",
30
+ "algorithm": "RS256"
31
+ },
32
+ "verifyOptions": {
33
+ "ignoreExpiration": false,
34
+ "algorithms": ["RS256"]
35
+ }
36
+ }
37
+ ```
38
+
39
+ The configuration options include:
40
+
41
+ - `secret`: A shared secret key used for both signing and verification (symmetric)
42
+ - `signKey`: Path to a private key file (for asymmetric signing)
43
+ - `verifyKey`: Path to a public key file (for asymmetric verification)
44
+ - `signOptions`: Options for token signing (follows jsonwebtoken's SignOptions)
45
+ - `verifyOptions`: Options for token verification (follows jsonwebtoken's VerifyOptions)
46
+
47
+ Note: Either `secret` or both `signKey` and `verifyKey` must be provided.
48
+
49
+ ## Usage with API Controllers
50
+
51
+ As this module interfaces auth decorator with the interface API provider system, it can be used with API controllers.
52
+
53
+ Authentication decorators can be used with any parameter in API controller methods. They can be combined with other parameters and decorators:
54
+
55
+ ```typescript
56
+ import { Controller, Get } from '@ajs/api/beta';
57
+ import { Authentication, AdminAuth } from '@ajs/auth/beta';
58
+
59
+ class UsersController extends Controller('/users') {
60
+ // Accessible to all authenticated users
61
+ @Get()
62
+ async listUsers(@Authentication() user: any) {
63
+ // List users
64
+ return { users: [] };
65
+ }
66
+ }
67
+ ```
68
+
69
+ ## License
70
+
71
+ Apache-2.0
@@ -0,0 +1,5 @@
1
+ import { SignOptions, VerifyOptions } from 'jsonwebtoken';
2
+ export declare namespace internal {
3
+ const Verify: (data?: string, options?: VerifyOptions) => Promise<any>;
4
+ const Sign: (data: string | Buffer | object, options?: SignOptions) => Promise<string>;
5
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.internal = void 0;
4
+ const index_1 = require("../../index");
5
+ var internal;
6
+ (function (internal) {
7
+ internal.Verify = (data, options) => {
8
+ return (0, index_1.getJWTHandler)().verify(data, options);
9
+ };
10
+ internal.Sign = (data, options) => {
11
+ return (0, index_1.getJWTHandler)().sign(data, options);
12
+ };
13
+ })(internal || (exports.internal = internal = {}));
14
+ //# sourceMappingURL=beta.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"beta.js","sourceRoot":"","sources":["../../../src/implementations/auth/beta.ts"],"names":[],"mappings":";;;AACA,uCAA4C;AAE5C,IAAiB,QAAQ,CAQxB;AARD,WAAiB,QAAQ;IACV,eAAM,GAAG,CAAC,IAAa,EAAE,OAAuB,EAAE,EAAE;QAC/D,OAAO,IAAA,qBAAa,GAAE,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC,CAAC;IAEW,aAAI,GAAG,CAAC,IAA8B,EAAE,OAAqB,EAAE,EAAE;QAC5E,OAAO,IAAA,qBAAa,GAAE,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC,CAAC;AACJ,CAAC,EARgB,QAAQ,wBAAR,QAAQ,QAQxB"}
@@ -0,0 +1,10 @@
1
+ import { SignOptions, VerifyOptions } from 'jsonwebtoken';
2
+ import { AuthSource, AuthVerifier, AuthValidator } from '@ajs.local/auth/dev';
3
+ export declare const Verify: (data?: string, options?: VerifyOptions) => Promise<any>;
4
+ export declare const Sign: (data: any, options?: SignOptions) => Promise<string>;
5
+ export declare const AttachAuthDecorator: (target: any, key: PropertyKey | undefined, index: number | PropertyDescriptor | undefined, callbacks: {
6
+ source?: AuthSource;
7
+ authenticator?: AuthVerifier;
8
+ authenticatorOptions?: VerifyOptions;
9
+ validator?: AuthValidator;
10
+ }, validator?: AuthValidator) => void;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AttachAuthDecorator = exports.Sign = exports.Verify = void 0;
4
+ const index_1 = require("../../index");
5
+ const dev_1 = require("@ajs/api/dev");
6
+ const dev_2 = require("@ajs.local/auth/dev");
7
+ const Verify = (data, options) => {
8
+ return (0, index_1.getJWTHandler)().verify(data, options);
9
+ };
10
+ exports.Verify = Verify;
11
+ const Sign = (data, options) => {
12
+ return (0, index_1.getJWTHandler)().sign(data, options);
13
+ };
14
+ exports.Sign = Sign;
15
+ const AttachAuthDecorator = (target, key, index, callbacks, validator) => {
16
+ const source = callbacks.source || dev_2.defaultSource;
17
+ const authenticator = callbacks.authenticator || dev_2.defaultAuthenticator;
18
+ const authenticatorOptions = callbacks.authenticatorOptions || {};
19
+ const defaultValidator = callbacks.validator;
20
+ if (typeof index === 'object' || key === undefined) {
21
+ (0, dev_1.SetParameterProvider)(target, Symbol(''), undefined, (context) => (0, dev_2.CheckAuthentication)(context.rawRequest, context.rawResponse, source, authenticator, authenticatorOptions, validator || defaultValidator));
22
+ }
23
+ else {
24
+ (0, dev_1.SetParameterProvider)(target, key, index, (context) => (0, dev_2.CheckAuthentication)(context.rawRequest, context.rawResponse, source, authenticator, authenticatorOptions, validator || defaultValidator));
25
+ }
26
+ };
27
+ exports.AttachAuthDecorator = AttachAuthDecorator;
28
+ //# sourceMappingURL=dev.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"d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AAC,OAAO,EAAE,EAAE,CACpD,IAAA,yBAAmB,EAClB,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,WAAW,EACnB,MAAM,EACN,aAAa,EACb,oBAAoB,EACpB,SAAS,IAAI,gBAAgB,CAC7B,CACD,CAAC;IACH,CAAC;AACF,CAAC,CAAC;AAxCW,QAAA,mBAAmB,uBAwC9B"}
@@ -0,0 +1,6 @@
1
+ import { JWTHandler, JWTHandlerConfig } from './jwt';
2
+ export declare function construct(config: JWTHandlerConfig): Promise<void>;
3
+ export declare function getJWTHandler(): JWTHandler;
4
+ export declare function destroy(): void;
5
+ export declare function start(): void;
6
+ export declare function stop(): void;
package/dist/index.js ADDED
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.construct = construct;
37
+ exports.getJWTHandler = getJWTHandler;
38
+ exports.destroy = destroy;
39
+ exports.start = start;
40
+ exports.stop = stop;
41
+ const jwt_1 = require("./jwt");
42
+ const beta_1 = require("@ajs/core/beta");
43
+ let auth;
44
+ async function construct(config) {
45
+ auth = new jwt_1.JWTHandler(config);
46
+ await auth.loadKeys();
47
+ await (0, beta_1.ImplementInterface)(Promise.resolve().then(() => __importStar(require('@ajs.local/auth/beta'))), Promise.resolve().then(() => __importStar(require('./implementations/auth/beta'))));
48
+ }
49
+ function getJWTHandler() {
50
+ return auth;
51
+ }
52
+ function destroy() { }
53
+ function start() { }
54
+ function stop() { }
55
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,8BAIC;AAED,sCAEC;AAED,0BAAkC;AAElC,sBAAgC;AAEhC,oBAA+B;AAnB/B,+BAAqD;AACrD,yCAAoD;AAEpD,IAAI,IAAgB,CAAC;AAEd,KAAK,UAAU,SAAS,CAAC,MAAwB;IACtD,IAAI,GAAG,IAAI,gBAAU,CAAC,MAAM,CAAC,CAAC;IAC9B,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;IACtB,MAAM,IAAA,yBAAkB,oDAAQ,sBAAsB,uDAAU,6BAA6B,IAAE,CAAC;AAClG,CAAC;AAED,SAAgB,aAAa;IAC3B,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAgB,OAAO,KAAU,CAAC;AAElC,SAAgB,KAAK,KAAU,CAAC;AAEhC,SAAgB,IAAI,KAAU,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { IncomingMessage, ServerResponse } from 'http';
2
+ export declare namespace internal {
3
+ const Verify: (data?: string | undefined, options?: VerifyOptions | undefined) => Promise<any>;
4
+ const Sign: (data: string | object | Buffer<ArrayBufferLike>, options?: SignOptions | undefined) => Promise<string>;
5
+ function defaultSource(req: IncomingMessage): string | undefined;
6
+ const defaultAuthenticator: AuthVerifier<any>;
7
+ function CheckAuthentication<T = unknown, R = unknown>(req: IncomingMessage, res: ServerResponse, source?: AuthSource | undefined, authenticator?: AuthVerifier<T> | undefined, authenticatorOptions?: VerifyOptions | undefined, validator?: AuthValidator<T, R> | undefined): Promise<any>;
8
+ }
9
+ export type AuthSource = (req: IncomingMessage, res: ServerResponse) => string | undefined;
10
+ export type AuthVerifier<T = unknown> = (data?: string, options?: VerifyOptions) => Promise<T> | T;
11
+ export type AuthValidator<T = unknown, R = unknown> = (data: T) => Promise<R> | R;
12
+ export interface CookieOptions {
13
+ maxAge?: number;
14
+ signed?: boolean;
15
+ expires?: Date;
16
+ httpOnly?: boolean;
17
+ path?: string;
18
+ domain?: string;
19
+ secure?: boolean;
20
+ }
21
+ export interface SignOptions {
22
+ expiresIn?: string | number;
23
+ notBefore?: string | number;
24
+ }
25
+ export interface VerifyOptions {
26
+ ignoreExpiration?: boolean;
27
+ ignoreNotBefore?: boolean;
28
+ maxAge?: string | number;
29
+ }
30
+ export declare function ValidateRaw<T = any>(token: string, options?: VerifyOptions): Promise<T>;
31
+ export declare function SignRaw(data: string | Buffer | object, options?: SignOptions): Promise<string>;
32
+ export declare function SignServerResponse(res: ServerResponse, data: string | Buffer | object, signOptions?: SignOptions, cookieOptions?: CookieOptions): Promise<ServerResponse<IncomingMessage>>;
33
+ export declare function CreateAuthDecorator<R = unknown, T = unknown>(callbacks: {
34
+ source?: AuthSource;
35
+ authenticator?: AuthVerifier<T>;
36
+ authenticatorOptions?: VerifyOptions;
37
+ validator?: AuthValidator<T, R>;
38
+ }): (validator?: AuthValidator<T, R> | undefined) => import("@ajs/core/beta/decorators").ClassDecorator<import("@ajs/core/beta/decorators").Class<any, any[]>> & import("@ajs/core/beta/decorators").PropertyDecorator & import("@ajs/core/beta/decorators").MethodDecorator & import("@ajs/core/beta/decorators").ParameterDecorator;
39
+ export declare const Authentication: (validator?: AuthValidator<unknown, unknown> | undefined) => import("@ajs/core/beta/decorators").ClassDecorator<import("@ajs/core/beta/decorators").Class<any, any[]>> & import("@ajs/core/beta/decorators").PropertyDecorator & import("@ajs/core/beta/decorators").MethodDecorator & import("@ajs/core/beta/decorators").ParameterDecorator;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Authentication = exports.internal = void 0;
4
+ exports.ValidateRaw = ValidateRaw;
5
+ exports.SignRaw = SignRaw;
6
+ exports.SignServerResponse = SignServerResponse;
7
+ exports.CreateAuthDecorator = CreateAuthDecorator;
8
+ const beta_1 = require("@ajs/core/beta");
9
+ const decorators_1 = require("@ajs/core/beta/decorators");
10
+ const beta_2 = require("@ajs/api/beta");
11
+ var internal;
12
+ (function (internal) {
13
+ internal.Verify = (0, beta_1.InterfaceFunction)();
14
+ internal.Sign = (0, beta_1.InterfaceFunction)();
15
+ function defaultSource(req) {
16
+ if (req.headers['x-antelopejs-auth']) {
17
+ return req.headers['x-antelopejs-auth'];
18
+ }
19
+ if (req.headers['cookie']) {
20
+ const match = (' ' + req.headers['cookie']).match(/ ANTELOPEJS_AUTH=([^;]*)/);
21
+ if (match) {
22
+ return match[1];
23
+ }
24
+ }
25
+ return undefined;
26
+ }
27
+ internal.defaultSource = defaultSource;
28
+ internal.defaultAuthenticator = ValidateRaw;
29
+ async function CheckAuthentication(req, res, source = undefined, authenticator = undefined, authenticatorOptions = undefined, validator = undefined) {
30
+ const data = await (authenticator || internal.defaultAuthenticator)((source || defaultSource)(req, res), authenticatorOptions);
31
+ return validator ? await validator(data) : data;
32
+ }
33
+ internal.CheckAuthentication = CheckAuthentication;
34
+ })(internal || (exports.internal = internal = {}));
35
+ function ValidateRaw(token, options) {
36
+ return internal.Verify(token, options);
37
+ }
38
+ function SignRaw(data, options) {
39
+ return internal.Sign(data, options);
40
+ }
41
+ function SignServerResponse(res, data, signOptions, cookieOptions) {
42
+ const opts = cookieOptions
43
+ ? Object.keys(cookieOptions)
44
+ .map((key) => `${key}=${cookieOptions[key]}`)
45
+ .join('; ')
46
+ : '';
47
+ return SignRaw(data, signOptions).then((data) => res.setHeader('Set-Cookie', `ANTELOPEJS_AUTH=${data}; ${opts}`));
48
+ }
49
+ function CreateAuthDecorator(callbacks) {
50
+ const source = callbacks.source || internal.defaultSource;
51
+ const authenticator = callbacks.authenticator || internal.defaultAuthenticator;
52
+ const authenticatorOptions = callbacks.authenticatorOptions || {};
53
+ const defaultValidator = callbacks.validator;
54
+ return (0, decorators_1.MakeParameterAndMethodAndPropertyAndClassDecorator)((target, key, index, validator) => {
55
+ if (typeof index === 'object' || key === undefined) {
56
+ (0, beta_2.SetParameterProvider)(target, Symbol(''), undefined, (context) => internal.CheckAuthentication(context.rawRequest, context.rawResponse, source, authenticator, authenticatorOptions, validator || defaultValidator));
57
+ }
58
+ else {
59
+ (0, beta_2.SetParameterProvider)(target, key, index, (context) => internal.CheckAuthentication(context.rawRequest, context.rawResponse, source, authenticator, authenticatorOptions, validator || defaultValidator));
60
+ }
61
+ });
62
+ }
63
+ exports.Authentication = CreateAuthDecorator({});
64
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/interfaces/auth/beta/index.ts"],"names":[],"mappings":";;;AA8MA,kCAEC;AAcD,0BAEC;AAqBD,gDAeC;AAuCD,kDAoCC;AA/UD,yCAAmD;AACnD,0DAA+F;AAE/F,wCAAqD;AAKrD,IAAiB,QAAQ,CA+CxB;AA/CD,WAAiB,QAAQ;IACV,eAAM,GAAG,IAAA,wBAAiB,GAAmD,CAAC;IAC9E,aAAI,GAAG,IAAA,wBAAiB,GAAqE,CAAC;IAE3G,SAAgB,aAAa,CAAC,GAAoB;QAChD,IAAI,GAAG,CAAC,OAAO,CAAC,m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;QACJ,CAAC;aAAM,CAAC;YACN,IAAA,2BAAoB,EAAC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE,CACnD,QAAQ,CAAC,mBAAmB,CAC1B,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,WAAW,EACnB,MAAM,EACN,aAAa,EACb,oBAAoB,EACpB,SAAS,IAAI,gBAAgB,CAC9B,CACF,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAgCY,QAAA,cAAc,GAAG,mBAAmB,CAAC,EAAE,CAAC,CAAC"}
@@ -0,0 +1,43 @@
1
+ import { IncomingMessage, ServerResponse } from 'http';
2
+ export type AuthSource = (req: IncomingMessage, res: ServerResponse) => string | undefined;
3
+ export type AuthVerifier<T = unknown> = (data?: string, options?: VerifyOptions) => Promise<T> | T;
4
+ export type AuthValidator<T = unknown, R = unknown> = (data: T) => Promise<R> | R;
5
+ export interface CookieOptions {
6
+ maxAge?: number;
7
+ signed?: boolean;
8
+ expires?: Date;
9
+ httpOnly?: boolean;
10
+ path?: string;
11
+ domain?: string;
12
+ secure?: boolean;
13
+ }
14
+ export interface SignOptions {
15
+ expiresIn?: string | number;
16
+ notBefore?: string | number;
17
+ }
18
+ export interface VerifyOptions {
19
+ ignoreExpiration?: boolean;
20
+ ignoreNotBefore?: boolean;
21
+ maxAge?: string | number;
22
+ }
23
+ export declare const Verify: (data?: string | undefined, options?: VerifyOptions | undefined) => Promise<any>;
24
+ export declare const Sign: (data: any, options?: SignOptions | undefined) => Promise<string>;
25
+ export declare const AttachAuthDecorator: (target: any, key: PropertyKey | undefined, index: number | PropertyDescriptor | undefined, callbacks: {
26
+ source?: AuthSource;
27
+ authenticator?: AuthVerifier<any>;
28
+ authenticatorOptions?: VerifyOptions;
29
+ validator?: AuthValidator<any, any>;
30
+ }, validator?: AuthValidator<unknown, unknown> | undefined) => Promise<void>;
31
+ export declare function ValidateRaw<T = any>(token: string, options?: VerifyOptions): Promise<T>;
32
+ export declare function SignRaw(data: any, options?: SignOptions): Promise<string>;
33
+ export declare function defaultSource(req: IncomingMessage): string | undefined;
34
+ export declare const defaultAuthenticator: AuthVerifier<any>;
35
+ export declare function CheckAuthentication<T = unknown, R = unknown>(req: IncomingMessage, res: ServerResponse, source?: AuthSource | undefined, authenticator?: AuthVerifier<T> | undefined, authenticatorOptions?: VerifyOptions | undefined, validator?: AuthValidator<T, R> | undefined): Promise<any>;
36
+ export declare function SignServerResponse(res: ServerResponse, data: any, signOptions?: SignOptions, cookieOptions?: CookieOptions): Promise<ServerResponse<IncomingMessage>>;
37
+ export declare function CreateAuthDecorator<R = unknown, T = unknown>(callbacks: {
38
+ source?: AuthSource;
39
+ authenticator?: AuthVerifier<T>;
40
+ authenticatorOptions?: VerifyOptions;
41
+ validator?: AuthValidator<T, R>;
42
+ }): (validator?: AuthValidator<T, R> | undefined) => import("@ajs/core/1/decorators").ClassDecorator<import("@ajs/core/1/decorators").Class<any, any[]>> & import("@ajs/core/1/decorators").PropertyDecorator & import("@ajs/core/1/decorators").MethodDecorator & import("@ajs/core/1/decorators").ParameterDecorator;
43
+ export declare const Authentication: (validator?: AuthValidator<unknown, unknown> | undefined) => import("@ajs/core/1/decorators").ClassDecorator<import("@ajs/core/1/decorators").Class<any, any[]>> & import("@ajs/core/1/decorators").PropertyDecorator & import("@ajs/core/1/decorators").MethodDecorator & import("@ajs/core/1/decorators").ParameterDecorator;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Authentication = exports.defaultAuthenticator = exports.AttachAuthDecorator = exports.Sign = exports.Verify = void 0;
4
+ exports.ValidateRaw = ValidateRaw;
5
+ exports.SignRaw = SignRaw;
6
+ exports.defaultSource = defaultSource;
7
+ exports.CheckAuthentication = CheckAuthentication;
8
+ exports.SignServerResponse = SignServerResponse;
9
+ exports.CreateAuthDecorator = CreateAuthDecorator;
10
+ const _1_1 = require("@ajs/core/1");
11
+ const decorators_1 = require("@ajs/core/1/decorators");
12
+ const dev_1 = require("@ajs/api/dev");
13
+ exports.Verify = (0, _1_1.InterfaceFunction)();
14
+ exports.Sign = (0, _1_1.InterfaceFunction)();
15
+ exports.AttachAuthDecorator = (0, _1_1.InterfaceFunction)();
16
+ function ValidateRaw(token, options) {
17
+ return (0, exports.Verify)(token, options);
18
+ }
19
+ function SignRaw(data, options) {
20
+ return (0, exports.Sign)(data, options);
21
+ }
22
+ function defaultSource(req) {
23
+ if (req.headers['x-antelopejs-auth']) {
24
+ return req.headers['x-antelopejs-auth'];
25
+ }
26
+ if (req.headers['cookie']) {
27
+ const match = (' ' + req.headers['cookie']).match(/ ANTELOPEJS_AUTH=([^;]*)/);
28
+ if (match) {
29
+ return match[1];
30
+ }
31
+ }
32
+ return undefined;
33
+ }
34
+ exports.defaultAuthenticator = ValidateRaw;
35
+ async function CheckAuthentication(req, res, source = undefined, authenticator = undefined, authenticatorOptions = undefined, validator = undefined) {
36
+ const data = await (authenticator || exports.defaultAuthenticator)((source || defaultSource)(req, res), authenticatorOptions);
37
+ return validator ? await validator(data) : data;
38
+ }
39
+ function SignServerResponse(res, data, signOptions, cookieOptions) {
40
+ const opts = cookieOptions
41
+ ? Object.keys(cookieOptions)
42
+ .map((key) => `${key}=${cookieOptions[key]}`)
43
+ .join('; ')
44
+ : '';
45
+ return SignRaw(data, signOptions).then((data) => res.setHeader('Set-Cookie', `ANTELOPEJS_AUTH=${data}; ${opts}`));
46
+ }
47
+ function CreateAuthDecorator(callbacks) {
48
+ const source = callbacks.source || defaultSource;
49
+ const authenticator = callbacks.authenticator || exports.defaultAuthenticator;
50
+ const authenticatorOptions = callbacks.authenticatorOptions || {};
51
+ const defaultValidator = callbacks.validator;
52
+ return (0, decorators_1.MakeParameterAndMethodAndPropertyAndClassDecorator)((target, key, index, validator) => {
53
+ if (typeof index === 'object' || key === undefined) {
54
+ (0, dev_1.SetParameterProvider)(target, Symbol(''), undefined, (context) => CheckAuthentication(context.rawRequest, context.rawResponse, source, authenticator, authenticatorOptions, validator || defaultValidator));
55
+ }
56
+ else {
57
+ (0, dev_1.SetParameterProvider)(target, key, index, (context) => CheckAuthentication(context.rawRequest, context.rawResponse, source, authenticator, authenticatorOptions, validator || defaultValidator));
58
+ }
59
+ });
60
+ }
61
+ exports.Authentication = CreateAuthDecorator({});
62
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/interfaces/auth/dev/index.ts"],"names":[],"mappings":";;;AAsLA,kCAEC;AAcD,0BAEC;AAKD,sCAWC;AAqBD,kDAaC;AAqBD,gDAeC;AAuCD,kDAoCC;AAzWD,oCAAgD;AAChD,uDAA4F;AAE5F,sCAAoD;AA4IvC,QAAA,MAAM,GAAG,IAAA,sBAAiB,GAAmD,CAAC;AAK9E,QAAA,IAAI,GAAG,IAAA,sBAAiB,GAAgD,CAAC;AAKzE,QAAA,mBAAmB,GAAG,IAAA,sBAAiB,GAajD,CAAC;AAgBJ,SAAgB,WAAW,CAAU,KAAa,EAAE,OAAuB;IAC1E,OAAO,IAAA,cAAM,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AAC/B,CAAC;AAcD,SAAgB,OAAO,CAAC,IAAS,EAAE,OAAqB;IACvD,OAAO,IAAA,YAAI,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC5B,CAAC;AAKD,SAAgB,aAAa,CAAC,GAAoB;IACjD,IAAI,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAAE,CAAC;QACtC,OAAO,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAW,CAAC;IACnD,CAAC;IACD,IAAI,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3B,MAAM,KAAK,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC9E,IAAI,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AAC;IACvF,MAAM,oBAAoB,GAAG,SAAS,CAAC,oBAAoB,IAAI,EAAE,CAAC;IAClE,MAAM,gBAAgB,GAAG,SAAS,CAAC,SAAS,CAAC;IAE7C,OAAO,IAAA,+DAAkD,EAAC,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,SAA+B,EAAE,EAAE;QACjH,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACpD,IAAA,0BAAoB,EAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CAC/D,mBAAmB,CAClB,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,WAAW,EACnB,MAAM,EACN,aAAa,EACb,oBAAoB,EACpB,SAAS,IAAI,gBAAgB,CAC7B,CACD,CAAC;QACH,CAAC;aAAM,CAAC;YACP,IAAA,0BAAoB,EAAC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE,CACpD,mBAAmB,CAClB,OAAO,CAAC,UAAU,EAClB,OAAO,CAAC,WAAW,EACnB,MAAM,EACN,aAAa,EACb,oBAAoB,EACpB,SAAS,IAAI,gBAAgB,CAC7B,CACD,CAAC;QACH,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC;AAgCY,QAAA,cAAc,GAAG,mBAAmB,CAAC,EAAE,CAAC,CAAC"}
package/dist/jwt.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { SignOptions, VerifyOptions } from 'jsonwebtoken';
2
+ export interface JWTHandlerConfig {
3
+ secret?: string;
4
+ signKey?: string;
5
+ verifyKey?: string;
6
+ signOptions?: SignOptions;
7
+ verifyOptions?: VerifyOptions;
8
+ }
9
+ export declare class JWTHandler {
10
+ private loadFromDisk;
11
+ private signKey;
12
+ private verifyKey;
13
+ private signOptions;
14
+ private verifyOptions;
15
+ constructor(config: JWTHandlerConfig);
16
+ loadKeys(): Promise<void>;
17
+ verify(data: string | undefined, options?: VerifyOptions): Promise<any>;
18
+ sign(data: string | Buffer | object, options?: SignOptions): Promise<string>;
19
+ }
package/dist/jwt.js ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JWTHandler = void 0;
4
+ const jsonwebtoken_1 = require("jsonwebtoken");
5
+ const beta_1 = require("@ajs/api/beta");
6
+ const promises_1 = require("fs/promises");
7
+ class JWTHandler {
8
+ loadFromDisk = false;
9
+ signKey;
10
+ verifyKey;
11
+ signOptions;
12
+ verifyOptions;
13
+ constructor(config) {
14
+ if (!config.secret && (!config.signKey || !config.verifyKey)) {
15
+ throw new Error('Invalid JWT config');
16
+ }
17
+ if (!config.secret) {
18
+ this.loadFromDisk = true;
19
+ }
20
+ this.signKey = (config.signKey || config.secret);
21
+ this.verifyKey = (config.verifyKey || config.secret);
22
+ this.signOptions = config.signOptions || {};
23
+ this.verifyOptions = config.verifyOptions || {};
24
+ }
25
+ async loadKeys() {
26
+ if (this.loadFromDisk) {
27
+ this.signKey = await (0, promises_1.readFile)(this.signKey);
28
+ this.verifyKey = await (0, promises_1.readFile)(this.verifyKey);
29
+ }
30
+ }
31
+ verify(data, options) {
32
+ return data
33
+ ? new Promise((resolve, reject) => (0, jsonwebtoken_1.verify)(data, this.verifyKey, { ...this.verifyOptions, ...(options || {}) }, (err, encoded) => err ? reject(new beta_1.HTTPResult(403, `Forbidden (${err.message})`)) : resolve(encoded)))
34
+ : Promise.reject(new beta_1.HTTPResult(401, 'Unauthorized'));
35
+ }
36
+ sign(data, options) {
37
+ return new Promise((resolve, reject) => (0, jsonwebtoken_1.sign)(data, this.signKey, { ...this.signOptions, ...(options || {}) }, (err, encoded) => err ? reject(err) : resolve(encoded)));
38
+ }
39
+ }
40
+ exports.JWTHandler = JWTHandler;
41
+ //# sourceMappingURL=jwt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt.js","sourceRoot":"","sources":["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IAAA,qBAAM,EAAC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,EAAE,GAAG,IAAI,CAAC,aAAa,EAAE,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAC3F,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,iBAAU,CAAC,GAAG,EAAE,cAAc,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CACnF,CACF;YACH,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,iBAAU,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC;IAC1D,CAAC;IAmBD,IAAI,CAAC,IAA8B,EAAE,OAAqB;QACxD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CACrC,IAAA,mBAAI,EAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CACrF,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAQ,CAAC,CACtC,CACF,CAAC;IACJ,CAAC;CACF;AA5FD,gCA4FC"}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@antelopejs/auth-jwt",
3
+ "version": "0.0.1",
4
+ "description": "Authentication and authorization module that implements the Auth interface of antelopejs with JWT",
5
+ "keywords": [
6
+ "antelope",
7
+ "jwt",
8
+ "auth",
9
+ "authentication",
10
+ "authorization"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/AntelopeJS/auth.git"
15
+ },
16
+ "main": "dist/index.js",
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "license": "Apache-2.0",
24
+ "packageManager": "pnpm@10.6.5",
25
+ "scripts": {
26
+ "dev": "ajs project run -w -p playground",
27
+ "build": "tsc",
28
+ "prepack": "pnpm run build",
29
+ "release": "pnpm run lint && pnpm run test && pnpm run prepack && release-it",
30
+ "format": "prettier --write .",
31
+ "lint:fix": "eslint . --ext .js,.jsx,.ts,.tsx --fix",
32
+ "lint": "eslint . --ext .js,.jsx,.ts,.tsx",
33
+ "test": "echo \"No test specified\""
34
+ },
35
+ "antelopeJs": {
36
+ "exportsPath": "dist/interfaces",
37
+ "imports": [
38
+ "core@beta",
39
+ "api@beta"
40
+ ],
41
+ "importsOptional": []
42
+ },
43
+ "dependencies": {
44
+ "jsonwebtoken": "^9.0.2"
45
+ },
46
+ "devDependencies": {
47
+ "@eslint/eslintrc": "^3.3.1",
48
+ "@eslint/js": "^9.25.0",
49
+ "@release-it/conventional-changelog": "^10.0.1",
50
+ "@types/jsonwebtoken": "^9.0.9",
51
+ "@types/node": "^22.14.1",
52
+ "@types/ws": "^8.18.1",
53
+ "eslint": "^9.25.0",
54
+ "eslint-config-prettier": "^10.1.2",
55
+ "eslint-plugin-import": "^2.31.0",
56
+ "eslint-plugin-prettier": "^5.2.6",
57
+ "globals": "^16.0.0",
58
+ "prettier": "^3.5.3",
59
+ "release-it": "^19.0.2",
60
+ "typescript": "^5.8.3",
61
+ "typescript-eslint": "^8.30.1",
62
+ "ws": "^8.18.1"
63
+ }
64
+ }