@smartsoft001/auth-shell-nestjs 2.148.0 → 2.149.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/package.json CHANGED
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "name": "@smartsoft001/auth-shell-nestjs",
3
- "version": "2.148.0",
3
+ "version": "2.149.0",
4
+ "type": "commonjs",
5
+ "main": "./src/index.js",
6
+ "typings": "./src/index.d.ts",
4
7
  "publishConfig": {
5
8
  "access": "public"
6
9
  },
@@ -15,5 +18,12 @@
15
18
  "nestjs"
16
19
  ],
17
20
  "author": "Emil Juchnikowski",
18
- "license": "MIT"
21
+ "license": "MIT",
22
+ "peerDependencies": {
23
+ "@smartsoft001/auth-domain": "2.149.0",
24
+ "@smartsoft001/auth-shell-app-services": "2.149.0",
25
+ "@smartsoft001/fb": "2.149.0",
26
+ "@smartsoft001/google": "2.149.0"
27
+ },
28
+ "types": "./src/index.d.ts"
19
29
  }
package/src/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/controllers/token/token.controller"), exports);
5
+ tslib_1.__exportStar(require("./lib/nestjs.module"), exports);
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/auth/shell/nestjs/src/index.ts"],"names":[],"mappings":";;;AAAA,mFAAyD;AACzD,8DAAoC"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TokenController = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const auth_shell_app_services_1 = require("@smartsoft001/auth-shell-app-services");
7
+ let TokenController = class TokenController {
8
+ service;
9
+ constructor(service) {
10
+ this.service = service;
11
+ }
12
+ create(req, httpReq) {
13
+ return this.service.create(req, httpReq);
14
+ }
15
+ };
16
+ exports.TokenController = TokenController;
17
+ tslib_1.__decorate([
18
+ (0, common_1.Post)(),
19
+ tslib_1.__param(0, (0, common_1.Body)()),
20
+ tslib_1.__param(1, (0, common_1.Req)()),
21
+ tslib_1.__metadata("design:type", Function),
22
+ tslib_1.__metadata("design:paramtypes", [Object, Object]),
23
+ tslib_1.__metadata("design:returntype", Promise)
24
+ ], TokenController.prototype, "create", null);
25
+ exports.TokenController = TokenController = tslib_1.__decorate([
26
+ (0, common_1.Controller)('token'),
27
+ tslib_1.__metadata("design:paramtypes", [auth_shell_app_services_1.AuthService])
28
+ ], TokenController);
29
+ //# sourceMappingURL=token.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.controller.js","sourceRoot":"","sources":["../../../../../../../../../packages/auth/shell/nestjs/src/lib/controllers/token/token.controller.ts"],"names":[],"mappings":";;;;AAAA,2CAA6D;AAI7D,mFAAoE;AAG7D,IAAM,eAAe,GAArB,MAAM,eAAe;IACG;IAA7B,YAA6B,OAAoB;QAApB,YAAO,GAAP,OAAO,CAAa;IAAG,CAAC;IAGrD,MAAM,CACI,GAAsB,EACvB,OAAgB;QAEvB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;CACF,CAAA;AAVY,0CAAe;AAI1B;IADC,IAAA,aAAI,GAAE;IAEJ,mBAAA,IAAA,aAAI,GAAE,CAAA;IACN,mBAAA,IAAA,YAAG,GAAE,CAAA;;;;6CAGP;0BATU,eAAe;IAD3B,IAAA,mBAAU,EAAC,OAAO,CAAC;6CAEoB,qCAAW;GADtC,eAAe,CAU3B"}
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var AuthShellNestjsModule_1, AuthShellNestjsCoreModule_1;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.AuthShellNestjsCoreModule = exports.AuthShellNestjsModule = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const axios_1 = require("@nestjs/axios");
7
+ const common_1 = require("@nestjs/common");
8
+ const jwt_1 = require("@nestjs/jwt");
9
+ const passport_1 = require("@nestjs/passport");
10
+ const typeorm_1 = require("@nestjs/typeorm");
11
+ const auth_domain_1 = require("@smartsoft001/auth-domain");
12
+ const auth_shell_app_services_1 = require("@smartsoft001/auth-shell-app-services");
13
+ const fb_1 = require("@smartsoft001/fb");
14
+ const google_1 = require("@smartsoft001/google");
15
+ const token_controller_1 = require("./controllers/token/token.controller");
16
+ let AuthShellNestjsModule = AuthShellNestjsModule_1 = class AuthShellNestjsModule {
17
+ static forRoot(options) {
18
+ return {
19
+ module: AuthShellNestjsModule_1,
20
+ controllers: [token_controller_1.TokenController],
21
+ providers: [
22
+ { provide: auth_domain_1.TokenConfig, useValue: options.tokenConfig },
23
+ auth_shell_app_services_1.AuthService,
24
+ fb_1.FbService,
25
+ google_1.GoogleService,
26
+ ...auth_domain_1.DOMAIN_SERVICES,
27
+ ],
28
+ imports: [
29
+ axios_1.HttpModule,
30
+ typeorm_1.TypeOrmModule.forFeature(auth_domain_1.ENTITIES),
31
+ passport_1.PassportModule.register({ defaultStrategy: 'jwt', session: false }),
32
+ jwt_1.JwtModule.register({
33
+ secret: options.tokenConfig.secretOrPrivateKey,
34
+ signOptions: {
35
+ expiresIn: options.tokenConfig.expiredIn,
36
+ },
37
+ }),
38
+ ],
39
+ exports: [fb_1.FbService, google_1.GoogleService],
40
+ };
41
+ }
42
+ };
43
+ exports.AuthShellNestjsModule = AuthShellNestjsModule;
44
+ exports.AuthShellNestjsModule = AuthShellNestjsModule = AuthShellNestjsModule_1 = tslib_1.__decorate([
45
+ (0, common_1.Module)({})
46
+ ], AuthShellNestjsModule);
47
+ let AuthShellNestjsCoreModule = AuthShellNestjsCoreModule_1 = class AuthShellNestjsCoreModule {
48
+ static forRoot(options) {
49
+ return {
50
+ module: AuthShellNestjsCoreModule_1,
51
+ providers: [
52
+ { provide: auth_domain_1.TokenConfig, useValue: options.tokenConfig },
53
+ auth_shell_app_services_1.AuthService,
54
+ ...auth_domain_1.DOMAIN_SERVICES,
55
+ ],
56
+ exports: [
57
+ auth_shell_app_services_1.AuthService,
58
+ ...auth_domain_1.DOMAIN_SERVICES,
59
+ { provide: auth_domain_1.TokenConfig, useValue: options.tokenConfig },
60
+ ],
61
+ imports: [
62
+ typeorm_1.TypeOrmModule.forFeature(auth_domain_1.ENTITIES),
63
+ passport_1.PassportModule.register({ defaultStrategy: 'jwt', session: false }),
64
+ jwt_1.JwtModule.register({
65
+ secret: options.tokenConfig.secretOrPrivateKey,
66
+ signOptions: {
67
+ expiresIn: options.tokenConfig.expiredIn,
68
+ },
69
+ }),
70
+ ],
71
+ };
72
+ }
73
+ };
74
+ exports.AuthShellNestjsCoreModule = AuthShellNestjsCoreModule;
75
+ exports.AuthShellNestjsCoreModule = AuthShellNestjsCoreModule = AuthShellNestjsCoreModule_1 = tslib_1.__decorate([
76
+ (0, common_1.Module)({})
77
+ ], AuthShellNestjsCoreModule);
78
+ //# sourceMappingURL=nestjs.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nestjs.module.js","sourceRoot":"","sources":["../../../../../../../packages/auth/shell/nestjs/src/lib/nestjs.module.ts"],"names":[],"mappings":";;;;;AAAA,yCAA2C;AAC3C,2CAAuD;AACvD,qCAAwC;AACxC,+CAAkD;AAClD,6CAAgD;AAEhD,2DAImC;AACnC,mFAAoE;AACpE,yCAA6C;AAC7C,iDAAqD;AAErD,2EAAuE;AAGhE,IAAM,qBAAqB,6BAA3B,MAAM,qBAAqB;IAChC,MAAM,CAAC,OAAO,CAAC,OAAqC;QAClD,OAAO;YACL,MAAM,EAAE,uBAAqB;YAC7B,WAAW,EAAE,CAAC,kCAAe,CAAC;YAC9B,SAAS,EAAE;gBACT,EAAE,OAAO,EAAE,yBAAW,EAAE,QAAQ,EAAE,OAAO,CAAC,WAAW,EAAE;gBACvD,qCAAW;gBACX,cAAS;gBACT,sBAAa;gBACb,GAAG,6BAAe;aACnB;YACD,OAAO,EAAE;gBACP,kBAAU;gBACV,uBAAa,CAAC,UAAU,CAAC,sBAAQ,CAAC;gBAClC,yBAAc,CAAC,QAAQ,CAAC,EAAE,eAAe,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;gBACnE,eAAS,CAAC,QAAQ,CAAC;oBACjB,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,kBAAkB;oBAC9C,WAAW,EAAE;wBACX,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,SAAS;qBACzC;iBACF,CAAC;aACH;YACD,OAAO,EAAE,CAAC,cAAS,EAAE,sBAAa,CAAC;SACpC,CAAC;IACJ,CAAC;CACF,CAAA;AA1BY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,qBAAqB,CA0BjC;AAGM,IAAM,yBAAyB,iCAA/B,MAAM,yBAAyB;IACpC,MAAM,CAAC,OAAO,CAAC,OAAqC;QAClD,OAAO;YACL,MAAM,EAAE,2BAAyB;YACjC,SAAS,EAAE;gBACT,EAAE,OAAO,EAAE,yBAAW,EAAE,QAAQ,EAAE,OAAO,CAAC,WAAW,EAAE;gBACvD,qCAAW;gBACX,GAAG,6BAAe;aACnB;YACD,OAAO,EAAE;gBACP,qCAAW;gBACX,GAAG,6BAAe;gBAClB,EAAE,OAAO,EAAE,yBAAW,EAAE,QAAQ,EAAE,OAAO,CAAC,WAAW,EAAE;aACxD;YACD,OAAO,EAAE;gBACP,uBAAa,CAAC,UAAU,CAAC,sBAAQ,CAAC;gBAClC,yBAAc,CAAC,QAAQ,CAAC,EAAE,eAAe,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;gBACnE,eAAS,CAAC,QAAQ,CAAC;oBACjB,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,kBAAkB;oBAC9C,WAAW,EAAE;wBACX,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,SAAS;qBACzC;iBACF,CAAC;aACH;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AA1BY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,yBAAyB,CA0BrC"}
package/test-setup.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=test-setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-setup.js","sourceRoot":"","sources":["../../../../../packages/auth/shell/nestjs/test-setup.ts"],"names":[],"mappings":""}
package/index.js DELETED
@@ -1,460 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __decorateClass = (decorators, target, key, kind) => {
4
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
- if (decorator = decorators[i])
7
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
- if (kind && result) __defProp(target, key, result);
9
- return result;
10
- };
11
- var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
12
-
13
- // packages/auth/shell/nestjs/src/lib/controllers/token/token.controller.ts
14
- import { Body, Controller, Post, Req } from "@nestjs/common";
15
- var TokenController = class {
16
- constructor(service) {
17
- this.service = service;
18
- }
19
- service;
20
- create(req, httpReq) {
21
- return this.service.create(req, httpReq);
22
- }
23
- };
24
- __decorateClass([
25
- Post(),
26
- __decorateParam(0, Body()),
27
- __decorateParam(1, Req())
28
- ], TokenController.prototype, "create", 1);
29
- TokenController = __decorateClass([
30
- Controller("token")
31
- ], TokenController);
32
-
33
- // packages/auth/shell/nestjs/src/lib/nestjs.module.ts
34
- import { HttpModule } from "@nestjs/axios";
35
- import { Module } from "@nestjs/common";
36
- import { JwtModule } from "@nestjs/jwt";
37
- import { PassportModule } from "@nestjs/passport";
38
- import { TypeOrmModule } from "@nestjs/typeorm";
39
-
40
- // packages/auth/domain/src/lib/entities/user.entity.ts
41
- import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
42
- var User = class {
43
- id;
44
- permissions;
45
- username;
46
- password;
47
- disabled;
48
- lastLoginDate;
49
- authRefreshToken;
50
- facebookUserId;
51
- googleUserId;
52
- };
53
- __decorateClass([
54
- PrimaryGeneratedColumn()
55
- ], User.prototype, "id", 2);
56
- __decorateClass([
57
- Column("permissions")
58
- ], User.prototype, "permissions", 2);
59
- __decorateClass([
60
- Column("username")
61
- ], User.prototype, "username", 2);
62
- __decorateClass([
63
- Column("password")
64
- ], User.prototype, "password", 2);
65
- __decorateClass([
66
- Column("disabled")
67
- ], User.prototype, "disabled", 2);
68
- __decorateClass([
69
- Column("lastLoginDate")
70
- ], User.prototype, "lastLoginDate", 2);
71
- __decorateClass([
72
- Column("authRefreshToken")
73
- ], User.prototype, "authRefreshToken", 2);
74
- __decorateClass([
75
- Column("facebookUserId")
76
- ], User.prototype, "facebookUserId", 2);
77
- __decorateClass([
78
- Column("googleUserId")
79
- ], User.prototype, "googleUserId", 2);
80
- User = __decorateClass([
81
- Entity("users")
82
- ], User);
83
-
84
- // packages/auth/domain/src/lib/feature-create-token/token.factory.ts
85
- import { Injectable } from "@nestjs/common";
86
- import { InjectRepository } from "@nestjs/typeorm";
87
- import { Guid as Guid2 } from "guid-typescript";
88
-
89
- // packages/shared/models/src/lib/decorators/model/model.decorator.ts
90
- import "reflect-metadata";
91
-
92
- // packages/shared/models/src/lib/decorators/field/field.decorator.ts
93
- import "reflect-metadata";
94
-
95
- // packages/shared/utils/src/lib/services/array/array.service.ts
96
- import * as _ from "lodash";
97
-
98
- // packages/shared/utils/src/lib/services/guid/guid.service.ts
99
- import { Guid } from "guid-typescript";
100
-
101
- // packages/shared/utils/src/lib/services/object/object.service.ts
102
- import { stringify } from "flatted";
103
-
104
- // packages/shared/utils/src/lib/services/password/password.service.ts
105
- import md5 from "md5";
106
- var PasswordService = class _PasswordService {
107
- /**
108
- * Hash password text
109
- * @param p {string} - text
110
- * @return - hashed text
111
- */
112
- static hash(p) {
113
- return Promise.resolve(md5(p));
114
- }
115
- /**
116
- * Compare password text with hashed text
117
- * @param p {string} - password text
118
- * @param h {string} - hashed text
119
- */
120
- static async compare(p, h) {
121
- const hp = await _PasswordService.hash(p);
122
- return hp === h;
123
- }
124
- };
125
-
126
- // packages/shared/domain-core/src/lib/errors.ts
127
- var DomainValidationError = class _DomainValidationError extends Error {
128
- type = _DomainValidationError;
129
- constructor(msg) {
130
- super(msg);
131
- }
132
- };
133
-
134
- // packages/auth/domain/src/lib/feature-create-token/token.factory.ts
135
- var TokenFactory = class {
136
- constructor(config, repository, jwtService, fbService, googleService) {
137
- this.config = config;
138
- this.repository = repository;
139
- this.jwtService = jwtService;
140
- this.fbService = fbService;
141
- this.googleService = googleService;
142
- }
143
- config;
144
- repository;
145
- jwtService;
146
- fbService;
147
- googleService;
148
- _invalidUsernameOrPasswordMessage = "Invalid username or password";
149
- static getQuery(config, customProvider = false) {
150
- switch (config.grant_type) {
151
- case "fb":
152
- return { facebookUserId: config.fb_user_id };
153
- case "google":
154
- return { googleUserId: config.google_user_id };
155
- case "password":
156
- return { username: config.username };
157
- case "refresh_token":
158
- return { authRefreshToken: config.refresh_token };
159
- default:
160
- if (!customProvider) {
161
- throw new DomainValidationError("Invalid grand type");
162
- }
163
- return null;
164
- }
165
- }
166
- static checkDisabled(user) {
167
- if (user.disabled) throw new DomainValidationError("user disabled");
168
- }
169
- async create(options) {
170
- if (options.request.grant_type === "fb") {
171
- options.request.fb_user_id = await this.fbService.getUserId(
172
- options.request.fb_token
173
- );
174
- }
175
- if (options.request.grant_type === "google") {
176
- options.request.google_user_id = await this.googleService.getUserId(
177
- options.request.google_token
178
- );
179
- }
180
- this.valid(options.request);
181
- const query = TokenFactory.getQuery(
182
- options.request,
183
- !!options.userProvider
184
- );
185
- const user = options.userProvider ? await options.userProvider.get(query, options.request, options.httpReq) : await this.repository.findOne(query);
186
- if (!options.validationProvider || !options.validationProvider.replace) {
187
- this.checkUser(options.request, user);
188
- TokenFactory.checkDisabled(user);
189
- await this.checkPassword(options.request, user);
190
- }
191
- if (options.validationProvider) {
192
- await options.validationProvider.check({
193
- request: options.request,
194
- user
195
- });
196
- }
197
- const refreshToken = Guid2.raw();
198
- await this.repository.update(
199
- {
200
- ...query,
201
- disabled: { $ne: true }
202
- },
203
- {
204
- lastLoginDate: /* @__PURE__ */ new Date(),
205
- authRefreshToken: refreshToken
206
- }
207
- );
208
- const payload = {
209
- permissions: user.permissions,
210
- scope: options.request.scope
211
- };
212
- if (options.payloadProvider) {
213
- await options.payloadProvider.change(payload, {
214
- user,
215
- request: options.request,
216
- httpReq: options.httpReq
217
- });
218
- }
219
- return {
220
- expired_in: this.config.expiredIn,
221
- token_type: "bearer",
222
- access_token: this.jwtService.sign(payload, {
223
- expiresIn: this.config.expiredIn,
224
- subject: user.username
225
- }),
226
- refresh_token: refreshToken,
227
- username: user.username
228
- };
229
- }
230
- checkUser(config, user) {
231
- if (!user)
232
- throw new DomainValidationError(
233
- config.grant_type === "password" ? this._invalidUsernameOrPasswordMessage : "Invalid token"
234
- );
235
- }
236
- async checkPassword(config, user) {
237
- if (config.grant_type === "password" && !await PasswordService.compare(config.password, user.password))
238
- throw new DomainValidationError(this._invalidUsernameOrPasswordMessage);
239
- }
240
- valid(req) {
241
- if (!req) throw new DomainValidationError("config is empty");
242
- if (!req.grant_type) throw new DomainValidationError("grant_type is empty");
243
- if (req.grant_type === "password") {
244
- if (!req.username) throw new DomainValidationError("username is empty");
245
- if (!req.password) throw new DomainValidationError("password is empty");
246
- if (!req.client_id) throw new DomainValidationError("client_id is empty");
247
- if (!this.config.clients.some((c) => c === req.client_id))
248
- throw new DomainValidationError("client_id is incorrect");
249
- } else if (req.grant_type === "refresh_token") {
250
- if (!req.refresh_token)
251
- throw new DomainValidationError("refresh_token is empty");
252
- } else if (req.grant_type === "fb") {
253
- if (!req.fb_token) throw new DomainValidationError("fb_token is empty");
254
- if (!req.fb_user_id)
255
- throw new DomainValidationError("fb_user_id is empty");
256
- } else if (req.grant_type === "google") {
257
- if (!req.google_token)
258
- throw new DomainValidationError("google_token is empty");
259
- if (!req.google_user_id)
260
- throw new DomainValidationError("google_user_id is empty");
261
- }
262
- }
263
- };
264
- TokenFactory = __decorateClass([
265
- Injectable(),
266
- __decorateParam(1, InjectRepository(User))
267
- ], TokenFactory);
268
-
269
- // packages/auth/domain/src/lib/feature-create-token/token.config.ts
270
- import { Injectable as Injectable2 } from "@nestjs/common";
271
- var TokenConfig = class {
272
- expiredIn;
273
- clients = [];
274
- secretOrPrivateKey;
275
- };
276
- TokenConfig = __decorateClass([
277
- Injectable2()
278
- ], TokenConfig);
279
-
280
- // packages/auth/domain/src/lib/feature-create-token/token-payload.provider.ts
281
- var AUTH_TOKEN_PAYLOAD_PROVIDER = "AUTH_TOKEN_PAYLOAD_PROVIDER";
282
-
283
- // packages/auth/domain/src/lib/feature-create-token/token-validation.provider.ts
284
- var AUTH_TOKEN_VALIDATION_PROVIDER = "AUTH_TOKEN_VALIDATION_PROVIDER";
285
-
286
- // packages/auth/domain/src/lib/feature-create-token/token-user.provider.ts
287
- var AUTH_TOKEN_USER_PROVIDER = "AUTH_TOKEN_USER_PROVIDER";
288
-
289
- // packages/auth/domain/src/index.ts
290
- var DOMAIN_SERVICES = [TokenFactory];
291
- var ENTITIES = [User];
292
-
293
- // packages/auth/shell/app-services/src/lib/services/auth/auth.service.ts
294
- import { Injectable as Injectable3, Logger } from "@nestjs/common";
295
- var AuthService = class {
296
- constructor(factory, moduleRef) {
297
- this.factory = factory;
298
- this.moduleRef = moduleRef;
299
- }
300
- factory;
301
- moduleRef;
302
- create(req, httpReq) {
303
- return this.factory.create({
304
- httpReq,
305
- request: req,
306
- payloadProvider: this.getPayloadProvider(),
307
- validationProvider: this.getValidationProvider(),
308
- userProvider: this.getUserProvider()
309
- });
310
- }
311
- getPayloadProvider() {
312
- try {
313
- return this.moduleRef.get(AUTH_TOKEN_PAYLOAD_PROVIDER, {
314
- strict: false
315
- });
316
- } catch (e) {
317
- Logger.debug(e.message, AuthService.name);
318
- }
319
- return null;
320
- }
321
- getValidationProvider() {
322
- try {
323
- return this.moduleRef.get(AUTH_TOKEN_VALIDATION_PROVIDER, {
324
- strict: false
325
- });
326
- } catch (e) {
327
- Logger.debug(e.message, AuthService.name);
328
- }
329
- return null;
330
- }
331
- getUserProvider() {
332
- try {
333
- return this.moduleRef.get(AUTH_TOKEN_USER_PROVIDER, {
334
- strict: false
335
- });
336
- } catch (e) {
337
- Logger.debug(e.message, AuthService.name);
338
- }
339
- return null;
340
- }
341
- };
342
- AuthService = __decorateClass([
343
- Injectable3()
344
- ], AuthService);
345
-
346
- // packages/shared/fb/src/lib/fb.service.ts
347
- import { Injectable as Injectable4 } from "@nestjs/common";
348
- var FbService = class {
349
- constructor(http) {
350
- this.http = http;
351
- }
352
- http;
353
- async getUserId(token) {
354
- const { data } = await this.http.get("https://graph.facebook.com/me?access_token=" + token).toPromise();
355
- return data.id;
356
- }
357
- async getData(token) {
358
- const { data } = await this.http.get(
359
- "https://graph.facebook.com/me?fields=email,id&access_token=" + token
360
- ).toPromise();
361
- return data;
362
- }
363
- };
364
- FbService = __decorateClass([
365
- Injectable4()
366
- ], FbService);
367
-
368
- // packages/shared/google/src/lib/google.service.ts
369
- import { Injectable as Injectable5 } from "@nestjs/common";
370
- var GoogleService = class {
371
- constructor(http) {
372
- this.http = http;
373
- }
374
- http;
375
- async getUserId(token) {
376
- const { data } = await this.http.get(
377
- "https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=" + token
378
- ).toPromise();
379
- return data.user_id;
380
- }
381
- async getData(token) {
382
- const { data } = await this.http.get(
383
- "https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=" + token
384
- ).toPromise();
385
- return {
386
- id: data.user_id,
387
- email: data.email
388
- };
389
- }
390
- };
391
- GoogleService = __decorateClass([
392
- Injectable5()
393
- ], GoogleService);
394
-
395
- // packages/auth/shell/nestjs/src/lib/nestjs.module.ts
396
- var AuthShellNestjsModule = class {
397
- static forRoot(options) {
398
- return {
399
- module: AuthShellNestjsModule,
400
- controllers: [TokenController],
401
- providers: [
402
- { provide: TokenConfig, useValue: options.tokenConfig },
403
- AuthService,
404
- FbService,
405
- GoogleService,
406
- ...DOMAIN_SERVICES
407
- ],
408
- imports: [
409
- HttpModule,
410
- TypeOrmModule.forFeature(ENTITIES),
411
- PassportModule.register({ defaultStrategy: "jwt", session: false }),
412
- JwtModule.register({
413
- secret: options.tokenConfig.secretOrPrivateKey,
414
- signOptions: {
415
- expiresIn: options.tokenConfig.expiredIn
416
- }
417
- })
418
- ],
419
- exports: [FbService, GoogleService]
420
- };
421
- }
422
- };
423
- AuthShellNestjsModule = __decorateClass([
424
- Module({})
425
- ], AuthShellNestjsModule);
426
- var AuthShellNestjsCoreModule = class {
427
- static forRoot(options) {
428
- return {
429
- module: AuthShellNestjsModule,
430
- providers: [
431
- { provide: TokenConfig, useValue: options.tokenConfig },
432
- AuthService,
433
- ...DOMAIN_SERVICES
434
- ],
435
- exports: [
436
- AuthService,
437
- ...DOMAIN_SERVICES,
438
- { provide: TokenConfig, useValue: options.tokenConfig }
439
- ],
440
- imports: [
441
- TypeOrmModule.forFeature(ENTITIES),
442
- PassportModule.register({ defaultStrategy: "jwt", session: false }),
443
- JwtModule.register({
444
- secret: options.tokenConfig.secretOrPrivateKey,
445
- signOptions: {
446
- expiresIn: options.tokenConfig.expiredIn
447
- }
448
- })
449
- ]
450
- };
451
- }
452
- };
453
- AuthShellNestjsCoreModule = __decorateClass([
454
- Module({})
455
- ], AuthShellNestjsCoreModule);
456
- export {
457
- AuthShellNestjsCoreModule,
458
- AuthShellNestjsModule,
459
- TokenController
460
- };