@mondomob/gae-node-nestjs 12.0.0-alpha-2 → 12.0.0-alpha-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/_test/mocks.d.ts +9 -0
- package/dist/_test/mocks.js +27 -0
- package/dist/_test/mocks.js.map +1 -0
- package/dist/_test/request-scope-test-utils.d.ts +3 -0
- package/dist/_test/request-scope-test-utils.js +18 -0
- package/dist/_test/request-scope-test-utils.js.map +1 -0
- package/dist/auth/auth-user.model.d.ts +9 -0
- package/dist/auth/auth-user.model.js +33 -0
- package/dist/auth/auth-user.model.js.map +1 -0
- package/dist/auth/auth.callbacks.d.ts +8 -0
- package/dist/auth/auth.callbacks.js +5 -0
- package/dist/auth/auth.callbacks.js.map +1 -0
- package/dist/auth/auth.configurer.d.ts +35 -0
- package/dist/auth/auth.configurer.js +212 -0
- package/dist/auth/auth.configurer.js.map +1 -0
- package/dist/auth/auth.controller.d.ts +27 -0
- package/dist/auth/auth.controller.js +312 -0
- package/dist/auth/auth.controller.js.map +1 -0
- package/dist/auth/auth.guard.d.ts +16 -0
- package/dist/auth/auth.guard.js +127 -0
- package/dist/auth/auth.guard.js.map +1 -0
- package/dist/auth/auth.listener.d.ts +5 -0
- package/dist/auth/auth.listener.js +5 -0
- package/dist/auth/auth.listener.js.map +1 -0
- package/dist/auth/auth.repository.d.ts +52 -0
- package/dist/auth/auth.repository.js +79 -0
- package/dist/auth/auth.repository.js.map +1 -0
- package/dist/auth/auth.resolver.d.ts +13 -0
- package/dist/auth/auth.resolver.js +86 -0
- package/dist/auth/auth.resolver.js.map +1 -0
- package/dist/auth/auth.service.d.ts +35 -0
- package/dist/auth/auth.service.js +299 -0
- package/dist/auth/auth.service.js.map +1 -0
- package/dist/auth/auth.task.controller.d.ts +13 -0
- package/dist/auth/auth.task.controller.js +76 -0
- package/dist/auth/auth.task.controller.js.map +1 -0
- package/dist/auth/auth.task.service.d.ts +8 -0
- package/dist/auth/auth.task.service.js +26 -0
- package/dist/auth/auth.task.service.js.map +1 -0
- package/dist/auth/csrf.interceptor.d.ts +11 -0
- package/dist/auth/csrf.interceptor.js +38 -0
- package/dist/auth/csrf.interceptor.js.map +1 -0
- package/dist/auth/invite-user.service.d.ts +45 -0
- package/dist/auth/invite-user.service.js +215 -0
- package/dist/auth/invite-user.service.js.map +1 -0
- package/dist/auth/invite.callbacks.d.ts +6 -0
- package/dist/auth/invite.callbacks.js +5 -0
- package/dist/auth/invite.callbacks.js.map +1 -0
- package/dist/auth/login-identifier.repository.d.ts +13 -0
- package/dist/auth/login-identifier.repository.js +28 -0
- package/dist/auth/login-identifier.repository.js.map +1 -0
- package/dist/auth/password-reset.service.d.ts +15 -0
- package/dist/auth/password-reset.service.js +81 -0
- package/dist/auth/password-reset.service.js.map +1 -0
- package/dist/auth/user.service.d.ts +27 -0
- package/dist/auth/user.service.js +94 -0
- package/dist/auth/user.service.js.map +1 -0
- package/dist/configuration.d.ts +84 -0
- package/dist/configuration.js +5 -0
- package/dist/configuration.js.map +1 -0
- package/dist/configure.d.ts +40 -0
- package/dist/configure.js +85 -0
- package/dist/configure.js.map +1 -0
- package/dist/context/context-middleware.d.ts +15 -0
- package/dist/context/context-middleware.js +37 -0
- package/dist/context/context-middleware.js.map +1 -0
- package/dist/context/context-request-scope.d.ts +8 -0
- package/dist/context/context-request-scope.js +29 -0
- package/dist/context/context-request-scope.js.map +1 -0
- package/dist/context/index.d.ts +2 -0
- package/dist/context/index.js +9 -0
- package/dist/context/index.js.map +1 -0
- package/dist/datastore/context.d.ts +36 -0
- package/dist/datastore/context.js +27 -0
- package/dist/datastore/context.js.map +1 -0
- package/dist/datastore/datastore.provider.d.ts +8 -0
- package/dist/datastore/datastore.provider.js +30 -0
- package/dist/datastore/datastore.provider.js.map +1 -0
- package/dist/datastore/filters.d.ts +19 -0
- package/dist/datastore/filters.js +27 -0
- package/dist/datastore/filters.js.map +1 -0
- package/dist/datastore/loader.d.ts +50 -0
- package/dist/datastore/loader.js +147 -0
- package/dist/datastore/loader.js.map +1 -0
- package/dist/datastore/node-datastore-session.d.ts +17 -0
- package/dist/datastore/node-datastore-session.js +87 -0
- package/dist/datastore/node-datastore-session.js.map +1 -0
- package/dist/datastore/repository.d.ts +45 -0
- package/dist/datastore/repository.js +150 -0
- package/dist/datastore/repository.js.map +1 -0
- package/dist/datastore/transactional.d.ts +4 -0
- package/dist/datastore/transactional.js +13 -0
- package/dist/datastore/transactional.js.map +1 -0
- package/dist/error/NonFatalError.d.ts +3 -0
- package/dist/error/NonFatalError.js +11 -0
- package/dist/error/NonFatalError.js.map +1 -0
- package/dist/filter.d.ts +5 -0
- package/dist/filter.js +40 -0
- package/dist/filter.js.map +1 -0
- package/dist/gcloud/logging.d.ts +1 -0
- package/dist/gcloud/logging.js +5 -0
- package/dist/gcloud/logging.js.map +1 -0
- package/dist/gcloud/storage.provider.d.ts +12 -0
- package/dist/gcloud/storage.provider.js +41 -0
- package/dist/gcloud/storage.provider.js.map +1 -0
- package/dist/gcloud/tasks.d.ts +10 -0
- package/dist/gcloud/tasks.js +68 -0
- package/dist/gcloud/tasks.js.map +1 -0
- package/dist/graphql/GraphQLMiddleware.d.ts +0 -0
- package/dist/graphql/GraphQLMiddleware.js +2 -0
- package/dist/graphql/GraphQLMiddleware.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -0
- package/dist/logging/index.d.ts +1 -0
- package/dist/logging/index.js +8 -0
- package/dist/logging/index.js.map +1 -0
- package/dist/logging/logging-internal.d.ts +2 -0
- package/dist/logging/logging-internal.js +20 -0
- package/dist/logging/logging-internal.js.map +1 -0
- package/dist/logging/logging-request-scope.d.ts +15 -0
- package/dist/logging/logging-request-scope.js +39 -0
- package/dist/logging/logging-request-scope.js.map +1 -0
- package/dist/logging/logging.d.ts +34 -0
- package/dist/logging/logging.js +55 -0
- package/dist/logging/logging.js.map +1 -0
- package/dist/mail/gmail/gmail.configurer.d.ts +15 -0
- package/dist/mail/gmail/gmail.configurer.js +59 -0
- package/dist/mail/gmail/gmail.configurer.js.map +1 -0
- package/dist/mail/gmail/gmail.controller.d.ts +9 -0
- package/dist/mail/gmail/gmail.controller.js +62 -0
- package/dist/mail/gmail/gmail.controller.js.map +1 -0
- package/dist/mail/gmail/gmail.sender.d.ts +12 -0
- package/dist/mail/gmail/gmail.sender.js +62 -0
- package/dist/mail/gmail/gmail.sender.js.map +1 -0
- package/dist/mail/gmail/stored.credentials.repository.d.ts +12 -0
- package/dist/mail/gmail/stored.credentials.repository.js +23 -0
- package/dist/mail/gmail/stored.credentials.repository.js.map +1 -0
- package/dist/mail/mail-logging.sender.d.ts +9 -0
- package/dist/mail/mail-logging.sender.js +42 -0
- package/dist/mail/mail-logging.sender.js.map +1 -0
- package/dist/mail/mail-subject.sender.d.ts +12 -0
- package/dist/mail/mail-subject.sender.js +33 -0
- package/dist/mail/mail-subject.sender.js.map +1 -0
- package/dist/mail/mail-whitelist.sender.d.ts +14 -0
- package/dist/mail/mail-whitelist.sender.js +59 -0
- package/dist/mail/mail-whitelist.sender.js.map +1 -0
- package/dist/mail/mail.diverter.d.ts +13 -0
- package/dist/mail/mail.diverter.js +65 -0
- package/dist/mail/mail.diverter.js.map +1 -0
- package/dist/mail/mail.sender.d.ts +6 -0
- package/dist/mail/mail.sender.js +5 -0
- package/dist/mail/mail.sender.js.map +1 -0
- package/dist/mail/smtp/smtp.sender.d.ts +10 -0
- package/dist/mail/smtp/smtp.sender.js +65 -0
- package/dist/mail/smtp/smtp.sender.js.map +1 -0
- package/dist/mail-templates/base.d.ts +2 -0
- package/dist/mail-templates/base.js +328 -0
- package/dist/mail-templates/base.js.map +1 -0
- package/dist/mail-templates/invite.d.ts +1 -0
- package/dist/mail-templates/invite.js +19 -0
- package/dist/mail-templates/invite.js.map +1 -0
- package/dist/module.d.ts +16 -0
- package/dist/module.js +136 -0
- package/dist/module.js.map +1 -0
- package/dist/request-scope/index.d.ts +2 -0
- package/dist/request-scope/index.js +9 -0
- package/dist/request-scope/index.js.map +1 -0
- package/dist/request-scope/request-scope-interceptor.d.ts +5 -0
- package/dist/request-scope/request-scope-interceptor.js +3 -0
- package/dist/request-scope/request-scope-interceptor.js.map +1 -0
- package/dist/request-scope/request-scope.d.ts +12 -0
- package/dist/request-scope/request-scope.js +79 -0
- package/dist/request-scope/request-scope.js.map +1 -0
- package/dist/request-scope/request-scope.middleware.d.ts +15 -0
- package/dist/request-scope/request-scope.middleware.js +53 -0
- package/dist/request-scope/request-scope.middleware.js.map +1 -0
- package/dist/search/search.service.d.ts +52 -0
- package/dist/search/search.service.js +90 -0
- package/dist/search/search.service.js.map +1 -0
- package/dist/search/searchable.repository.d.ts +36 -0
- package/dist/search/searchable.repository.js +95 -0
- package/dist/search/searchable.repository.js.map +1 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/util/arrays.d.ts +1 -0
- package/dist/util/arrays.js +10 -0
- package/dist/util/arrays.js.map +1 -0
- package/dist/util/guards.d.ts +1 -0
- package/dist/util/guards.js +7 -0
- package/dist/util/guards.js.map +1 -0
- package/dist/util/index.d.ts +1 -0
- package/dist/util/index.js +5 -0
- package/dist/util/index.js.map +1 -0
- package/dist/util/nestjs.d.ts +9 -0
- package/dist/util/nestjs.js +9 -0
- package/dist/util/nestjs.js.map +1 -0
- package/dist/util/types.d.ts +4 -0
- package/dist/util/types.js +8 -0
- package/dist/util/types.js.map +1 -0
- package/dist/validator.d.ts +1 -0
- package/dist/validator.js +5 -0
- package/dist/validator.js.map +1 -0
- package/mondomob-gae-node-nestjs-12.0.0-alpha-3.tgz +0 -0
- package/package.json +1 -1
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthResolver = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
6
|
+
const auth_guard_1 = require("./auth.guard");
|
|
7
|
+
const invite_user_service_1 = require("./invite-user.service");
|
|
8
|
+
const password_reset_service_1 = require("./password-reset.service");
|
|
9
|
+
let AuthResolver = class AuthResolver {
|
|
10
|
+
constructor(passwordResetService, inviteUserService) {
|
|
11
|
+
this.passwordResetService = passwordResetService;
|
|
12
|
+
this.inviteUserService = inviteUserService;
|
|
13
|
+
}
|
|
14
|
+
async resetPassword(_req, email, context) {
|
|
15
|
+
return await this.passwordResetService.resetPassword(context, email);
|
|
16
|
+
}
|
|
17
|
+
async confirmResetPassword(_req, newPassword, code, context) {
|
|
18
|
+
return await this.passwordResetService.confirmResetPassword(context, code, newPassword);
|
|
19
|
+
}
|
|
20
|
+
async inviteUser(_req, roles, email, context) {
|
|
21
|
+
const { user: { id }, } = await this.inviteUserService.inviteUser(context, { email, roles });
|
|
22
|
+
return id;
|
|
23
|
+
}
|
|
24
|
+
async checkActivationCode(_req, code, context) {
|
|
25
|
+
return this.inviteUserService.checkActivationCode(context, code);
|
|
26
|
+
}
|
|
27
|
+
async activateAccount(_req, password, name, code, context) {
|
|
28
|
+
await this.inviteUserService.activateAccount(context, code, name, password);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.AuthResolver = AuthResolver;
|
|
32
|
+
tslib_1.__decorate([
|
|
33
|
+
(0, auth_guard_1.AllowAnonymous)(),
|
|
34
|
+
(0, graphql_1.Mutation)(() => Boolean, { nullable: true }),
|
|
35
|
+
tslib_1.__param(1, (0, graphql_1.Args)('email')),
|
|
36
|
+
tslib_1.__param(2, (0, graphql_1.Context)()),
|
|
37
|
+
tslib_1.__metadata("design:type", Function),
|
|
38
|
+
tslib_1.__metadata("design:paramtypes", [void 0, String, Object]),
|
|
39
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
40
|
+
], AuthResolver.prototype, "resetPassword", null);
|
|
41
|
+
tslib_1.__decorate([
|
|
42
|
+
(0, auth_guard_1.AllowAnonymous)(),
|
|
43
|
+
(0, graphql_1.Mutation)(() => Boolean, { nullable: true }),
|
|
44
|
+
tslib_1.__param(1, (0, graphql_1.Args)('newPassword')),
|
|
45
|
+
tslib_1.__param(2, (0, graphql_1.Args)('code')),
|
|
46
|
+
tslib_1.__param(3, (0, graphql_1.Context)()),
|
|
47
|
+
tslib_1.__metadata("design:type", Function),
|
|
48
|
+
tslib_1.__metadata("design:paramtypes", [void 0, String, String, Object]),
|
|
49
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
50
|
+
], AuthResolver.prototype, "confirmResetPassword", null);
|
|
51
|
+
tslib_1.__decorate([
|
|
52
|
+
(0, auth_guard_1.Roles)('admin'),
|
|
53
|
+
(0, graphql_1.Mutation)(() => String),
|
|
54
|
+
tslib_1.__param(1, (0, graphql_1.Args)('roles', { type: () => [String] })),
|
|
55
|
+
tslib_1.__param(2, (0, graphql_1.Args)('email')),
|
|
56
|
+
tslib_1.__param(3, (0, graphql_1.Context)()),
|
|
57
|
+
tslib_1.__metadata("design:type", Function),
|
|
58
|
+
tslib_1.__metadata("design:paramtypes", [void 0, Array, String, Object]),
|
|
59
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
60
|
+
], AuthResolver.prototype, "inviteUser", null);
|
|
61
|
+
tslib_1.__decorate([
|
|
62
|
+
(0, auth_guard_1.AllowAnonymous)(),
|
|
63
|
+
(0, graphql_1.Query)(() => String, { nullable: true }),
|
|
64
|
+
tslib_1.__param(1, (0, graphql_1.Args)('code')),
|
|
65
|
+
tslib_1.__param(2, (0, graphql_1.Context)()),
|
|
66
|
+
tslib_1.__metadata("design:type", Function),
|
|
67
|
+
tslib_1.__metadata("design:paramtypes", [void 0, String, Object]),
|
|
68
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
69
|
+
], AuthResolver.prototype, "checkActivationCode", null);
|
|
70
|
+
tslib_1.__decorate([
|
|
71
|
+
(0, auth_guard_1.AllowAnonymous)(),
|
|
72
|
+
(0, graphql_1.Mutation)(() => Boolean, { nullable: true }),
|
|
73
|
+
tslib_1.__param(1, (0, graphql_1.Args)('password')),
|
|
74
|
+
tslib_1.__param(2, (0, graphql_1.Args)('name')),
|
|
75
|
+
tslib_1.__param(3, (0, graphql_1.Args)('code')),
|
|
76
|
+
tslib_1.__param(4, (0, graphql_1.Context)()),
|
|
77
|
+
tslib_1.__metadata("design:type", Function),
|
|
78
|
+
tslib_1.__metadata("design:paramtypes", [void 0, String, String, String, Object]),
|
|
79
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
80
|
+
], AuthResolver.prototype, "activateAccount", null);
|
|
81
|
+
exports.AuthResolver = AuthResolver = tslib_1.__decorate([
|
|
82
|
+
(0, graphql_1.Resolver)(),
|
|
83
|
+
tslib_1.__metadata("design:paramtypes", [password_reset_service_1.PasswordResetService,
|
|
84
|
+
invite_user_service_1.InviteUserService])
|
|
85
|
+
], AuthResolver);
|
|
86
|
+
//# sourceMappingURL=auth.resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.resolver.js","sourceRoot":"","sources":["../../src/auth/auth.resolver.ts"],"names":[],"mappings":";;;;AAAA,6CAAyF;AACzF,6CAAqD;AACrD,+DAA0D;AAC1D,qEAAgE;AAIzD,IAAM,YAAY,GAAlB,MAAM,YAAY;IACvB,YACmB,oBAA0C,EAC1C,iBAAoC;QADpC,yBAAoB,GAApB,oBAAoB,CAAsB;QAC1C,sBAAiB,GAAjB,iBAAiB,CAAmB;IACpD,CAAC;IAIE,AAAN,KAAK,CAAC,aAAa,CAAC,IAAU,EAAiB,KAAa,EAAgB,OAAgB;QAC1F,OAAO,MAAM,IAAI,CAAC,oBAAoB,CAAC,aAAa,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACvE,CAAC;IAIK,AAAN,KAAK,CAAC,oBAAoB,CACxB,IAAU,EACW,WAAmB,EAC1B,IAAY,EACZ,OAAgB;QAE9B,OAAO,MAAM,IAAI,CAAC,oBAAoB,CAAC,oBAAoB,CAAC,OA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IK;IAFL,IAAA,kBAAK,EAAC,OAAO,CAAC;IACd,IAAA,kBAAQ,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAGpB,mBAAA,IAAA,cAAI,EAAC,OAAO,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,MAAO,CAAC,EAAE,CAAC,CAAA;IACxC,mBAAA,IAAA,cAAI,EAAC,OAAO,CAAC,CAAA;IACb,mBAAA,IAAA,iBAAU,GAAE,CAAA;;;;8CAMd;AAIK;IAFL,IAAA,2BAAc,GAAE;IAChB,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAGrC,mBAAA,IAAA,cAAI,EAAC,MAAM,CAAC,CAAA;IACZ,mBAAA,IAAA,iBAAU,GAAE,CAAA;;;;uDAGd;AAIK;IAFL,IAAA,2BAAc,GAAE;IAChB,IAAA,kBAAQ,EAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAGzC,mBAAA,IAAA,cAAI,EAAC,UAAU,CAAC,CAAA;IAChB,mBAAA,IAAA,cAAI,EAAC,MAAM,CAAC,CAAA;IACZ,mBAAA,IAAA,cAAI,EAAC,MAAM,CAAC,CAAA;IACZ,mBAAA,IAAA,iBAAU,GAAE,CAAA;;;;mDAGd;uBAzDU,YAAY;IADxB,IAAA,kBAAQ,GAAE;6CAGgC,6CAAoB;QACvB,uCAAiB;GAH5C,YAAY,CA0DxB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { HttpException } from '@nestjs/common';
|
|
2
|
+
import { Configuration } from '../configuration';
|
|
3
|
+
import { CredentialRepository, LoginCredentials } from './auth.repository';
|
|
4
|
+
import { UserService } from './user.service';
|
|
5
|
+
import { AuthCallbacks } from './auth.callbacks';
|
|
6
|
+
import { Context, IUser } from '../datastore/context';
|
|
7
|
+
export declare class AuthenticationFailedException extends HttpException {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
export declare function hashPassword(password: string): Promise<string>;
|
|
11
|
+
export declare class AuthService {
|
|
12
|
+
private readonly authRepository;
|
|
13
|
+
private readonly userService;
|
|
14
|
+
private readonly configurationProvider;
|
|
15
|
+
private readonly authCallbacks;
|
|
16
|
+
private readonly logger;
|
|
17
|
+
constructor(authRepository: CredentialRepository, userService: UserService<IUser>, configurationProvider: Configuration, authCallbacks: AuthCallbacks);
|
|
18
|
+
validateUser(context: Context, username: string, password: string): Promise<IUser>;
|
|
19
|
+
validateFakeLogin(context: Context, secret: string | string[] | undefined, email: string, name: string, roles: string[], orgId: string, props: any): Promise<IUser>;
|
|
20
|
+
validateUserGoogle(context: Context, inputProfile: object): Promise<IUser>;
|
|
21
|
+
validateUserSaml(context: Context, profile: SimpleUserProfile): Promise<IUser>;
|
|
22
|
+
validateUserOidc(context: Context, profile: any, overwriteCredentials: boolean, newUserRoles?: string[]): Promise<IUser>;
|
|
23
|
+
validateUserAuth0(context: Context, id: string, email: string, name: string, orgId: string, roles: string[], props: any): Promise<IUser>;
|
|
24
|
+
createAccount(context: Context, email: string, password: string, account: string): Promise<LoginCredentials>;
|
|
25
|
+
private validateOrCreateExternalAuthAccount;
|
|
26
|
+
private loadUserAndCheckEnabled;
|
|
27
|
+
private validateUserEnabled;
|
|
28
|
+
private getAccountByEmail;
|
|
29
|
+
private toName;
|
|
30
|
+
}
|
|
31
|
+
export interface SimpleUserProfile {
|
|
32
|
+
email: string;
|
|
33
|
+
firstName?: string;
|
|
34
|
+
lastName?: string;
|
|
35
|
+
}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthService = exports.AuthenticationFailedException = void 0;
|
|
4
|
+
exports.hashPassword = hashPassword;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const bcrypt = require("bcryptjs");
|
|
8
|
+
const emails = require("email-addresses");
|
|
9
|
+
const t = require("io-ts");
|
|
10
|
+
const io_ts_reporters_1 = require("io-ts-reporters");
|
|
11
|
+
const lodash_1 = require("lodash");
|
|
12
|
+
const configuration_1 = require("../configuration");
|
|
13
|
+
const auth_repository_1 = require("./auth.repository");
|
|
14
|
+
const user_service_1 = require("./user.service");
|
|
15
|
+
const auth_callbacks_1 = require("./auth.callbacks");
|
|
16
|
+
const logging_1 = require("../logging");
|
|
17
|
+
const transactional_1 = require("../datastore/transactional");
|
|
18
|
+
const Either_1 = require("fp-ts/lib/Either");
|
|
19
|
+
const userProfile = t.type({
|
|
20
|
+
id: t.string,
|
|
21
|
+
emails: t.array(t.interface({
|
|
22
|
+
value: t.string,
|
|
23
|
+
verified: t.boolean,
|
|
24
|
+
})),
|
|
25
|
+
displayName: t.string,
|
|
26
|
+
});
|
|
27
|
+
class AuthenticationFailedException extends common_1.HttpException {
|
|
28
|
+
constructor(message) {
|
|
29
|
+
super(message, common_1.HttpStatus.UNAUTHORIZED);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.AuthenticationFailedException = AuthenticationFailedException;
|
|
33
|
+
const SALT_LENGTH = 10;
|
|
34
|
+
async function hashPassword(password) {
|
|
35
|
+
return await bcrypt.hash(password, SALT_LENGTH);
|
|
36
|
+
}
|
|
37
|
+
let AuthService = class AuthService {
|
|
38
|
+
constructor(authRepository, userService, configurationProvider, authCallbacks) {
|
|
39
|
+
this.authRepository = authRepository;
|
|
40
|
+
this.userService = userService;
|
|
41
|
+
this.configurationProvider = configurationProvider;
|
|
42
|
+
this.authCallbacks = authCallbacks;
|
|
43
|
+
this.logger = (0, logging_1.createLogger)('account-service');
|
|
44
|
+
}
|
|
45
|
+
async validateUser(context, username, password) {
|
|
46
|
+
const account = await this.getAccountByEmail(context, username);
|
|
47
|
+
if (!account) {
|
|
48
|
+
throw new AuthenticationFailedException('No credentials found for user');
|
|
49
|
+
}
|
|
50
|
+
if (account.type !== 'password') {
|
|
51
|
+
throw new AuthenticationFailedException('No credentials found for user');
|
|
52
|
+
}
|
|
53
|
+
const result = await bcrypt.compare(password, account.password);
|
|
54
|
+
if (!result) {
|
|
55
|
+
throw new AuthenticationFailedException(`Invalid password for user`);
|
|
56
|
+
}
|
|
57
|
+
return await this.loadUserAndCheckEnabled(context, account.userId);
|
|
58
|
+
}
|
|
59
|
+
async validateFakeLogin(context, secret, email, name, roles, orgId, props) {
|
|
60
|
+
this.logger.info(`Validating fake login for ${email}`);
|
|
61
|
+
const configSecret = this.configurationProvider.auth.fake.secret;
|
|
62
|
+
if (configSecret && configSecret !== secret) {
|
|
63
|
+
throw new AuthenticationFailedException('Fake login secret invalid');
|
|
64
|
+
}
|
|
65
|
+
const user = await this.userService.getByEmail(context, email);
|
|
66
|
+
if (user) {
|
|
67
|
+
if (!user.enabled) {
|
|
68
|
+
throw new AuthenticationFailedException('User account is disabled');
|
|
69
|
+
}
|
|
70
|
+
return await this.userService.update(context, user.id, Object.assign(Object.assign({}, user), { name,
|
|
71
|
+
roles,
|
|
72
|
+
orgId,
|
|
73
|
+
props }));
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
return await this.userService.create(context, {
|
|
77
|
+
email,
|
|
78
|
+
name,
|
|
79
|
+
roles,
|
|
80
|
+
orgId,
|
|
81
|
+
props,
|
|
82
|
+
enabled: true,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async validateUserGoogle(context, inputProfile) {
|
|
87
|
+
const validationResult = userProfile.decode(inputProfile);
|
|
88
|
+
if ((0, Either_1.isLeft)(validationResult)) {
|
|
89
|
+
throw new Error(io_ts_reporters_1.default.report(validationResult).join(', '));
|
|
90
|
+
}
|
|
91
|
+
const profile = validationResult.right;
|
|
92
|
+
const accountEmails = profile.emails.find(accountEmail => accountEmail.verified);
|
|
93
|
+
if (!accountEmails) {
|
|
94
|
+
throw new AuthenticationFailedException('No credentials found for user');
|
|
95
|
+
}
|
|
96
|
+
const email = accountEmails.value;
|
|
97
|
+
const account = await this.getAccountByEmail(context, email);
|
|
98
|
+
if (!account) {
|
|
99
|
+
if (!this.configurationProvider.auth.google || !this.configurationProvider.auth.google.signUpEnabled) {
|
|
100
|
+
throw new AuthenticationFailedException('No credentials found for user');
|
|
101
|
+
}
|
|
102
|
+
const { domain } = emails.parseOneAddress(email);
|
|
103
|
+
const signUpDomains = this.configurationProvider.auth.google.signUpDomains || [];
|
|
104
|
+
if (!signUpDomains.includes(domain)) {
|
|
105
|
+
throw new AuthenticationFailedException('No credentials found for user');
|
|
106
|
+
}
|
|
107
|
+
const createdUser = await this.userService.create(context, {
|
|
108
|
+
roles: this.configurationProvider.auth.google.signUpRoles,
|
|
109
|
+
email,
|
|
110
|
+
name: profile.displayName,
|
|
111
|
+
enabled: true,
|
|
112
|
+
});
|
|
113
|
+
await this.authRepository.save(context, {
|
|
114
|
+
id: email,
|
|
115
|
+
type: 'google',
|
|
116
|
+
userId: createdUser.id,
|
|
117
|
+
});
|
|
118
|
+
return createdUser;
|
|
119
|
+
}
|
|
120
|
+
if (account.type !== 'google' && account.type !== 'password') {
|
|
121
|
+
throw new AuthenticationFailedException('No credentials found for user');
|
|
122
|
+
}
|
|
123
|
+
return await this.loadUserAndCheckEnabled(context, account.userId);
|
|
124
|
+
}
|
|
125
|
+
async validateUserSaml(context, profile) {
|
|
126
|
+
return this.validateOrCreateExternalAuthAccount(context, (0, user_service_1.normaliseEmail)(profile.email), {
|
|
127
|
+
type: 'saml',
|
|
128
|
+
newUserRequest: () => ({
|
|
129
|
+
roles: [],
|
|
130
|
+
email: profile.email,
|
|
131
|
+
name: this.toName(profile),
|
|
132
|
+
enabled: true,
|
|
133
|
+
}),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
async validateUserOidc(context, profile, overwriteCredentials, newUserRoles = []) {
|
|
137
|
+
const profileJson = profile['_json'];
|
|
138
|
+
const email = profile.email || (profileJson && profileJson.email);
|
|
139
|
+
let replaceRolesWithIdpRoles = false;
|
|
140
|
+
let roles = [];
|
|
141
|
+
if (this.authCallbacks && this.authCallbacks.buildUserRolesList) {
|
|
142
|
+
replaceRolesWithIdpRoles = true;
|
|
143
|
+
roles = this.authCallbacks.buildUserRolesList('oidc', profile);
|
|
144
|
+
}
|
|
145
|
+
let props = {};
|
|
146
|
+
if (this.authCallbacks && this.authCallbacks.buildUserPropertiesObject) {
|
|
147
|
+
props = this.authCallbacks.buildUserPropertiesObject('oidc', profile);
|
|
148
|
+
}
|
|
149
|
+
return this.validateOrCreateExternalAuthAccount(context, (0, user_service_1.normaliseEmail)(email), {
|
|
150
|
+
type: 'oidc',
|
|
151
|
+
overwriteCredentials,
|
|
152
|
+
newUserRequest: () => {
|
|
153
|
+
const userRoles = replaceRolesWithIdpRoles ? roles : newUserRoles;
|
|
154
|
+
return {
|
|
155
|
+
email,
|
|
156
|
+
name: profile.displayName,
|
|
157
|
+
roles: userRoles,
|
|
158
|
+
props,
|
|
159
|
+
enabled: true,
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
updateUser: user => {
|
|
163
|
+
const mergedProps = Object.assign(Object.assign({}, user.props), props);
|
|
164
|
+
const userRoles = replaceRolesWithIdpRoles ? roles : user.roles || [];
|
|
165
|
+
return this.userService.update(context, user.id, Object.assign(Object.assign({}, user), { roles: userRoles, props: mergedProps, name: profile.displayName }));
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
async validateUserAuth0(context, id, email, name, orgId, roles, props) {
|
|
170
|
+
this.logger.info('Validating auth0 account using login identifier: ', id);
|
|
171
|
+
return this.validateOrCreateExternalAuthAccount(context, id, {
|
|
172
|
+
type: 'auth0',
|
|
173
|
+
newUserRequest: () => ({
|
|
174
|
+
roles,
|
|
175
|
+
orgId,
|
|
176
|
+
email,
|
|
177
|
+
name,
|
|
178
|
+
props,
|
|
179
|
+
enabled: true,
|
|
180
|
+
}),
|
|
181
|
+
updateUser: user => {
|
|
182
|
+
user.name = name;
|
|
183
|
+
user.roles = roles;
|
|
184
|
+
user.orgId = orgId;
|
|
185
|
+
user.props = props;
|
|
186
|
+
user.email = email;
|
|
187
|
+
return this.userService.update(context, user.id, user);
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
async createAccount(context, email, password, account) {
|
|
192
|
+
const existingCredentials = await this.getAccountByEmail(context, email);
|
|
193
|
+
if (!existingCredentials) {
|
|
194
|
+
return await this.authRepository.save(context, {
|
|
195
|
+
id: email,
|
|
196
|
+
password: await hashPassword(password),
|
|
197
|
+
userId: account,
|
|
198
|
+
type: 'password',
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
return existingCredentials;
|
|
202
|
+
}
|
|
203
|
+
async validateOrCreateExternalAuthAccount(context, id, options) {
|
|
204
|
+
const { newUserRequest, updateUser, type } = options;
|
|
205
|
+
this.logger.info(`Validating ${type} user profile`);
|
|
206
|
+
const account = await this.authRepository.get(context, id);
|
|
207
|
+
if (!account) {
|
|
208
|
+
this.logger.info(`No login credentials found for ${id}, creating credentials and creating or updating user.`);
|
|
209
|
+
const updatedUser = await this.userService.createOrUpdate(context, newUserRequest(), this.validateUserEnabled);
|
|
210
|
+
await this.authRepository.save(context, {
|
|
211
|
+
id,
|
|
212
|
+
type,
|
|
213
|
+
userId: updatedUser.id,
|
|
214
|
+
});
|
|
215
|
+
return updatedUser;
|
|
216
|
+
}
|
|
217
|
+
if (!options.overwriteCredentials && account.type !== type) {
|
|
218
|
+
throw new AuthenticationFailedException('No credentials found for user');
|
|
219
|
+
}
|
|
220
|
+
const user = await this.loadUserAndCheckEnabled(context, account.userId);
|
|
221
|
+
if (account.type !== type) {
|
|
222
|
+
this.logger.info(`Updating auth type to [${type}] for [${id}]`);
|
|
223
|
+
await this.authRepository.save(context, {
|
|
224
|
+
id: account.id,
|
|
225
|
+
type,
|
|
226
|
+
userId: account.userId,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
this.logger.info(`User ${id} validated`);
|
|
230
|
+
return updateUser ? await updateUser(user) : user;
|
|
231
|
+
}
|
|
232
|
+
async loadUserAndCheckEnabled(context, userId) {
|
|
233
|
+
const user = await this.userService.get(context, userId);
|
|
234
|
+
if (!user) {
|
|
235
|
+
throw new AuthenticationFailedException('User not found');
|
|
236
|
+
}
|
|
237
|
+
this.validateUserEnabled(user);
|
|
238
|
+
return user;
|
|
239
|
+
}
|
|
240
|
+
validateUserEnabled(user) {
|
|
241
|
+
if (!user.enabled) {
|
|
242
|
+
throw new AuthenticationFailedException('User account is disabled');
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
getAccountByEmail(context, email) {
|
|
246
|
+
const normalisedEmail = (0, user_service_1.normaliseEmail)(email);
|
|
247
|
+
this.logger.info(`Looking up user by email ${normalisedEmail}`);
|
|
248
|
+
return this.authRepository.get(context, normalisedEmail);
|
|
249
|
+
}
|
|
250
|
+
toName(profile) {
|
|
251
|
+
return [profile.firstName, profile.lastName].filter(part => !(0, lodash_1.isNil)(part)).join(' ');
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
exports.AuthService = AuthService;
|
|
255
|
+
tslib_1.__decorate([
|
|
256
|
+
(0, transactional_1.Transactional)(),
|
|
257
|
+
tslib_1.__metadata("design:type", Function),
|
|
258
|
+
tslib_1.__metadata("design:paramtypes", [Object, Object, String, String, Array, String, Object]),
|
|
259
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
260
|
+
], AuthService.prototype, "validateFakeLogin", null);
|
|
261
|
+
tslib_1.__decorate([
|
|
262
|
+
(0, transactional_1.Transactional)(),
|
|
263
|
+
tslib_1.__metadata("design:type", Function),
|
|
264
|
+
tslib_1.__metadata("design:paramtypes", [Object, Object]),
|
|
265
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
266
|
+
], AuthService.prototype, "validateUserGoogle", null);
|
|
267
|
+
tslib_1.__decorate([
|
|
268
|
+
(0, transactional_1.Transactional)(),
|
|
269
|
+
tslib_1.__metadata("design:type", Function),
|
|
270
|
+
tslib_1.__metadata("design:paramtypes", [Object, Object]),
|
|
271
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
272
|
+
], AuthService.prototype, "validateUserSaml", null);
|
|
273
|
+
tslib_1.__decorate([
|
|
274
|
+
(0, transactional_1.Transactional)(),
|
|
275
|
+
tslib_1.__metadata("design:type", Function),
|
|
276
|
+
tslib_1.__metadata("design:paramtypes", [Object, Object, Boolean, Array]),
|
|
277
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
278
|
+
], AuthService.prototype, "validateUserOidc", null);
|
|
279
|
+
tslib_1.__decorate([
|
|
280
|
+
(0, transactional_1.Transactional)(),
|
|
281
|
+
tslib_1.__metadata("design:type", Function),
|
|
282
|
+
tslib_1.__metadata("design:paramtypes", [Object, String, String, String, String, Array, Object]),
|
|
283
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
284
|
+
], AuthService.prototype, "validateUserAuth0", null);
|
|
285
|
+
tslib_1.__decorate([
|
|
286
|
+
(0, transactional_1.Transactional)(),
|
|
287
|
+
tslib_1.__metadata("design:type", Function),
|
|
288
|
+
tslib_1.__metadata("design:paramtypes", [Object, String, String, String]),
|
|
289
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
290
|
+
], AuthService.prototype, "createAccount", null);
|
|
291
|
+
exports.AuthService = AuthService = tslib_1.__decorate([
|
|
292
|
+
(0, common_1.Injectable)(),
|
|
293
|
+
tslib_1.__param(1, (0, common_1.Inject)(user_service_1.USER_SERVICE)),
|
|
294
|
+
tslib_1.__param(2, (0, common_1.Inject)(configuration_1.CONFIGURATION)),
|
|
295
|
+
tslib_1.__param(3, (0, common_1.Optional)()),
|
|
296
|
+
tslib_1.__param(3, (0, common_1.Inject)(auth_callbacks_1.AUTH_CALLBACKS)),
|
|
297
|
+
tslib_1.__metadata("design:paramtypes", [auth_repository_1.CredentialRepository, Object, Object, Object])
|
|
298
|
+
], AuthService);
|
|
299
|
+
//# sourceMappingURL=auth.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../src/auth/auth.service.ts"],"names":[],"mappings":";;;AAiCA,oCAEC;;AAnCD,2CAAyF;AACzF,mCAAmC;AACnC,0CAA0C;AAC1C,2BAA2B;AAC3B,qDAA2C;AAC3C,mCAA+B;AAC/B,oDAAgE;AAChE,uDAA6F;AAC7F,iDAA2E;AAC3E,qDAAiE;AACjE,wCAAkD;AAElD,8DAA2D;AAC3D,6CAA0C;AAE1C,MAAM,WAAW,GAAG,CAAC,CAAC,IAAI,CAAC;IACzB,EAAE,EAAE,CAAC,CAAC,MAAM;IACZ,MAAM,EAAE,CAAC,CAAC,KAAK,CACb,CAAC,CAAC,SAAS,CAAC;QACV,KAAK,EAAE,CAAC,CAAC,MAAM;QACf,QAAQ,EAAE,CAAC,CAAC,OAAO;KACpB,CAAC,CACH;IACD,WAAW,EAAE,CAAC,CAAC,MAAM;CACtB,CAAC,CAAC;AAEH,MAAa,6BAA8B,SAAQ,sBAAa;IAC9D,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,mBAAU,CAAC,YAAY,CAAC,CAAC;IAC1C,CAAC;CACF;AAJD,sEAIC;AACD,MAAM,WAAW,GAAG,EAAE,CAAC;AAEhB,KAAK,UAAU,YAAY,CAAC,QAAgB;IACjD,OAAO,MAAM,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;AAClD,CAAC;AAGM,IAAM,WAAW,GAAjB,MAAM,WAAW;IAGtB,YACmB,cAAoC,EACd,WAA+B,EAC9B,qBAAoC,EACvB,aAA4B;QAHhE,mBAAc,GAAd,cAAc,CAAsB;QACd,gBAAW,GAAX,WAAW,CAAoB;QAC9B,0BAAqB,GAArB,qBAAqB,CAAe;QACvB,kBAAa,GAAb,aAAa,CAAe;QAEjF,IAAI,CAAC,MAAM,GAAG,IAAA,sBAAY,EAAC,iBAAi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,GAAE,CAAA;IAAE,mBAAA,IAAA,eAAM,EAAC,+BAAc,CAAC,CAAA;6CAHF,sCAAoB;GAJ5C,WAAW,CA+VvB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MailSender } from '../mail/mail.sender';
|
|
2
|
+
import { Context } from '../datastore/context';
|
|
3
|
+
import { Configuration } from '../configuration';
|
|
4
|
+
export declare class AuthTaskController {
|
|
5
|
+
private readonly configuration;
|
|
6
|
+
private readonly mailSender;
|
|
7
|
+
private readonly logger;
|
|
8
|
+
constructor(configuration: Configuration, mailSender: MailSender);
|
|
9
|
+
sendActivationEmail(context: Context, inviteId: string, email: string): Promise<void>;
|
|
10
|
+
sendPasswordResetEmail(context: Context, resetId: string, email: string): Promise<void>;
|
|
11
|
+
private getActivationExpiryEmailCopy;
|
|
12
|
+
private getInvitationCopy;
|
|
13
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthTaskController = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const auth_guard_1 = require("./auth.guard");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const mail_sender_1 = require("../mail/mail.sender");
|
|
8
|
+
const context_1 = require("../datastore/context");
|
|
9
|
+
const configuration_1 = require("../configuration");
|
|
10
|
+
const invite_1 = require("../mail-templates/invite");
|
|
11
|
+
const logging_1 = require("../logging");
|
|
12
|
+
const DEFAULT_INVITE_CODE_EXPIRY_EMAIL_COPY = '7 days';
|
|
13
|
+
const DEFAULT_INVITATION_EMAIL_COPY = 'You have been invited as a new user.';
|
|
14
|
+
let AuthTaskController = class AuthTaskController {
|
|
15
|
+
constructor(configuration, mailSender) {
|
|
16
|
+
this.configuration = configuration;
|
|
17
|
+
this.mailSender = mailSender;
|
|
18
|
+
this.getActivationExpiryEmailCopy = () => !(this.configuration.auth.local && this.configuration.auth.local.activationExpiryInMinutes)
|
|
19
|
+
? DEFAULT_INVITE_CODE_EXPIRY_EMAIL_COPY
|
|
20
|
+
: this.configuration.auth.local.activationExpiryEmailCopy;
|
|
21
|
+
this.getInvitationCopy = () => !(this.configuration.auth.local && this.configuration.auth.local.invitationEmailCopy)
|
|
22
|
+
? DEFAULT_INVITATION_EMAIL_COPY
|
|
23
|
+
: this.configuration.auth.local.invitationEmailCopy;
|
|
24
|
+
this.logger = (0, logging_1.createLogger)('auth-task-controller');
|
|
25
|
+
}
|
|
26
|
+
async sendActivationEmail(context, inviteId, email) {
|
|
27
|
+
const activateLink = `${this.configuration.host}/activate/${inviteId}`;
|
|
28
|
+
this.logger.info(`Sending invitation email to ${email} with link ${activateLink}`);
|
|
29
|
+
const title = 'Activate your account';
|
|
30
|
+
await this.mailSender.send(context, {
|
|
31
|
+
to: email,
|
|
32
|
+
subject: title,
|
|
33
|
+
html: (0, invite_1.userInviteEmail)(title, activateLink, this.getInvitationCopy(), this.getActivationExpiryEmailCopy()),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
async sendPasswordResetEmail(context, resetId, email) {
|
|
37
|
+
const address = `${this.configuration.host}/confirm-reset/${resetId}`;
|
|
38
|
+
await this.mailSender.send(context, {
|
|
39
|
+
to: email,
|
|
40
|
+
subject: 'Password reset',
|
|
41
|
+
html: `
|
|
42
|
+
<html>
|
|
43
|
+
<head></head>
|
|
44
|
+
<body><a href="${address}">Reset your password</a></body>
|
|
45
|
+
</html>
|
|
46
|
+
`,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
exports.AuthTaskController = AuthTaskController;
|
|
51
|
+
tslib_1.__decorate([
|
|
52
|
+
(0, common_1.Post)('/activation-email'),
|
|
53
|
+
tslib_1.__param(0, (0, context_1.Ctxt)()),
|
|
54
|
+
tslib_1.__param(1, (0, common_1.Body)('inviteId')),
|
|
55
|
+
tslib_1.__param(2, (0, common_1.Body)('email')),
|
|
56
|
+
tslib_1.__metadata("design:type", Function),
|
|
57
|
+
tslib_1.__metadata("design:paramtypes", [Object, String, String]),
|
|
58
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
59
|
+
], AuthTaskController.prototype, "sendActivationEmail", null);
|
|
60
|
+
tslib_1.__decorate([
|
|
61
|
+
(0, common_1.Post)('/password-reset-email'),
|
|
62
|
+
tslib_1.__param(0, (0, context_1.Ctxt)()),
|
|
63
|
+
tslib_1.__param(1, (0, common_1.Body)('resetId')),
|
|
64
|
+
tslib_1.__param(2, (0, common_1.Body)('email')),
|
|
65
|
+
tslib_1.__metadata("design:type", Function),
|
|
66
|
+
tslib_1.__metadata("design:paramtypes", [Object, String, String]),
|
|
67
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
68
|
+
], AuthTaskController.prototype, "sendPasswordResetEmail", null);
|
|
69
|
+
exports.AuthTaskController = AuthTaskController = tslib_1.__decorate([
|
|
70
|
+
(0, auth_guard_1.Task)(),
|
|
71
|
+
(0, common_1.Controller)('/tasks/auth'),
|
|
72
|
+
tslib_1.__param(0, (0, common_1.Inject)(configuration_1.CONFIGURATION)),
|
|
73
|
+
tslib_1.__param(1, (0, common_1.Inject)(mail_sender_1.MAIL_SENDER)),
|
|
74
|
+
tslib_1.__metadata("design:paramtypes", [Object, Object])
|
|
75
|
+
], AuthTaskController);
|
|
76
|
+
//# sourceMappingURL=auth.task.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.task.controller.js","sourceRoot":"","sources":["../../src/auth/auth.task.controller.ts"],"names":[],"mappings":";;;;AAAA,6CAAoC;AACpC,2CAAgE;AAChE,qDAA8D;AAC9D,kDAAqD;AACrD,oDAAgE;AAChE,qDAA2D;AAC3D,wCAAkD;AAElD,MAAM,qCAAqC,GAAG,QAAQ,CAAC;AACvD,MAAM,6BAA6B,GAAG,sCAAsC,CAAC;AAItE,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAG7B,YACyB,aAA6C,EAC/C,UA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CAAC;IAGK,AAAN,KAAK,CAAC,sBAAsB,CAClB,OAAgB,EACP,OAAe,EACjB,KAAa;QAE5B,MAAM,OAAO,GAAG,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,kBAAkB,OAAO,EAAE,CAAC;QACtE,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE;YAClC,EAAE,EAAE,KAAK;YACT,OAAO,EAAE,gBAAgB;YACzB,IAAI,EAAE;;;yBAGa,OAAO;;OAEzB;SACF,CAAC,CAAC;IACL,CAAC;CAWF,CAAA;AAtDY,gDAAkB;AAWvB;IADL,IAAA,aAAI,EAAC,mBAAmB,CAAC;IAEvB,mBAAA,IAAA,cAAI,GAAE,CAAA;IACN,mBAAA,IAAA,aAAI,EAAC,UAAU,CAAC,CAAA;IAChB,mBAAA,IAAA,aAAI,EAAC,OAAO,CAAC,CAAA;;;;6DAUf;AAGK;IADL,IAAA,aAAI,EAAC,uBAAuB,CAAC;IAE3B,mBAAA,IAAA,cAAI,GAAE,CAAA;IACN,mBAAA,IAAA,aAAI,EAAC,SAAS,CAAC,CAAA;IACf,mBAAA,IAAA,aAAI,EAAC,OAAO,CAAC,CAAA;;;;gEAaf;6BA3CU,kBAAkB;IAF9B,IAAA,iBAAI,GAAE;IACN,IAAA,mBAAU,EAAC,aAAa,CAAC;IAKrB,mBAAA,IAAA,eAAM,EAAC,6BAAa,CAAC,CAAA;IACrB,mBAAA,IAAA,eAAM,EAAC,yBAAW,CAAC,CAAA;;GALX,kBAAkB,CAsD9B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TaskQueue } from '../gcloud/tasks';
|
|
2
|
+
import { Configuration } from '../configuration';
|
|
3
|
+
export declare class AuthTaskService extends TaskQueue<Configuration> {
|
|
4
|
+
private readonly configuration;
|
|
5
|
+
constructor(configuration: Configuration);
|
|
6
|
+
queueActivationEmail(inviteId: string, email: string): Promise<void>;
|
|
7
|
+
queuePasswordResetEmail(resetId: string, email: string): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthTaskService = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const tasks_1 = require("../gcloud/tasks");
|
|
7
|
+
const configuration_1 = require("../configuration");
|
|
8
|
+
let AuthTaskService = class AuthTaskService extends tasks_1.TaskQueue {
|
|
9
|
+
constructor(configuration) {
|
|
10
|
+
super(configuration, 'default');
|
|
11
|
+
this.configuration = configuration;
|
|
12
|
+
}
|
|
13
|
+
queueActivationEmail(inviteId, email) {
|
|
14
|
+
return this.enqueue('auth/activation-email', { inviteId, email });
|
|
15
|
+
}
|
|
16
|
+
queuePasswordResetEmail(resetId, email) {
|
|
17
|
+
return this.enqueue('auth/password-reset-email', { resetId, email });
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
exports.AuthTaskService = AuthTaskService;
|
|
21
|
+
exports.AuthTaskService = AuthTaskService = tslib_1.__decorate([
|
|
22
|
+
(0, common_1.Injectable)(),
|
|
23
|
+
tslib_1.__param(0, (0, common_1.Inject)(configuration_1.CONFIGURATION)),
|
|
24
|
+
tslib_1.__metadata("design:paramtypes", [Object])
|
|
25
|
+
], AuthTaskService);
|
|
26
|
+
//# sourceMappingURL=auth.task.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.task.service.js","sourceRoot":"","sources":["../../src/auth/auth.task.service.ts"],"names":[],"mappings":";;;;AAAA,2CAAoD;AACpD,2CAA4C;AAC5C,oDAAgE;AAGzD,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,iBAAwB;IAC3D,YAAoD,aAA4B;QAC9E,KAAK,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;QADkB,kBAAa,GAAb,aAAa,CAAe;IAEhF,CAAC;IAED,oBAAoB,CAAC,QAAgB,EAAE,KAAa;QAClD,OAAO,IAAI,CAAC,OAAO,CAAC,uBAAuB,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;IACpE,CAAC;IAED,uBAAuB,CAAC,OAAe,EAAE,KAAa;QACpD,OAAO,IAAI,CAAC,OAAO,CAAC,2BAA2B,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;IACvE,CAAC;CACF,CAAA;AAZY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;IAEE,mBAAA,IAAA,eAAM,EAAC,6BAAa,CAAC,CAAA;;GADvB,eAAe,CAY3B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Response, NextFunction, RequestHandler } from 'express';
|
|
2
|
+
import { Request } from 'express-serve-static-core';
|
|
3
|
+
interface CsrfValidatorOptions {
|
|
4
|
+
sameSite: boolean;
|
|
5
|
+
}
|
|
6
|
+
interface RequestHandlerWithOptions {
|
|
7
|
+
(req: Request, res: Response, next: NextFunction, options: CsrfValidatorOptions): any;
|
|
8
|
+
}
|
|
9
|
+
export declare const CsrfValidator: RequestHandlerWithOptions;
|
|
10
|
+
export declare const CsrfValidatorWithOptions: (options: CsrfValidatorOptions) => (req: any, res: Response, next: NextFunction) => RequestHandler;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CsrfValidatorWithOptions = exports.CsrfValidator = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
const generateToken = () => (process.env.APP_ENGINE_ENVIRONMENT ? (0, uuid_1.v4)() : 'development');
|
|
6
|
+
const defaultValidatorOptions = {
|
|
7
|
+
sameSite: true,
|
|
8
|
+
};
|
|
9
|
+
const CsrfValidator = (req, res, next, options) => {
|
|
10
|
+
options = Object.assign(Object.assign({}, defaultValidatorOptions), options);
|
|
11
|
+
if (req.session && !req.session.csrf) {
|
|
12
|
+
req.session.csrf = generateToken();
|
|
13
|
+
res.cookie('csrf-token', req.session.csrf, {
|
|
14
|
+
sameSite: options.sameSite,
|
|
15
|
+
maxAge: 9999999999,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
if (req.method === 'GET' || req.method === 'OPTIONS' || req.method === 'HEAD') {
|
|
19
|
+
return next();
|
|
20
|
+
}
|
|
21
|
+
if (req.headers && req.session) {
|
|
22
|
+
const token = req.headers['x-csrf-token'];
|
|
23
|
+
if (token && token === req.session.csrf) {
|
|
24
|
+
return next();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
res.status(403).send({
|
|
28
|
+
message: 'Invalid CSRF token',
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
exports.CsrfValidator = CsrfValidator;
|
|
32
|
+
const CsrfValidatorWithOptions = (options) => {
|
|
33
|
+
return (req, res, next) => {
|
|
34
|
+
return (0, exports.CsrfValidator)(req, res, next, options);
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
exports.CsrfValidatorWithOptions = CsrfValidatorWithOptions;
|
|
38
|
+
//# sourceMappingURL=csrf.interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csrf.interceptor.js","sourceRoot":"","sources":["../../src/auth/csrf.interceptor.ts"],"names":[],"mappings":";;;AACA,+BAAoC;AAGpC,MAAM,aAAa,GAAG,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC,CAAC,IAAA,SAAM,GAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;AAM5F,MAAM,uBAAuB,GAAyB;IACpD,QAAQ,EAAE,IAAI;CACf,CAAC;AAOK,MAAM,aAAa,GAA8B,CACtD,GAAQ,EACR,GAAa,EACb,IAAkB,EAClB,OAA6B,EAC7B,EAAE;IACF,OAAO,mCAAQ,uBAAuB,GAAK,OAAO,CAAE,CAAC;I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