@citec-spbu/jwt 1.0.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.
- package/dist/constants/consumer.constants.d.ts +1 -0
- package/dist/constants/consumer.constants.js +4 -0
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/index.js +18 -0
- package/dist/constants/issuer.constants.d.ts +1 -0
- package/dist/constants/issuer.constants.js +4 -0
- package/dist/consumer/consumer.module.d.ts +6 -0
- package/dist/consumer/consumer.module.js +97 -0
- package/dist/consumer/consumer.provider.d.ts +4 -0
- package/dist/consumer/consumer.provider.js +24 -0
- package/dist/consumer/consumer.service.d.ts +8 -0
- package/dist/consumer/consumer.service.js +66 -0
- package/dist/consumer/index.d.ts +3 -0
- package/dist/consumer/index.js +19 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +19 -0
- package/dist/interfaces/consumer-async-options.interface.d.ts +6 -0
- package/dist/interfaces/consumer-async-options.interface.js +2 -0
- package/dist/interfaces/consumer-options.interface.d.ts +3 -0
- package/dist/interfaces/consumer-options.interface.js +2 -0
- package/dist/interfaces/index.d.ts +5 -0
- package/dist/interfaces/index.js +21 -0
- package/dist/interfaces/issuer-async-options.interface.d.ts +6 -0
- package/dist/interfaces/issuer-async-options.interface.js +2 -0
- package/dist/interfaces/issuer-options.interface.d.ts +3 -0
- package/dist/interfaces/issuer-options.interface.js +2 -0
- package/dist/interfaces/token.interface.d.ts +3 -0
- package/dist/interfaces/token.interface.js +2 -0
- package/dist/issuer/index.d.ts +3 -0
- package/dist/issuer/index.js +19 -0
- package/dist/issuer/issuer.module.d.ts +6 -0
- package/dist/issuer/issuer.module.js +98 -0
- package/dist/issuer/issuer.provider.d.ts +4 -0
- package/dist/issuer/issuer.provider.js +24 -0
- package/dist/issuer/issuer.service.d.ts +8 -0
- package/dist/issuer/issuer.service.js +66 -0
- package/package.json +30 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CONSUMER_OPTIONS: unique symbol;
|
|
@@ -0,0 +1,18 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./issuer.constants"), exports);
|
|
18
|
+
__exportStar(require("./consumer.constants"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ISSUER_OPTIONS: unique symbol;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DynamicModule } from "@nestjs/common";
|
|
2
|
+
import { ConsumerAsyncOptions, ConsumerOptions } from "../interfaces";
|
|
3
|
+
export declare class ConsumerModule {
|
|
4
|
+
static register(options: ConsumerOptions): DynamicModule;
|
|
5
|
+
static registerAsync(options: ConsumerAsyncOptions): DynamicModule;
|
|
6
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.ConsumerModule = void 0;
|
|
38
|
+
const common_1 = require("@nestjs/common");
|
|
39
|
+
const jwt_1 = require("@nestjs/jwt");
|
|
40
|
+
const constants_1 = require("../constants");
|
|
41
|
+
const consumer_provider_1 = require("./consumer.provider");
|
|
42
|
+
const consumer_service_1 = require("./consumer.service");
|
|
43
|
+
const JWT_VERIFY_OPTIONS = {
|
|
44
|
+
algorithms: ["RS256"],
|
|
45
|
+
issuer: "auth-service",
|
|
46
|
+
audience: "gateway-service"
|
|
47
|
+
};
|
|
48
|
+
let ConsumerModule = (() => {
|
|
49
|
+
let _classDecorators = [(0, common_1.Global)(), (0, common_1.Module)({})];
|
|
50
|
+
let _classDescriptor;
|
|
51
|
+
let _classExtraInitializers = [];
|
|
52
|
+
let _classThis;
|
|
53
|
+
var ConsumerModule = class {
|
|
54
|
+
static { _classThis = this; }
|
|
55
|
+
static {
|
|
56
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
57
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
58
|
+
ConsumerModule = _classThis = _classDescriptor.value;
|
|
59
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
60
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
61
|
+
}
|
|
62
|
+
static register(options) {
|
|
63
|
+
const optionsProvider = (0, consumer_provider_1.createConsumerOptionsProvider)(options);
|
|
64
|
+
return {
|
|
65
|
+
module: ConsumerModule,
|
|
66
|
+
imports: [
|
|
67
|
+
jwt_1.JwtModule.register({
|
|
68
|
+
publicKey: options.publicKey,
|
|
69
|
+
signOptions: JWT_VERIFY_OPTIONS
|
|
70
|
+
})
|
|
71
|
+
],
|
|
72
|
+
providers: [optionsProvider, consumer_service_1.ConsumerService],
|
|
73
|
+
exports: [consumer_service_1.ConsumerService, constants_1.CONSUMER_OPTIONS]
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
static registerAsync(options) {
|
|
77
|
+
const optionsProvider = (0, consumer_provider_1.createConsumerAsyncOptionsProvider)(options);
|
|
78
|
+
return {
|
|
79
|
+
module: ConsumerModule,
|
|
80
|
+
imports: [
|
|
81
|
+
...(options.imports || []),
|
|
82
|
+
jwt_1.JwtModule.registerAsync({
|
|
83
|
+
useFactory: async (options) => ({
|
|
84
|
+
publicKey: options.publicKey,
|
|
85
|
+
signOptions: JWT_VERIFY_OPTIONS
|
|
86
|
+
}),
|
|
87
|
+
inject: [constants_1.CONSUMER_OPTIONS]
|
|
88
|
+
})
|
|
89
|
+
],
|
|
90
|
+
providers: [optionsProvider, consumer_service_1.ConsumerService],
|
|
91
|
+
exports: [consumer_service_1.ConsumerService, constants_1.CONSUMER_OPTIONS]
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
return ConsumerModule = _classThis;
|
|
96
|
+
})();
|
|
97
|
+
exports.ConsumerModule = ConsumerModule;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Provider } from "@nestjs/common";
|
|
2
|
+
import { ConsumerAsyncOptions, ConsumerOptions } from "../interfaces";
|
|
3
|
+
export declare function createConsumerOptionsProvider(options: ConsumerOptions): Provider;
|
|
4
|
+
export declare function createConsumerAsyncOptionsProvider(options: ConsumerAsyncOptions): Provider;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createConsumerOptionsProvider = createConsumerOptionsProvider;
|
|
4
|
+
exports.createConsumerAsyncOptionsProvider = createConsumerAsyncOptionsProvider;
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
function createConsumerOptionsProvider(options) {
|
|
7
|
+
return {
|
|
8
|
+
provide: constants_1.CONSUMER_OPTIONS,
|
|
9
|
+
useValue: Object.freeze({ ...options })
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function createConsumerAsyncOptionsProvider(options) {
|
|
13
|
+
return {
|
|
14
|
+
provide: constants_1.CONSUMER_OPTIONS,
|
|
15
|
+
useFactory: async (...args) => {
|
|
16
|
+
const resolved = await options.useFactory(...args);
|
|
17
|
+
if (!resolved || typeof resolved.publicKey !== "string") {
|
|
18
|
+
throw new Error(`[ConsumerModule] "publicKey" is required and must be a string`);
|
|
19
|
+
}
|
|
20
|
+
return Object.freeze({ ...resolved });
|
|
21
|
+
},
|
|
22
|
+
inject: options.inject ?? []
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { JwtService, JwtVerifyOptions } from "@nestjs/jwt";
|
|
2
|
+
import { TokenPayload } from "../interfaces";
|
|
3
|
+
export declare class ConsumerService {
|
|
4
|
+
private readonly jwtService;
|
|
5
|
+
constructor(jwtService: JwtService);
|
|
6
|
+
verify(token: string, options?: JwtVerifyOptions): TokenPayload;
|
|
7
|
+
verifyAsync(token: string, options?: JwtVerifyOptions): Promise<TokenPayload>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.ConsumerService = void 0;
|
|
38
|
+
const common_1 = require("@nestjs/common");
|
|
39
|
+
let ConsumerService = (() => {
|
|
40
|
+
let _classDecorators = [(0, common_1.Injectable)()];
|
|
41
|
+
let _classDescriptor;
|
|
42
|
+
let _classExtraInitializers = [];
|
|
43
|
+
let _classThis;
|
|
44
|
+
var ConsumerService = class {
|
|
45
|
+
static { _classThis = this; }
|
|
46
|
+
static {
|
|
47
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
48
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
49
|
+
ConsumerService = _classThis = _classDescriptor.value;
|
|
50
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
51
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
52
|
+
}
|
|
53
|
+
jwtService;
|
|
54
|
+
constructor(jwtService) {
|
|
55
|
+
this.jwtService = jwtService;
|
|
56
|
+
}
|
|
57
|
+
verify(token, options) {
|
|
58
|
+
return this.jwtService.verify(token, options);
|
|
59
|
+
}
|
|
60
|
+
verifyAsync(token, options) {
|
|
61
|
+
return this.jwtService.verifyAsync(token, options);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
return ConsumerService = _classThis;
|
|
65
|
+
})();
|
|
66
|
+
exports.ConsumerService = ConsumerService;
|
|
@@ -0,0 +1,19 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./consumer.module"), exports);
|
|
18
|
+
__exportStar(require("./consumer.service"), exports);
|
|
19
|
+
__exportStar(require("./consumer.provider"), exports);
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./issuer"), exports);
|
|
18
|
+
__exportStar(require("./consumer"), exports);
|
|
19
|
+
__exportStar(require("./interfaces"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FactoryProvider, ModuleMetadata } from "@nestjs/common";
|
|
2
|
+
import type { ConsumerOptions } from "./consumer-options.interface";
|
|
3
|
+
export interface ConsumerAsyncOptions extends Pick<ModuleMetadata, "imports"> {
|
|
4
|
+
useFactory?: (...args: any[]) => Promise<ConsumerOptions> | ConsumerOptions;
|
|
5
|
+
inject?: FactoryProvider["inject"];
|
|
6
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./token.interface"), exports);
|
|
18
|
+
__exportStar(require("./issuer-options.interface"), exports);
|
|
19
|
+
__exportStar(require("./issuer-async-options.interface"), exports);
|
|
20
|
+
__exportStar(require("./consumer-options.interface"), exports);
|
|
21
|
+
__exportStar(require("./consumer-async-options.interface"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FactoryProvider, ModuleMetadata } from "@nestjs/common";
|
|
2
|
+
import type { IssuerOptions } from "./issuer-options.interface";
|
|
3
|
+
export interface IssuerAsyncOptions extends Pick<ModuleMetadata, "imports"> {
|
|
4
|
+
useFactory?: (...args: any[]) => Promise<IssuerOptions> | IssuerOptions;
|
|
5
|
+
inject?: FactoryProvider["inject"];
|
|
6
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./issuer.module"), exports);
|
|
18
|
+
__exportStar(require("./issuer.service"), exports);
|
|
19
|
+
__exportStar(require("./issuer.provider"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DynamicModule } from "@nestjs/common";
|
|
2
|
+
import { IssuerAsyncOptions, IssuerOptions } from "../interfaces";
|
|
3
|
+
export declare class IssuerModule {
|
|
4
|
+
static register(options: IssuerOptions): DynamicModule;
|
|
5
|
+
static registerAsync(options: IssuerAsyncOptions): DynamicModule;
|
|
6
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.IssuerModule = void 0;
|
|
38
|
+
const common_1 = require("@nestjs/common");
|
|
39
|
+
const jwt_1 = require("@nestjs/jwt");
|
|
40
|
+
const constants_1 = require("../constants");
|
|
41
|
+
const issuer_provider_1 = require("./issuer.provider");
|
|
42
|
+
const issuer_service_1 = require("./issuer.service");
|
|
43
|
+
const JWT_SIGN_OPTIONS = {
|
|
44
|
+
algorithm: "RS256",
|
|
45
|
+
issuer: "auth-service",
|
|
46
|
+
audience: "gateway-service",
|
|
47
|
+
keyid: "auth.v1"
|
|
48
|
+
};
|
|
49
|
+
let IssuerModule = (() => {
|
|
50
|
+
let _classDecorators = [(0, common_1.Global)(), (0, common_1.Module)({})];
|
|
51
|
+
let _classDescriptor;
|
|
52
|
+
let _classExtraInitializers = [];
|
|
53
|
+
let _classThis;
|
|
54
|
+
var IssuerModule = class {
|
|
55
|
+
static { _classThis = this; }
|
|
56
|
+
static {
|
|
57
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
58
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
59
|
+
IssuerModule = _classThis = _classDescriptor.value;
|
|
60
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
61
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
62
|
+
}
|
|
63
|
+
static register(options) {
|
|
64
|
+
const optionsProvider = (0, issuer_provider_1.createIssuerOptionsProvider)(options);
|
|
65
|
+
return {
|
|
66
|
+
module: IssuerModule,
|
|
67
|
+
imports: [
|
|
68
|
+
jwt_1.JwtModule.register({
|
|
69
|
+
privateKey: options.privateKey,
|
|
70
|
+
signOptions: JWT_SIGN_OPTIONS
|
|
71
|
+
})
|
|
72
|
+
],
|
|
73
|
+
providers: [optionsProvider, issuer_service_1.IssuerService],
|
|
74
|
+
exports: [issuer_service_1.IssuerService, constants_1.ISSUER_OPTIONS]
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
static registerAsync(options) {
|
|
78
|
+
const optionsProvider = (0, issuer_provider_1.createIssuerAsyncOptionsProvider)(options);
|
|
79
|
+
return {
|
|
80
|
+
module: IssuerModule,
|
|
81
|
+
imports: [
|
|
82
|
+
...(options.imports || []),
|
|
83
|
+
jwt_1.JwtModule.registerAsync({
|
|
84
|
+
useFactory: async (options) => ({
|
|
85
|
+
privateKey: options.privateKey,
|
|
86
|
+
signOptions: JWT_SIGN_OPTIONS
|
|
87
|
+
}),
|
|
88
|
+
inject: [constants_1.ISSUER_OPTIONS]
|
|
89
|
+
})
|
|
90
|
+
],
|
|
91
|
+
providers: [optionsProvider, issuer_service_1.IssuerService],
|
|
92
|
+
exports: [issuer_service_1.IssuerService, constants_1.ISSUER_OPTIONS]
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
return IssuerModule = _classThis;
|
|
97
|
+
})();
|
|
98
|
+
exports.IssuerModule = IssuerModule;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Provider } from "@nestjs/common";
|
|
2
|
+
import { IssuerAsyncOptions, IssuerOptions } from "../interfaces";
|
|
3
|
+
export declare function createIssuerOptionsProvider(options: IssuerOptions): Provider;
|
|
4
|
+
export declare function createIssuerAsyncOptionsProvider(options: IssuerAsyncOptions): Provider;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createIssuerOptionsProvider = createIssuerOptionsProvider;
|
|
4
|
+
exports.createIssuerAsyncOptionsProvider = createIssuerAsyncOptionsProvider;
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
function createIssuerOptionsProvider(options) {
|
|
7
|
+
return {
|
|
8
|
+
provide: constants_1.ISSUER_OPTIONS,
|
|
9
|
+
useValue: Object.freeze({ ...options })
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function createIssuerAsyncOptionsProvider(options) {
|
|
13
|
+
return {
|
|
14
|
+
provide: constants_1.ISSUER_OPTIONS,
|
|
15
|
+
useFactory: async (...args) => {
|
|
16
|
+
const resolved = await options.useFactory(...args);
|
|
17
|
+
if (!resolved || typeof resolved.privateKey !== "string") {
|
|
18
|
+
throw new Error(`[IssuerModule] "privateKey" is required and must be a string`);
|
|
19
|
+
}
|
|
20
|
+
return Object.freeze({ ...resolved });
|
|
21
|
+
},
|
|
22
|
+
inject: options.inject ?? []
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { JwtService, JwtSignOptions } from "@nestjs/jwt";
|
|
2
|
+
import { TokenPayload } from "../interfaces";
|
|
3
|
+
export declare class IssuerService {
|
|
4
|
+
private readonly jwtService;
|
|
5
|
+
constructor(jwtService: JwtService);
|
|
6
|
+
sign(payload: TokenPayload, options?: JwtSignOptions): string;
|
|
7
|
+
signAsync(payload: TokenPayload, options?: JwtSignOptions): Promise<string>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
+
var _, done = false;
|
|
8
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
+
var context = {};
|
|
10
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
+
if (kind === "accessor") {
|
|
15
|
+
if (result === void 0) continue;
|
|
16
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
+
}
|
|
21
|
+
else if (_ = accept(result)) {
|
|
22
|
+
if (kind === "field") initializers.unshift(_);
|
|
23
|
+
else descriptor[key] = _;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
+
done = true;
|
|
28
|
+
};
|
|
29
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
+
var useValue = arguments.length > 2;
|
|
31
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
+
}
|
|
34
|
+
return useValue ? value : void 0;
|
|
35
|
+
};
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.IssuerService = void 0;
|
|
38
|
+
const common_1 = require("@nestjs/common");
|
|
39
|
+
let IssuerService = (() => {
|
|
40
|
+
let _classDecorators = [(0, common_1.Injectable)()];
|
|
41
|
+
let _classDescriptor;
|
|
42
|
+
let _classExtraInitializers = [];
|
|
43
|
+
let _classThis;
|
|
44
|
+
var IssuerService = class {
|
|
45
|
+
static { _classThis = this; }
|
|
46
|
+
static {
|
|
47
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
48
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
49
|
+
IssuerService = _classThis = _classDescriptor.value;
|
|
50
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
51
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
52
|
+
}
|
|
53
|
+
jwtService;
|
|
54
|
+
constructor(jwtService) {
|
|
55
|
+
this.jwtService = jwtService;
|
|
56
|
+
}
|
|
57
|
+
sign(payload, options) {
|
|
58
|
+
return this.jwtService.sign(payload, options);
|
|
59
|
+
}
|
|
60
|
+
signAsync(payload, options) {
|
|
61
|
+
return this.jwtService.signAsync(payload, options);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
return IssuerService = _classThis;
|
|
65
|
+
})();
|
|
66
|
+
exports.IssuerService = IssuerService;
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@citec-spbu/jwt",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Lightweight auth lib",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc -p tsconfig.build.json",
|
|
9
|
+
"format": "prettier --write \"lib/**/*.ts\""
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@citec-spbu/core": "^1.0.3",
|
|
19
|
+
"@types/node": "^25.0.8",
|
|
20
|
+
"prettier": "^3.7.4",
|
|
21
|
+
"typescript": "^5.9.3"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@nestjs/common": "^11.1.12",
|
|
25
|
+
"@nestjs/core": "^11.1.12",
|
|
26
|
+
"@nestjs/jwt": "^11.0.2",
|
|
27
|
+
"reflect-metadata": "^0.2.2",
|
|
28
|
+
"rxjs": "^7.8.2"
|
|
29
|
+
}
|
|
30
|
+
}
|