@antelopejs/auth-jwt 0.1.1 → 0.1.3
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/dist/interfaces/auth/beta/index.d.ts +2 -2
- package/dist/interfaces/auth/beta/index.js +3 -3
- package/dist/interfaces/auth/beta/index.js.map +1 -1
- package/dist/test/interfaces/auth/beta/index.d.ts +1 -0
- package/dist/test/interfaces/auth/beta/index.js +54 -0
- package/dist/test/interfaces/auth/beta/index.js.map +1 -0
- package/package.json +14 -5
- package/dist/implementations/auth/dev.d.ts +0 -10
- package/dist/implementations/auth/dev.js +0 -28
- package/dist/implementations/auth/dev.js.map +0 -1
- package/dist/interfaces/auth/dev/index.d.ts +0 -43
- package/dist/interfaces/auth/dev/index.js +0 -62
- package/dist/interfaces/auth/dev/index.js.map +0 -1
|
@@ -35,5 +35,5 @@ export declare function CreateAuthDecorator<R = unknown, T = unknown>(callbacks:
|
|
|
35
35
|
authenticator?: AuthVerifier<T>;
|
|
36
36
|
authenticatorOptions?: VerifyOptions;
|
|
37
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").
|
|
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").
|
|
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").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").ParameterDecorator;
|
|
@@ -51,9 +51,9 @@ function CreateAuthDecorator(callbacks) {
|
|
|
51
51
|
const authenticator = callbacks.authenticator || internal.defaultAuthenticator;
|
|
52
52
|
const authenticatorOptions = callbacks.authenticatorOptions || {};
|
|
53
53
|
const defaultValidator = callbacks.validator;
|
|
54
|
-
return (0, decorators_1.
|
|
55
|
-
if (
|
|
56
|
-
(0, beta_2.SetParameterProvider)(target, Symbol(''), undefined, (context) => internal.CheckAuthentication(context.rawRequest, context.rawResponse, source, authenticator, authenticatorOptions, validator || defaultValidator));
|
|
54
|
+
return (0, decorators_1.MakeParameterAndPropertyAndClassDecorator)((target, key, index, validator) => {
|
|
55
|
+
if (key === undefined) {
|
|
56
|
+
(0, beta_2.SetParameterProvider)(target.prototype, Symbol(''), undefined, (context) => internal.CheckAuthentication(context.rawRequest, context.rawResponse, source, authenticator, authenticatorOptions, validator || defaultValidator));
|
|
57
57
|
}
|
|
58
58
|
else {
|
|
59
59
|
(0, beta_2.SetParameterProvider)(target, key, index, (context) => internal.CheckAuthentication(context.rawRequest, context.rawResponse, source, authenticator, authenticatorOptions, validator || defaultValidator));
|
|
@@ -1 +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,
|
|
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,0DAAsF;AAEtF,wCAAqD;AAKrD,IAAiB,QAAQ,CA+CxB;AA/CD,W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ACxE,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;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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const chai_1 = require("chai");
|
|
4
|
+
const beta_1 = require("@ajs.local/auth/beta");
|
|
5
|
+
const beta_2 = require("@ajs/api/beta");
|
|
6
|
+
const testUsers = {
|
|
7
|
+
default: {
|
|
8
|
+
name: 'Bob',
|
|
9
|
+
email: 'bob@email.com',
|
|
10
|
+
password: 'very-secure-qwerty123',
|
|
11
|
+
},
|
|
12
|
+
alternate: {
|
|
13
|
+
name: 'Alice',
|
|
14
|
+
email: 'alice@email.com',
|
|
15
|
+
password: 'very-secure-qwerty123',
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
describe('JWT Authentication Tests', () => {
|
|
19
|
+
it('jwt token is valid', async () => await jwtTokenIsValid());
|
|
20
|
+
it('jwt token is invalid', async () => await jwtTokenIsInvalid());
|
|
21
|
+
it('jwt token is expired', async () => await jwtTokenIsExpired());
|
|
22
|
+
});
|
|
23
|
+
async function jwtTokenIsValid() {
|
|
24
|
+
const userData = testUsers.default;
|
|
25
|
+
const token = await (0, beta_1.SignRaw)(userData, { expiresIn: '1h' });
|
|
26
|
+
const verifiedData = await (0, beta_1.ValidateRaw)(token);
|
|
27
|
+
(0, chai_1.expect)(verifiedData).to.be.an('object');
|
|
28
|
+
(0, chai_1.expect)(verifiedData).to.have.property('name', userData.name);
|
|
29
|
+
(0, chai_1.expect)(verifiedData).to.have.property('email', userData.email);
|
|
30
|
+
(0, chai_1.expect)(verifiedData).to.have.property('password', userData.password);
|
|
31
|
+
}
|
|
32
|
+
async function jwtTokenIsInvalid() {
|
|
33
|
+
const invalidToken = 'invalid.jwt.token';
|
|
34
|
+
try {
|
|
35
|
+
await (0, beta_1.ValidateRaw)(invalidToken);
|
|
36
|
+
chai_1.expect.fail('Should have thrown an error for invalid token');
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
(0, chai_1.expect)(error).to.be.instanceOf(beta_2.HTTPResult);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function jwtTokenIsExpired() {
|
|
43
|
+
const userData = testUsers.default;
|
|
44
|
+
const token = await (0, beta_1.SignRaw)(userData, { expiresIn: '1ms' });
|
|
45
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
46
|
+
try {
|
|
47
|
+
await (0, beta_1.ValidateRaw)(token);
|
|
48
|
+
chai_1.expect.fail('Should have thrown an error for expired token');
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
(0, chai_1.expect)(error).to.be.instanceOf(beta_2.HTTPResult);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/test/interfaces/auth/beta/index.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,+CAA4D;AAC5D,wCAA2C;AAS3C,MAAM,SAAS,GAAyC;IACtD,OAAO,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,CAAC,CAAC;AACvE,CAAC;AAED,KAAK,UAAU,iBAAiB;IAC9B,MAAM,YAAY,GAAG,mBAAmB,CAAC;IAEzC,IAAI,CAAC;QACH,MAAM,IAAA,kBAAW,EAAW,YAAY,CAAC,CAAC;QAC1C,aAAM,CAAC,IAAI,CAAC,+CAA+C,CAAC,CAAC;IAC/D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAA,aAAM,EAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,iBAAU,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC;AAED,KAAK,UAAU,iBAAiB;IAC9B,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC;IACnC,MAAM,KAAK,GAAG,MAAM,IAAA,cAAO,EAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;IAE5D,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAExD,IAAI,CAAC;QACH,MAAM,IAAA,kBAAW,EAAW,KAAK,CAAC,CAAC;QACnC,aAAM,CAAC,IAAI,CAAC,+CAA+C,CAAC,CAAC;IAC/D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAA,aAAM,EAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,iBAAU,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/auth-jwt",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Authentication and authorization module that implements the Auth interface of antelopejs with JWT",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"antelope",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"license": "Apache-2.0",
|
|
24
24
|
"packageManager": "pnpm@10.6.5",
|
|
25
25
|
"scripts": {
|
|
26
|
-
"build": "tsc",
|
|
26
|
+
"build": "rm -rf dist && tsc",
|
|
27
27
|
"dev:prepare": "cd playground && ajs module imports install",
|
|
28
28
|
"dev": "ajs project run -w -p playground",
|
|
29
29
|
"format": "prettier --write .",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"prepack": "pnpm run build",
|
|
34
34
|
"prepare": "ajs module imports install",
|
|
35
35
|
"release": "pnpm run lint && pnpm run test && pnpm run prepack && release-it",
|
|
36
|
-
"test": "
|
|
36
|
+
"test": "pnpm run build && ajs module test"
|
|
37
37
|
},
|
|
38
38
|
"antelopeJs": {
|
|
39
39
|
"exportsPath": "dist/interfaces",
|
|
@@ -44,16 +44,23 @@
|
|
|
44
44
|
"importsOptional": [],
|
|
45
45
|
"defaultConfig": {
|
|
46
46
|
"secret": "your-secret-key"
|
|
47
|
+
},
|
|
48
|
+
"test": {
|
|
49
|
+
"project": "src/test/antelope.test.js",
|
|
50
|
+
"folder": "dist/test"
|
|
47
51
|
}
|
|
48
52
|
},
|
|
49
53
|
"dependencies": {
|
|
50
|
-
"
|
|
54
|
+
"chai": "^4.5.0",
|
|
55
|
+
"jsonwebtoken": "^9.0.2",
|
|
56
|
+
"mocha": "^11.7.1"
|
|
51
57
|
},
|
|
52
58
|
"devDependencies": {
|
|
53
59
|
"@eslint/eslintrc": "^3.3.1",
|
|
54
60
|
"@eslint/js": "^9.25.0",
|
|
55
|
-
"@
|
|
61
|
+
"@types/chai": "^4.3.3",
|
|
56
62
|
"@types/jsonwebtoken": "^9.0.9",
|
|
63
|
+
"@types/mocha": "^10.0.10",
|
|
57
64
|
"@types/node": "^22.14.1",
|
|
58
65
|
"@types/ws": "^8.18.1",
|
|
59
66
|
"eslint": "^9.25.0",
|
|
@@ -61,8 +68,10 @@
|
|
|
61
68
|
"eslint-plugin-import": "^2.31.0",
|
|
62
69
|
"eslint-plugin-prettier": "^5.2.6",
|
|
63
70
|
"globals": "^16.0.0",
|
|
71
|
+
"mongodb-memory-server-core": "^10.1.4",
|
|
64
72
|
"prettier": "^3.5.3",
|
|
65
73
|
"release-it": "^19.0.2",
|
|
74
|
+
"release-it-changelogen": "^0.1.0",
|
|
66
75
|
"typescript": "^5.8.3",
|
|
67
76
|
"typescript-eslint": "^8.30.1",
|
|
68
77
|
"ws": "^8.18.1"
|
|
@@ -1,10 +0,0 @@
|
|
|
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;
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../../../src/implementations/auth/dev.ts"],"names":[],"mappings":";;;AACA,uCAA4C;AAC5C,sCAAoD;AACpD,6CAO6B;AAEtB,MAAM,MAAM,GAAG,CAAC,IAAa,EAAE,OAAuB,EAAE,EAAE;IAChE,OAAO,IAAA,qBAAa,GAAE,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC9C,CAAC,CAAC;AAFW,QAAA,MAAM,UAEjB;AAEK,MAAM,IAAI,GAAG,CAAC,IAAS,EAAE,OAAqB,EAAE,EAAE;IACxD,OAAO,IAAA,qBAAa,GAAE,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC,CAAC;AAFW,QAAA,IAAI,QAEf;AAEK,MAAM,mBAAmB,GAAG,CAClC,MAAW,EACX,GAA4B,EAC5B,KAA8C,EAC9C,SAKC,EACD,SAAyB,EACxB,EAAE;IACH,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,IAAgB,mBAAa,CAAC;IAC7D,MAAM,aAAa,GAAG,SAAS,CAAC,aAAa,IAAkB,0BAAoB,CAAC;IACpF,MAAM,oBAAoB,GAAG,SAAS,CAAC,oBAAoB,IAAI,EAAE,CAAC;IAClE,MAAM,gBAAgB,GAAG,SAAS,CAAC,SAAS,CAAC;IAE7C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACpD,IAAA,0BAAoB,EAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE,CAC/D,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;SAAM,CAAC;QACP,IAAA,0BAAoB,EAAC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,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"}
|
|
@@ -1,43 +0,0 @@
|
|
|
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;
|
|
@@ -1,62 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,KAA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