@vnodes/auth 0.0.5 → 0.0.11
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/auth.controller.d.ts +5 -0
- package/dist/auth.controller.d.ts.map +1 -1
- package/dist/auth.controller.js +41 -3
- package/dist/auth.module.d.ts.map +1 -1
- package/dist/auth.module.js +8 -4
- package/dist/client/auth-client.module.d.ts +3 -0
- package/dist/client/auth-client.module.d.ts.map +1 -0
- package/dist/client/auth-client.module.js +21 -0
- package/dist/context/context.d.ts +3 -1
- package/dist/context/context.d.ts.map +1 -1
- package/dist/context/context.js +6 -0
- package/dist/dto/can-activate-response-dto.d.ts +5 -0
- package/dist/dto/can-activate-response-dto.d.ts.map +1 -0
- package/dist/dto/can-activate-response-dto.js +12 -0
- package/dist/dto/can-activate.dto.d.ts +6 -0
- package/dist/dto/can-activate.dto.d.ts.map +1 -0
- package/dist/dto/can-activate.dto.js +17 -0
- package/dist/dto/email-otp-event.dto.d.ts +6 -0
- package/dist/dto/email-otp-event.dto.d.ts.map +1 -0
- package/dist/dto/email-otp-event.dto.js +17 -0
- package/dist/dto/forgot-password.dto.d.ts.map +1 -1
- package/dist/dto/forgot-password.dto.js +1 -1
- package/dist/dto/login-with-otp.dto.d.ts.map +1 -1
- package/dist/dto/login-with-otp.dto.js +2 -2
- package/dist/dto/login.dto.d.ts.map +1 -1
- package/dist/dto/login.dto.js +2 -2
- package/dist/dto/update-password-event.dto.d.ts +5 -0
- package/dist/dto/update-password-event.dto.d.ts.map +1 -0
- package/dist/dto/update-password-event.dto.js +14 -0
- package/dist/guards/auth-client.guard.d.ts +14 -0
- package/dist/guards/auth-client.guard.d.ts.map +1 -0
- package/dist/guards/auth-client.guard.js +64 -0
- package/dist/guards/auth.guard.d.ts +7 -3
- package/dist/guards/auth.guard.d.ts.map +1 -1
- package/dist/guards/auth.guard.js +32 -19
- package/dist/index.d.ts +13 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -2
- package/dist/providers/auth-client-options.provider.d.ts +5 -0
- package/dist/providers/auth-client-options.provider.d.ts.map +1 -0
- package/dist/providers/auth-client-options.provider.js +21 -0
- package/dist/services/auth-listener.service.d.ts +10 -0
- package/dist/services/auth-listener.service.d.ts.map +1 -0
- package/dist/services/auth-listener.service.js +32 -0
- package/dist/services/{user.service.d.ts → auth-user.service.d.ts} +12 -4
- package/dist/services/auth-user.service.d.ts.map +1 -0
- package/dist/services/{user.service.js → auth-user.service.js} +29 -10
- package/dist/services/auth.service.d.ts +14 -3
- package/dist/services/auth.service.d.ts.map +1 -1
- package/dist/services/auth.service.js +33 -13
- package/dist/types/auth-client-options.d.ts +6 -0
- package/dist/types/auth-client-options.d.ts.map +1 -0
- package/dist/types/auth-client-options.js +7 -0
- package/dist/types/auth-request.d.ts +1 -1
- package/dist/types/auth-request.d.ts.map +1 -1
- package/dist/types/jwt-payload.d.ts +6 -0
- package/dist/types/jwt-payload.d.ts.map +1 -0
- package/dist/types/jwt-payload.js +5 -0
- package/dist/{services → types}/user-manager.d.ts +12 -16
- package/dist/types/user-manager.d.ts.map +1 -0
- package/dist/{services → types}/user-manager.js +25 -29
- package/dist/types/user.d.ts +10 -0
- package/dist/types/user.d.ts.map +1 -0
- package/dist/types/user.js +17 -0
- package/package.json +4 -4
- package/dist/services/user-manager.d.ts.map +0 -1
- package/dist/services/user.service.d.ts.map +0 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { CanActivateDto } from './dto/can-activate.dto.js';
|
|
1
2
|
import { ForgotPasswordDto } from './dto/forgot-password.dto.js';
|
|
2
3
|
import { LoginDto } from './dto/login.dto.js';
|
|
4
|
+
import { UpdatePasswordDto } from './dto/update-password.dto.js';
|
|
3
5
|
import { AuthService } from './services/auth.service.js';
|
|
4
6
|
export declare class AuthController {
|
|
5
7
|
protected readonly authService: AuthService;
|
|
@@ -7,5 +9,8 @@ export declare class AuthController {
|
|
|
7
9
|
login(body: LoginDto): Promise<import("./index.js").AccessTokenDto>;
|
|
8
10
|
logout(accessToken: string): import("./index.js").MessageDto;
|
|
9
11
|
forgotPassword(body: ForgotPasswordDto): import("./index.js").MessageDto;
|
|
12
|
+
updatePassword(uuid: string, body: UpdatePasswordDto): Promise<import("./index.js").MessageDto>;
|
|
13
|
+
profile(uuid: string): import("./index.js").UserManager;
|
|
14
|
+
canActivate(username: string, body: CanActivateDto): Promise<import("./index.js").CanActivateResponseDto>;
|
|
10
15
|
}
|
|
11
16
|
//# sourceMappingURL=auth.controller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.controller.d.ts","sourceRoot":"","sources":["../src/auth.controller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.controller.d.ts","sourceRoot":"","sources":["../src/auth.controller.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEzD,qBAKa,cAAc;IACX,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW;gBAAxB,WAAW,EAAE,WAAW;IAIvD,KAAK,CAAS,IAAI,EAAE,QAAQ;IAK5B,MAAM,CAAgB,WAAW,EAAE,MAAM;IAMzC,cAAc,CAAS,IAAI,EAAE,iBAAiB;IAK9C,cAAc,CAAa,IAAI,EAAE,MAAM,EAAU,IAAI,EAAE,iBAAiB;IAKxE,OAAO,CAAa,IAAI,EAAE,MAAM;IAKhC,WAAW,CAAiB,QAAQ,EAAE,MAAM,EAAU,IAAI,EAAE,cAAc;CAG7E"}
|
package/dist/auth.controller.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
-
import { Body, Controller, Post } from '@nestjs/common';
|
|
2
|
+
import { Body, Controller, Get, Post } from '@nestjs/common';
|
|
3
|
+
import { ApiBearerAuth } from '@nestjs/swagger';
|
|
3
4
|
import { Throttle } from '@nestjs/throttler';
|
|
4
|
-
import { Public } from '@vnodes/metadata';
|
|
5
|
-
import { AccessToken } from './context/context.js';
|
|
5
|
+
import { ByPassAutorization, Public, ResourceName } from '@vnodes/metadata';
|
|
6
|
+
import { AccessToken, UserUsername, UserUuid } from './context/context.js';
|
|
7
|
+
import { CanActivateDto } from './dto/can-activate.dto.js';
|
|
6
8
|
import { ForgotPasswordDto } from './dto/forgot-password.dto.js';
|
|
7
9
|
import { LoginDto } from './dto/login.dto.js';
|
|
10
|
+
import { UpdatePasswordDto } from './dto/update-password.dto.js';
|
|
8
11
|
import { AuthService } from './services/auth.service.js';
|
|
9
12
|
let AuthController = class AuthController {
|
|
10
13
|
authService;
|
|
@@ -20,6 +23,15 @@ let AuthController = class AuthController {
|
|
|
20
23
|
forgotPassword(body) {
|
|
21
24
|
return this.authService.forgotPassword(body);
|
|
22
25
|
}
|
|
26
|
+
updatePassword(uuid, body) {
|
|
27
|
+
return this.authService.updatePassword(uuid, body);
|
|
28
|
+
}
|
|
29
|
+
profile(uuid) {
|
|
30
|
+
return this.authService.profile(uuid);
|
|
31
|
+
}
|
|
32
|
+
canActivate(username, body) {
|
|
33
|
+
return this.authService.canActivate(username, body);
|
|
34
|
+
}
|
|
23
35
|
};
|
|
24
36
|
__decorate([
|
|
25
37
|
Public(),
|
|
@@ -44,8 +56,34 @@ __decorate([
|
|
|
44
56
|
__metadata("design:paramtypes", [ForgotPasswordDto]),
|
|
45
57
|
__metadata("design:returntype", void 0)
|
|
46
58
|
], AuthController.prototype, "forgotPassword", null);
|
|
59
|
+
__decorate([
|
|
60
|
+
Post('update-password'),
|
|
61
|
+
__param(0, UserUuid()),
|
|
62
|
+
__param(1, Body()),
|
|
63
|
+
__metadata("design:type", Function),
|
|
64
|
+
__metadata("design:paramtypes", [String, UpdatePasswordDto]),
|
|
65
|
+
__metadata("design:returntype", void 0)
|
|
66
|
+
], AuthController.prototype, "updatePassword", null);
|
|
67
|
+
__decorate([
|
|
68
|
+
Get('profile'),
|
|
69
|
+
__param(0, UserUuid()),
|
|
70
|
+
__metadata("design:type", Function),
|
|
71
|
+
__metadata("design:paramtypes", [String]),
|
|
72
|
+
__metadata("design:returntype", void 0)
|
|
73
|
+
], AuthController.prototype, "profile", null);
|
|
74
|
+
__decorate([
|
|
75
|
+
Post('can-activate'),
|
|
76
|
+
__param(0, UserUsername()),
|
|
77
|
+
__param(1, Body()),
|
|
78
|
+
__metadata("design:type", Function),
|
|
79
|
+
__metadata("design:paramtypes", [String, CanActivateDto]),
|
|
80
|
+
__metadata("design:returntype", void 0)
|
|
81
|
+
], AuthController.prototype, "canActivate", null);
|
|
47
82
|
AuthController = __decorate([
|
|
83
|
+
ByPassAutorization(),
|
|
48
84
|
Throttle({ default: { limit: 6, ttl: 30_000 } }),
|
|
85
|
+
ResourceName('Auth'),
|
|
86
|
+
ApiBearerAuth(),
|
|
49
87
|
Controller('auth'),
|
|
50
88
|
__metadata("design:paramtypes", [AuthService])
|
|
51
89
|
], AuthController);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.module.d.ts","sourceRoot":"","sources":["../src/auth.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.module.d.ts","sourceRoot":"","sources":["../src/auth.module.ts"],"names":[],"mappings":"AAWA,qBAsBa,UAAU;CAAG"}
|
package/dist/auth.module.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { Module } from '@nestjs/common';
|
|
3
3
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
4
|
+
import { APP_GUARD } from '@nestjs/core';
|
|
4
5
|
import { EventEmitterModule } from '@nestjs/event-emitter';
|
|
5
6
|
import { JwtModule } from '@nestjs/jwt';
|
|
7
|
+
import { Env } from '@vnodes/metadata';
|
|
6
8
|
import { AuthController } from './auth.controller.js';
|
|
9
|
+
import { AuthGuard } from './guards/auth.guard.js';
|
|
7
10
|
import { AuthService } from './services/auth.service.js';
|
|
8
|
-
import {
|
|
11
|
+
import { AuthUserService } from './services/auth-user.service.js';
|
|
9
12
|
let AuthModule = class AuthModule {
|
|
10
13
|
};
|
|
11
14
|
AuthModule = __decorate([
|
|
@@ -16,8 +19,8 @@ AuthModule = __decorate([
|
|
|
16
19
|
imports: [ConfigModule],
|
|
17
20
|
inject: [ConfigService],
|
|
18
21
|
useFactory(config) {
|
|
19
|
-
const secret = config.getOrThrow(
|
|
20
|
-
const expiresIn = config.getOrThrow(
|
|
22
|
+
const secret = config.getOrThrow(Env.JWT_SECRET);
|
|
23
|
+
const expiresIn = config.getOrThrow(Env.JWT_EXPIRES_IN);
|
|
21
24
|
return {
|
|
22
25
|
secret,
|
|
23
26
|
signOptions: {
|
|
@@ -28,7 +31,8 @@ AuthModule = __decorate([
|
|
|
28
31
|
}),
|
|
29
32
|
],
|
|
30
33
|
controllers: [AuthController],
|
|
31
|
-
providers: [
|
|
34
|
+
providers: [AuthUserService, AuthService, { provide: APP_GUARD, useClass: AuthGuard }],
|
|
35
|
+
exports: [AuthUserService],
|
|
32
36
|
})
|
|
33
37
|
], AuthModule);
|
|
34
38
|
export { AuthModule };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-client.module.d.ts","sourceRoot":"","sources":["../../src/client/auth-client.module.ts"],"names":[],"mappings":"AAMA,qBAUa,gBAAgB;CAAG"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { Module } from '@nestjs/common';
|
|
3
|
+
import { ConfigModule } from '@nestjs/config';
|
|
4
|
+
import { APP_GUARD } from '@nestjs/core';
|
|
5
|
+
import { AuthClientGuard } from '../guards/auth-client.guard.js';
|
|
6
|
+
import { provideAuthClientOptions } from '../providers/auth-client-options.provider.js';
|
|
7
|
+
let AuthClientModule = class AuthClientModule {
|
|
8
|
+
};
|
|
9
|
+
AuthClientModule = __decorate([
|
|
10
|
+
Module({
|
|
11
|
+
imports: [ConfigModule],
|
|
12
|
+
providers: [
|
|
13
|
+
provideAuthClientOptions(),
|
|
14
|
+
{
|
|
15
|
+
provide: APP_GUARD,
|
|
16
|
+
useClass: AuthClientGuard,
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
})
|
|
20
|
+
], AuthClientModule);
|
|
21
|
+
export { AuthClientModule };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { User } from '../
|
|
1
|
+
import { User } from '../types/user.js';
|
|
2
2
|
/**
|
|
3
3
|
* Get the user info {@link UserInfo} of the current session from the request
|
|
4
4
|
*/
|
|
5
5
|
export declare const UserInfo: (...dataOrPipes: (User | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
|
|
6
|
+
export declare const UserUuid: (...dataOrPipes: (User | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
|
|
7
|
+
export declare const UserUsername: (...dataOrPipes: (User | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
|
|
6
8
|
/**
|
|
7
9
|
* Get the access token of the current session from the request
|
|
8
10
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context/context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context/context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC;;GAEG;AACH,eAAO,MAAM,QAAQ,uLAEnB,CAAC;AAEH,eAAO,MAAM,QAAQ,uLAEnB,CAAC;AAEH,eAAO,MAAM,YAAY,uLAEvB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,WAAW,yLAEtB,CAAC"}
|
package/dist/context/context.js
CHANGED
|
@@ -5,6 +5,12 @@ import { createParamDecorator } from '@nestjs/common';
|
|
|
5
5
|
export const UserInfo = createParamDecorator((_, context) => {
|
|
6
6
|
return context.switchToHttp().getRequest().user;
|
|
7
7
|
});
|
|
8
|
+
export const UserUuid = createParamDecorator((_, context) => {
|
|
9
|
+
return context.switchToHttp().getRequest().user.uuid;
|
|
10
|
+
});
|
|
11
|
+
export const UserUsername = createParamDecorator((_, context) => {
|
|
12
|
+
return context.switchToHttp().getRequest().user.username;
|
|
13
|
+
});
|
|
8
14
|
/**
|
|
9
15
|
* Get the access token of the current session from the request
|
|
10
16
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"can-activate-response-dto.d.ts","sourceRoot":"","sources":["../../src/dto/can-activate-response-dto.ts"],"names":[],"mappings":"AAEA,qBAAa,sBAAsB;IACvB,WAAW,EAAE,OAAO,CAAC;gBAEjB,IAAI,EAAE,sBAAsB;CAG3C"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Prop } from '@vnodes/property';
|
|
3
|
+
export class CanActivateResponseDto {
|
|
4
|
+
canActivate;
|
|
5
|
+
constructor(data) {
|
|
6
|
+
Object.assign(this, data);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
__decorate([
|
|
10
|
+
Prop(),
|
|
11
|
+
__metadata("design:type", Boolean)
|
|
12
|
+
], CanActivateResponseDto.prototype, "canActivate", void 0);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"can-activate.dto.d.ts","sourceRoot":"","sources":["../../src/dto/can-activate.dto.ts"],"names":[],"mappings":"AAEA,qBAAa,cAAc;IACG,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;gBAC7C,IAAI,EAAE,cAAc;CAGnC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Prop } from '@vnodes/property';
|
|
3
|
+
export class CanActivateDto {
|
|
4
|
+
requiredRoles;
|
|
5
|
+
requiredPermissions;
|
|
6
|
+
constructor(data) {
|
|
7
|
+
Object.assign(this, data);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
__decorate([
|
|
11
|
+
Prop({ type: [String] }),
|
|
12
|
+
__metadata("design:type", Array)
|
|
13
|
+
], CanActivateDto.prototype, "requiredRoles", void 0);
|
|
14
|
+
__decorate([
|
|
15
|
+
Prop({ type: [String] }),
|
|
16
|
+
__metadata("design:type", Array)
|
|
17
|
+
], CanActivateDto.prototype, "requiredPermissions", void 0);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-otp-event.dto.d.ts","sourceRoot":"","sources":["../../src/dto/email-otp-event.dto.ts"],"names":[],"mappings":"AAEA,qBAAa,gBAAgB;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;gBACR,IAAI,EAAE,gBAAgB;CAGrC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Prop } from '@vnodes/property';
|
|
3
|
+
export class EmailOtpEventDto {
|
|
4
|
+
username;
|
|
5
|
+
otp;
|
|
6
|
+
constructor(data) {
|
|
7
|
+
Object.assign(this, data);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
__decorate([
|
|
11
|
+
Prop(),
|
|
12
|
+
__metadata("design:type", String)
|
|
13
|
+
], EmailOtpEventDto.prototype, "username", void 0);
|
|
14
|
+
__decorate([
|
|
15
|
+
Prop(),
|
|
16
|
+
__metadata("design:type", String)
|
|
17
|
+
], EmailOtpEventDto.prototype, "otp", void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forgot-password.dto.d.ts","sourceRoot":"","sources":["../../src/dto/forgot-password.dto.ts"],"names":[],"mappings":"AAEA,qBAAa,iBAAiB;
|
|
1
|
+
{"version":3,"file":"forgot-password.dto.d.ts","sourceRoot":"","sources":["../../src/dto/forgot-password.dto.ts"],"names":[],"mappings":"AAEA,qBAAa,iBAAiB;IACA,QAAQ,EAAE,MAAM,CAAC;CAC9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login-with-otp.dto.d.ts","sourceRoot":"","sources":["../../src/dto/login-with-otp.dto.ts"],"names":[],"mappings":"AAEA,qBAAa,eAAe;
|
|
1
|
+
{"version":3,"file":"login-with-otp.dto.d.ts","sourceRoot":"","sources":["../../src/dto/login-with-otp.dto.ts"],"names":[],"mappings":"AAEA,qBAAa,eAAe;IACE,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACzC"}
|
|
@@ -5,10 +5,10 @@ export class LoginWithOtpDto {
|
|
|
5
5
|
otp;
|
|
6
6
|
}
|
|
7
7
|
__decorate([
|
|
8
|
-
Prop({ required: true
|
|
8
|
+
Prop({ required: true }),
|
|
9
9
|
__metadata("design:type", String)
|
|
10
10
|
], LoginWithOtpDto.prototype, "username", void 0);
|
|
11
11
|
__decorate([
|
|
12
|
-
Prop({ required: true
|
|
12
|
+
Prop({ required: true }),
|
|
13
13
|
__metadata("design:type", String)
|
|
14
14
|
], LoginWithOtpDto.prototype, "otp", void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login.dto.d.ts","sourceRoot":"","sources":["../../src/dto/login.dto.ts"],"names":[],"mappings":"AAEA,qBAAa,QAAQ;
|
|
1
|
+
{"version":3,"file":"login.dto.d.ts","sourceRoot":"","sources":["../../src/dto/login.dto.ts"],"names":[],"mappings":"AAEA,qBAAa,QAAQ;IACS,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAC9C"}
|
package/dist/dto/login.dto.js
CHANGED
|
@@ -5,10 +5,10 @@ export class LoginDto {
|
|
|
5
5
|
password;
|
|
6
6
|
}
|
|
7
7
|
__decorate([
|
|
8
|
-
Prop({ required: true
|
|
8
|
+
Prop({ required: true }),
|
|
9
9
|
__metadata("design:type", String)
|
|
10
10
|
], LoginDto.prototype, "username", void 0);
|
|
11
11
|
__decorate([
|
|
12
|
-
Prop({ required: true
|
|
12
|
+
Prop({ required: true }),
|
|
13
13
|
__metadata("design:type", String)
|
|
14
14
|
], LoginDto.prototype, "password", void 0);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-password-event.dto.d.ts","sourceRoot":"","sources":["../../src/dto/update-password-event.dto.ts"],"names":[],"mappings":"AAEA,qBAAa,sBAAsB;IACL,IAAI,EAAE,MAAM,CAAC;IACO,QAAQ,EAAE,MAAM,CAAC;CAClE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Prop } from '@vnodes/property';
|
|
3
|
+
export class UpdatePasswordEventDto {
|
|
4
|
+
uuid;
|
|
5
|
+
password;
|
|
6
|
+
}
|
|
7
|
+
__decorate([
|
|
8
|
+
Prop({ required: true }),
|
|
9
|
+
__metadata("design:type", String)
|
|
10
|
+
], UpdatePasswordEventDto.prototype, "uuid", void 0);
|
|
11
|
+
__decorate([
|
|
12
|
+
Prop({ required: true, format: 'password' }),
|
|
13
|
+
__metadata("design:type", String)
|
|
14
|
+
], UpdatePasswordEventDto.prototype, "password", void 0);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { ConfigService } from '@nestjs/config';
|
|
3
|
+
import { Reflector } from '@nestjs/core';
|
|
4
|
+
import { AuthClientOptions } from '../types/auth-client-options.js';
|
|
5
|
+
import { AuthRequest } from '../types/auth-request.js';
|
|
6
|
+
export declare class AuthClientGuard implements CanActivate {
|
|
7
|
+
protected readonly reflector: Reflector;
|
|
8
|
+
protected readonly config: ConfigService;
|
|
9
|
+
protected readonly serviceOptions: AuthClientOptions;
|
|
10
|
+
constructor(reflector: Reflector, config: ConfigService, serviceOptions: AuthClientOptions);
|
|
11
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
12
|
+
extractToken(request: AuthRequest): string;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=auth-client.guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-client.guard.d.ts","sourceRoot":"","sources":["../../src/guards/auth-client.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAqC,MAAM,gBAAgB,CAAC;AAClG,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAIzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,qBACa,eAAgB,YAAW,WAAW;IAE3C,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS;IACvC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,aAAa;IACb,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,iBAAiB;gBAF5D,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,aAAa,EACM,cAAc,EAAE,iBAAiB;IAG7E,WAAW,CAAC,OAAO,EAAE,gBAAgB;IAwC3C,YAAY,CAAC,OAAO,EAAE,WAAW;CAYpC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
+
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
|
3
|
+
import { ConfigService } from '@nestjs/config';
|
|
4
|
+
import { Reflector } from '@nestjs/core';
|
|
5
|
+
import { getOperationName, getPermissions, getRoles, isPublic } from '@vnodes/metadata';
|
|
6
|
+
import { CanActivateDto } from '../dto/can-activate.dto.js';
|
|
7
|
+
import { InjectAutoClientOptions } from '../providers/auth-client-options.provider.js';
|
|
8
|
+
import { AuthClientOptions } from '../types/auth-client-options.js';
|
|
9
|
+
let AuthClientGuard = class AuthClientGuard {
|
|
10
|
+
reflector;
|
|
11
|
+
config;
|
|
12
|
+
serviceOptions;
|
|
13
|
+
constructor(reflector, config, serviceOptions) {
|
|
14
|
+
this.reflector = reflector;
|
|
15
|
+
this.config = config;
|
|
16
|
+
this.serviceOptions = serviceOptions;
|
|
17
|
+
}
|
|
18
|
+
async canActivate(context) {
|
|
19
|
+
const req = context.switchToHttp().getRequest();
|
|
20
|
+
if (isPublic(this.reflector, context)) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
const headers = new Headers();
|
|
24
|
+
const resourceName = getOperationName(this.reflector, context);
|
|
25
|
+
const operationName = getOperationName(this.reflector, context);
|
|
26
|
+
const permit = `${this.serviceOptions.appId}.${resourceName}.${operationName}`;
|
|
27
|
+
const customPermissions = getPermissions(this.reflector, context) ?? [];
|
|
28
|
+
const customRoles = getRoles(this.reflector, context) ?? [];
|
|
29
|
+
const token = this.extractToken(req);
|
|
30
|
+
headers.set('authorization', token);
|
|
31
|
+
const policy = new CanActivateDto({
|
|
32
|
+
requiredRoles: [...customRoles],
|
|
33
|
+
requiredPermissions: [permit, ...customPermissions],
|
|
34
|
+
});
|
|
35
|
+
const bodyAsString = JSON.stringify(policy);
|
|
36
|
+
const res = await fetch(this.serviceOptions.authServiceUrl, {
|
|
37
|
+
method: 'POST',
|
|
38
|
+
headers,
|
|
39
|
+
body: bodyAsString,
|
|
40
|
+
});
|
|
41
|
+
if (res.status > 200 && res.status < 300) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
extractToken(request) {
|
|
47
|
+
const rawToken = request.headers.authorization;
|
|
48
|
+
if (!rawToken) {
|
|
49
|
+
throw new UnauthorizedException('No token');
|
|
50
|
+
}
|
|
51
|
+
const [type, token] = rawToken.split(' ');
|
|
52
|
+
if (type === 'Bearer' && token)
|
|
53
|
+
return token;
|
|
54
|
+
throw new UnauthorizedException('Invalid token ');
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
AuthClientGuard = __decorate([
|
|
58
|
+
Injectable(),
|
|
59
|
+
__param(2, InjectAutoClientOptions()),
|
|
60
|
+
__metadata("design:paramtypes", [Reflector,
|
|
61
|
+
ConfigService,
|
|
62
|
+
AuthClientOptions])
|
|
63
|
+
], AuthClientGuard);
|
|
64
|
+
export { AuthClientGuard };
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { ConfigService } from '@nestjs/config';
|
|
2
3
|
import { Reflector } from '@nestjs/core';
|
|
3
|
-
import {
|
|
4
|
+
import { UserManager } from 'src/types/user-manager.js';
|
|
5
|
+
import { AuthUserService } from '../services/auth-user.service.js';
|
|
4
6
|
import { AuthRequest } from '../types/auth-request.js';
|
|
5
7
|
export declare class AuthGuard implements CanActivate {
|
|
8
|
+
protected readonly config: ConfigService;
|
|
6
9
|
protected readonly reflector: Reflector;
|
|
7
|
-
protected readonly
|
|
8
|
-
constructor(reflector: Reflector,
|
|
10
|
+
protected readonly authUserService: AuthUserService;
|
|
11
|
+
constructor(config: ConfigService, reflector: Reflector, authUserService: AuthUserService);
|
|
9
12
|
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
13
|
+
protected isAutorized(context: ExecutionContext, user: UserManager): boolean;
|
|
10
14
|
extractToken(request: AuthRequest): string;
|
|
11
15
|
}
|
|
12
16
|
//# sourceMappingURL=auth.guard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.guard.d.ts","sourceRoot":"","sources":["../../src/guards/auth.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAqC,MAAM,gBAAgB,CAAC;AAClG,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.guard.d.ts","sourceRoot":"","sources":["../../src/guards/auth.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAqC,MAAM,gBAAgB,CAAC;AAClG,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AASzC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,qBACa,SAAU,YAAW,WAAW;IAErC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,aAAa;IACxC,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS;IACvC,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,eAAe;gBAFhC,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,SAAS,EACpB,eAAe,EAAE,eAAe;IAGjD,WAAW,CAAC,OAAO,EAAE,gBAAgB;IAgB3C,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW;IAgClE,YAAY,CAAC,OAAO,EAAE,WAAW;CAYpC"}
|
|
@@ -1,42 +1,54 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
|
3
|
+
import { ConfigService } from '@nestjs/config';
|
|
3
4
|
import { Reflector } from '@nestjs/core';
|
|
4
|
-
import { getPermissions, getRoles, isPublic } from '@vnodes/metadata';
|
|
5
|
-
import {
|
|
5
|
+
import { getOperationName, getPermissions, getResourceName, getRoles, isByPassAuthorization, isPublic, } from '@vnodes/metadata';
|
|
6
|
+
import { AuthUserService } from '../services/auth-user.service.js';
|
|
6
7
|
let AuthGuard = class AuthGuard {
|
|
8
|
+
config;
|
|
7
9
|
reflector;
|
|
8
|
-
|
|
9
|
-
constructor(reflector,
|
|
10
|
+
authUserService;
|
|
11
|
+
constructor(config, reflector, authUserService) {
|
|
12
|
+
this.config = config;
|
|
10
13
|
this.reflector = reflector;
|
|
11
|
-
this.
|
|
14
|
+
this.authUserService = authUserService;
|
|
12
15
|
}
|
|
13
16
|
async canActivate(context) {
|
|
14
17
|
if (isPublic(this.reflector, context)) {
|
|
15
18
|
return true;
|
|
16
19
|
}
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
20
|
+
const req = context.switchToHttp().getRequest();
|
|
21
|
+
const token = this.extractToken(req);
|
|
22
|
+
const user = await this.authUserService.findByToken(token);
|
|
23
|
+
req.user = user.user;
|
|
24
|
+
if (isByPassAuthorization(this.reflector, context)) {
|
|
21
25
|
return true;
|
|
22
26
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
return this.isAutorized(context, user);
|
|
28
|
+
}
|
|
29
|
+
isAutorized(context, user) {
|
|
30
|
+
const appId = this.config.getOrThrow('APP_ID');
|
|
31
|
+
const resourceName = getResourceName(this.reflector, context);
|
|
32
|
+
const operationName = getOperationName(this.reflector, context);
|
|
33
|
+
const customPermits = getPermissions(this.reflector, context);
|
|
34
|
+
const customRoles = getRoles(this.reflector, context);
|
|
35
|
+
const permit = `${appId}.${resourceName}.${operationName}`;
|
|
27
36
|
if (user.isAdmin()) {
|
|
28
37
|
return true;
|
|
29
38
|
}
|
|
30
|
-
if (
|
|
31
|
-
if (!user.
|
|
39
|
+
if (customPermits && customPermits.length > 0) {
|
|
40
|
+
if (!user.hasAllPermissions(customPermits)) {
|
|
32
41
|
return false;
|
|
33
42
|
}
|
|
34
43
|
}
|
|
35
|
-
if (
|
|
36
|
-
if (!user.
|
|
44
|
+
if (customRoles && customRoles.length > 0) {
|
|
45
|
+
if (!user.hasSomeRoles(customRoles)) {
|
|
37
46
|
return false;
|
|
38
47
|
}
|
|
39
48
|
}
|
|
49
|
+
if (!user.hasAllPermissions([permit])) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
40
52
|
return true;
|
|
41
53
|
}
|
|
42
54
|
extractToken(request) {
|
|
@@ -52,7 +64,8 @@ let AuthGuard = class AuthGuard {
|
|
|
52
64
|
};
|
|
53
65
|
AuthGuard = __decorate([
|
|
54
66
|
Injectable(),
|
|
55
|
-
__metadata("design:paramtypes", [
|
|
56
|
-
|
|
67
|
+
__metadata("design:paramtypes", [ConfigService,
|
|
68
|
+
Reflector,
|
|
69
|
+
AuthUserService])
|
|
57
70
|
], AuthGuard);
|
|
58
71
|
export { AuthGuard };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
export * from './auth.controller.js';
|
|
2
2
|
export * from './auth.module.js';
|
|
3
|
+
export * from './client/auth-client.module.js';
|
|
3
4
|
export * from './context/context.js';
|
|
4
5
|
export * from './dto/access-token.dto.js';
|
|
6
|
+
export * from './dto/can-activate.dto.js';
|
|
7
|
+
export * from './dto/can-activate-response-dto.js';
|
|
8
|
+
export * from './dto/email-otp-event.dto.js';
|
|
5
9
|
export * from './dto/forgot-password.dto.js';
|
|
6
10
|
export * from './dto/login.dto.js';
|
|
7
11
|
export * from './dto/login-with-otp.dto.js';
|
|
8
12
|
export * from './dto/message.dto.js';
|
|
9
13
|
export * from './dto/otp-response-dto.js';
|
|
10
14
|
export * from './dto/update-password.dto.js';
|
|
15
|
+
export * from './dto/update-password-event.dto.js';
|
|
11
16
|
export * from './guards/auth.guard.js';
|
|
17
|
+
export * from './guards/auth-client.guard.js';
|
|
18
|
+
export * from './providers/auth-client-options.provider.js';
|
|
12
19
|
export * from './services/auth.service.js';
|
|
13
|
-
export * from './services/
|
|
14
|
-
export * from './services/user
|
|
20
|
+
export * from './services/auth-listener.service.js';
|
|
21
|
+
export * from './services/auth-user.service.js';
|
|
22
|
+
export * from './types/auth-client-options.js';
|
|
15
23
|
export * from './types/auth-request.js';
|
|
24
|
+
export * from './types/jwt-payload.js';
|
|
25
|
+
export * from './types/user.js';
|
|
26
|
+
export * from './types/user-manager.js';
|
|
16
27
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC;AACnC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oCAAoC,CAAC;AACnD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC;AACnC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oCAAoC,CAAC;AACnD,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6CAA6C,CAAC;AAC5D,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qCAAqC,CAAC;AACpD,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
// @index(['./**/*.ts', '!./**/*.spec.ts', '!./**/{main,serve,index}.ts', '!./**/prisma', '!./**/generated'], f => `export * from '${f.path}.js'`)
|
|
2
2
|
export * from './auth.controller.js';
|
|
3
3
|
export * from './auth.module.js';
|
|
4
|
+
export * from './client/auth-client.module.js';
|
|
4
5
|
export * from './context/context.js';
|
|
5
6
|
export * from './dto/access-token.dto.js';
|
|
7
|
+
export * from './dto/can-activate.dto.js';
|
|
8
|
+
export * from './dto/can-activate-response-dto.js';
|
|
9
|
+
export * from './dto/email-otp-event.dto.js';
|
|
6
10
|
export * from './dto/forgot-password.dto.js';
|
|
7
11
|
export * from './dto/login.dto.js';
|
|
8
12
|
export * from './dto/login-with-otp.dto.js';
|
|
9
13
|
export * from './dto/message.dto.js';
|
|
10
14
|
export * from './dto/otp-response-dto.js';
|
|
11
15
|
export * from './dto/update-password.dto.js';
|
|
16
|
+
export * from './dto/update-password-event.dto.js';
|
|
12
17
|
export * from './guards/auth.guard.js';
|
|
18
|
+
export * from './guards/auth-client.guard.js';
|
|
19
|
+
export * from './providers/auth-client-options.provider.js';
|
|
13
20
|
export * from './services/auth.service.js';
|
|
14
|
-
export * from './services/
|
|
15
|
-
export * from './services/user
|
|
21
|
+
export * from './services/auth-listener.service.js';
|
|
22
|
+
export * from './services/auth-user.service.js';
|
|
23
|
+
export * from './types/auth-client-options.js';
|
|
16
24
|
export * from './types/auth-request.js';
|
|
25
|
+
export * from './types/jwt-payload.js';
|
|
26
|
+
export * from './types/user.js';
|
|
27
|
+
export * from './types/user-manager.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Provider } from '@nestjs/common';
|
|
2
|
+
export declare function getAuthClientOptionsToken(): string;
|
|
3
|
+
export declare function provideAuthClientOptions(): Provider;
|
|
4
|
+
export declare const InjectAutoClientOptions: () => PropertyDecorator & ParameterDecorator;
|
|
5
|
+
//# sourceMappingURL=auth-client-options.provider.d.ts.map
|