@serene-dev/la-nest-library 11.0.56 → 11.0.57
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/libs/la-library/src/index.d.ts +1 -1
- package/dist/libs/la-library/src/index.js +4 -3
- package/dist/libs/la-library/src/index.js.map +1 -1
- package/dist/libs/la-library/src/modules/authentication/authentication.guard.d.ts +125 -0
- package/dist/libs/la-library/src/modules/authentication/authentication.guard.js +128 -3
- package/dist/libs/la-library/src/modules/authentication/authentication.guard.js.map +1 -1
- package/package.json +1 -1
|
@@ -12,7 +12,7 @@ export { APIService as SDKAPIService } from './services/api.service';
|
|
|
12
12
|
export { TokenService as SDKTokenService, TokenSessionService as SDKTokenSessionService, TokenServiceModule as SDKTokenServiceModule, } from './services/token.service';
|
|
13
13
|
export { TokenSessionEntity as SDKTokenSessionEntity } from './entities/token-session.entity';
|
|
14
14
|
export { AuthenticationModule as SDKAuthenticationModule } from './modules/authentication/authentication.module';
|
|
15
|
-
export { AuthenticationGuard as SDKAuthenticationGuard, PublicAuth as SDKPublicAuth, AuthParam, } from './modules/authentication/authentication.guard';
|
|
15
|
+
export { AuthenticationGuard as SDKAuthenticationGuard, PublicAuth as SDKPublicAuth, AuthParam, QueryParamAuth, } from './modules/authentication/authentication.guard';
|
|
16
16
|
export { AuthenticationService as SDKAuthenticationService, AuthSessionService as SDKAuthenticationSessionService, } from './modules/authentication/authentication.service';
|
|
17
17
|
export { AuthenticationController as SDKAuthenticationController } from './modules/authentication/authentication.controller';
|
|
18
18
|
export { AuthEntity as SDKAuthEntity } from './modules/authentication/authentication.entity';
|
|
@@ -14,9 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
18
|
-
exports.
|
|
19
|
-
exports.SDKCustomValidationPipe = exports.SDKUtilityController = exports.ESortOrder = exports.ESearchCondition = exports.SDKSearchService = exports.SearchQueryDto = exports.FileUploadJSONDto = exports.FileUploadJSONMiniDto = exports.SDKFileUploadDto = exports.SDKFileUpdateDto = exports.SDKFileSearchDto = exports.SDKFileActionDto = exports.SDKListsEntity = exports.SDKListOptionsEntity = exports.SDKListsController = exports.SDKSaveListOption = exports.SDKSaveListGroupDTO = exports.SDKListsService = exports.SDKListsModule = exports.SDKTelnetService = exports.SDKTelnetModule = exports.SDKTelnetRequestDTO = exports.SDKTelnetController = void 0;
|
|
17
|
+
exports.SDKFileModule = exports.FileEntity = exports.LikesEntity = exports.SDKFileController = exports.SDKEFileSizeUnit = exports.SDKSample = exports.SDKBaseDto = exports.BaseView = exports.BaseEntity = exports.BaseJoinEntity = exports.SDKBaseService = exports.SDKBaseCRUDController = exports.SDKBaseCRUController = exports.SDKBaseController = exports.SDKVerifyResetPasswordTokenResponseDTO = exports.SDKVerifyResetPasswordTokenDTO = exports.SDKChangePasswordDTO = exports.SDKResetPasswordDTO = exports.SDKRequestPasswordResetDTO = exports.SDKToggleAuthDTO = exports.SDKSystemLogoutDTO = exports.SDKRegisterDTO = exports.SDKLogoutDTO = exports.SDKLoginDTO = exports.SDKAuthSessionEntity = exports.SDKAuthEntity = exports.SDKAuthenticationController = exports.SDKAuthenticationSessionService = exports.SDKAuthenticationService = exports.QueryParamAuth = exports.AuthParam = exports.SDKPublicAuth = exports.SDKAuthenticationGuard = exports.SDKAuthenticationModule = exports.SDKTokenSessionEntity = exports.SDKTokenServiceModule = exports.SDKTokenSessionService = exports.SDKTokenService = exports.SDKAPIService = exports.SMSService = exports.MailService = exports.SDKUtilityClass = exports.SDKETableName = exports.SDKERefCat = exports.SDKEvt = exports.setSDKEnvironment = exports.ISDKEnvironment = exports.SDKEnvironmentService = exports.RoutePath = exports.SDKConfig = void 0;
|
|
18
|
+
exports.SDKNotificationService = exports.SDKNotificationModule = exports.SDKnotificationEntities = exports.SDKNotificationItemEntity = exports.SDKNotificationEntity = exports.SDKNotificationToggleActiveStatusDTO = exports.SDKNotificationQueryDTO = exports.SDKNotificationItemQueryDTO = exports.SDKCreateNotificationDTO = exports.SDKNotificationController = exports.MessageService = exports.MessageModule = exports.MessageRecipientEntity = exports.MessageEntity = exports.MessageController = exports.SDKWalletTransactionService = exports.SDKWalletService = exports.SDKETransactionType = exports.SDKETransMethod = exports.SDKECurrency = exports.SDKWalletTransaction = exports.SDKWalletNetBalanceView = exports.SDKWalletGrossBalanceView = exports.SDKWalletExternalBank = exports.SDKWalletEntity = exports.SDKWalletEntities = exports.SDKWalletSearchDTO = exports.SDKSaveWalletDTO = exports.SDKWalletController = exports.SDKWalletModule = exports.SDKLogEntity = exports.SDKLogsController = exports.SDKLogCreateSingleDTO = exports.SDKLogCreateMultipleDTO = exports.SDKLogSearchDTO = exports.SDKLogsForInterceptorService = exports.SDKLogsService = exports.SDKLogsModule = exports.initLogger = exports.stream = exports.logger = exports.SDKCategoryService = exports.SDKCategoryModule = exports.SDKCategoryEntity = exports.SDKUpdateCategoryDto = exports.SDKSearchCategoryDto = exports.SDKCreateCategoryDto = exports.SDKCategoryController = exports.SDKLikesService = exports.SDKFileService = void 0;
|
|
19
|
+
exports.SDKCustomValidationPipe = exports.SDKUtilityController = exports.ESortOrder = exports.ESearchCondition = exports.SDKSearchService = exports.SearchQueryDto = exports.FileUploadJSONDto = exports.FileUploadJSONMiniDto = exports.SDKFileUploadDto = exports.SDKFileUpdateDto = exports.SDKFileSearchDto = exports.SDKFileActionDto = exports.SDKListsEntity = exports.SDKListOptionsEntity = exports.SDKListsController = exports.SDKSaveListOption = exports.SDKSaveListGroupDTO = exports.SDKListsService = exports.SDKListsModule = exports.SDKTelnetService = exports.SDKTelnetModule = exports.SDKTelnetRequestDTO = exports.SDKTelnetController = exports.SDKNotificationItemService = void 0;
|
|
20
20
|
__exportStar(require("./la-library.module"), exports);
|
|
21
21
|
var index_config_1 = require("./configs/index.config");
|
|
22
22
|
Object.defineProperty(exports, "SDKConfig", { enumerable: true, get: function () { return index_config_1.SDKConfig; } });
|
|
@@ -55,6 +55,7 @@ var authentication_guard_1 = require("./modules/authentication/authentication.gu
|
|
|
55
55
|
Object.defineProperty(exports, "SDKAuthenticationGuard", { enumerable: true, get: function () { return authentication_guard_1.AuthenticationGuard; } });
|
|
56
56
|
Object.defineProperty(exports, "SDKPublicAuth", { enumerable: true, get: function () { return authentication_guard_1.PublicAuth; } });
|
|
57
57
|
Object.defineProperty(exports, "AuthParam", { enumerable: true, get: function () { return authentication_guard_1.AuthParam; } });
|
|
58
|
+
Object.defineProperty(exports, "QueryParamAuth", { enumerable: true, get: function () { return authentication_guard_1.QueryParamAuth; } });
|
|
58
59
|
var authentication_service_1 = require("./modules/authentication/authentication.service");
|
|
59
60
|
Object.defineProperty(exports, "SDKAuthenticationService", { enumerable: true, get: function () { return authentication_service_1.AuthenticationService; } });
|
|
60
61
|
Object.defineProperty(exports, "SDKAuthenticationSessionService", { enumerable: true, get: function () { return authentication_service_1.AuthSessionService; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/la-library/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,sDAAoC;AAEpC,uDAAmD;AAA1C,yGAAA,SAAS,OAAA;AAClB,+DAAuD;AAA9C,6GAAA,SAAS,OAAA;AAClB,sEAKwC;AAJtC,4HAAA,qBAAqB,OAAA;AACrB,sHAAA,eAAe,OAAA;AACf,wHAAA,iBAAiB,OAAA;AACjB,6GAAA,GAAG,OAAU;AAEf,+CAG2B;AAFzB,uGAAA,OAAO,OAAc;AACrB,0GAAA,UAAU,OAAiB;AAE7B,2DAAyC;AACzC,8DAA6E;AAApE,kHAAA,YAAY,OAAmB;AACxC,wDAAsD;AAA7C,2GAAA,WAAW,OAAA;AACpB,0DAAwD;AAA/C,yGAAA,UAAU,OAAA;AACn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BAAoB,OAA2B;AAKxD,YAAY;AAEZ,mBAAmB;AACnB,sEAAoD;AACpD,YAAY;AAEZ,oEAAkD;AAClD,mEAAiD;AAEjD,qDAAmC;AACnC,sDAAoC"}
|
|
@@ -5,21 +5,146 @@ import { Reflector } from '@nestjs/core';
|
|
|
5
5
|
import { evt } from '../../services/environment.service';
|
|
6
6
|
import { IAuthParam } from './authentication.interface';
|
|
7
7
|
import { AuthEntity } from './authentication.entity';
|
|
8
|
+
/**
|
|
9
|
+
* Authentication guard that verifies bearer tokens in incoming HTTP requests.
|
|
10
|
+
*
|
|
11
|
+
* @typeParam TEntity - Concrete `AuthEntity` used by the authentication service.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* @UseGuards(AuthenticationGuard)
|
|
16
|
+
* @Controller('account')
|
|
17
|
+
* export class AccountController {
|
|
18
|
+
* @Get()
|
|
19
|
+
* getProfile(@AuthParam() auth: IAuthParam) {
|
|
20
|
+
* return auth;
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
8
25
|
export declare class AuthenticationGuard<TEntity extends AuthEntity = AuthEntity> implements CanActivate {
|
|
9
26
|
protected tokenService: TokenService;
|
|
10
27
|
protected authS: AuthenticationService<TEntity>;
|
|
11
28
|
protected reflector: Reflector;
|
|
29
|
+
/**
|
|
30
|
+
* Environment identifier at which authentication checks are skipped.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* guard.skipEnvironment = 'test';
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
12
37
|
skipEnvironment: typeof evt.ENVIRONMENT;
|
|
13
38
|
constructor(tokenService: TokenService, authS: AuthenticationService<TEntity>, reflector: Reflector);
|
|
39
|
+
/**
|
|
40
|
+
* Optional additional validation executed after the token is verified.
|
|
41
|
+
*
|
|
42
|
+
* @param context - Current execution context.
|
|
43
|
+
* @param payload - Decrypted authentication payload.
|
|
44
|
+
* @param isPublic - Whether the current handler is marked as public.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* guard.extraCheck = async (context, payload) => payload.role === 'admin';
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
14
51
|
extraCheck?: (context: ExecutionContext, payload: IAuthParam, isPublic: boolean) => Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* Verifies the provided authentication token.
|
|
54
|
+
*
|
|
55
|
+
* @param context - Current execution context.
|
|
56
|
+
* @param payload - Payload containing the bearer token.
|
|
57
|
+
* @returns Result of the authentication service verification.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* const isValid = await guard.verifyAuthToken(context, payload);
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
15
64
|
verifyAuthToken(context: ExecutionContext, payload: IAuthParam): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Determines whether a request is allowed to proceed.
|
|
67
|
+
*
|
|
68
|
+
* @param context - Execution context containing the request.
|
|
69
|
+
* @returns Resolves with `true` when the request is authorized.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* const allowed = await guard.canActivate(context);
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
16
76
|
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
77
|
+
/**
|
|
78
|
+
* Extracts the bearer token from the HTTP authorization header.
|
|
79
|
+
*
|
|
80
|
+
* @param request - Incoming HTTP request.
|
|
81
|
+
* @returns The bearer token if present; otherwise `undefined`.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* const token = guard['extractTokenFromHeader'](request);
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
17
88
|
private extractTokenFromHeader;
|
|
89
|
+
private extractTokenFromQueryParam;
|
|
90
|
+
private extractTokenFromTokenString;
|
|
91
|
+
/**
|
|
92
|
+
* Attaches the authentication payload to the request object.
|
|
93
|
+
*
|
|
94
|
+
* @param request - HTTP request being processed.
|
|
95
|
+
* @param payload - Decrypted authentication payload.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* await guard.requestPatcher(req, payload);
|
|
100
|
+
* console.log(req.user);
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
18
103
|
requestPatcher(request: any, payload: any): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Provides the guard as an application-wide provider.
|
|
106
|
+
*
|
|
107
|
+
* @returns Provider definition for the guard.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* @Module({
|
|
112
|
+
* providers: [AuthenticationGuard.provideGuard()],
|
|
113
|
+
* })
|
|
114
|
+
* export class AppModule {}
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
19
117
|
static provideGuard(): {
|
|
20
118
|
provide: string;
|
|
21
119
|
useClass: typeof AuthenticationGuard;
|
|
22
120
|
};
|
|
23
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Marks a route handler as public, bypassing authentication.
|
|
124
|
+
*
|
|
125
|
+
* @returns Metadata decorator indicating the handler is public.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* @PublicAuth()
|
|
130
|
+
* @Get('status')
|
|
131
|
+
* status() {
|
|
132
|
+
* return 'ok';
|
|
133
|
+
* }
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
24
136
|
export declare const PublicAuth: () => import("@nestjs/common").CustomDecorator<string>;
|
|
137
|
+
export declare const QueryParamAuth: () => import("@nestjs/common").CustomDecorator<string>;
|
|
138
|
+
/**
|
|
139
|
+
* Retrieves the authentication payload from the request.
|
|
140
|
+
*
|
|
141
|
+
* @returns Extracted authentication parameter.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* someHandler(@AuthParam() auth) {
|
|
146
|
+
* console.log(auth.id);
|
|
147
|
+
* }
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
25
150
|
export declare const AuthParam: (...dataOrPipes: any[]) => ParameterDecorator;
|
|
@@ -10,7 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
var AuthenticationGuard_1;
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.AuthParam = exports.PublicAuth = exports.AuthenticationGuard = void 0;
|
|
13
|
+
exports.AuthParam = exports.QueryParamAuth = exports.PublicAuth = exports.AuthenticationGuard = void 0;
|
|
14
14
|
const common_1 = require("@nestjs/common");
|
|
15
15
|
const token_service_1 = require("../../services/token.service");
|
|
16
16
|
const authentication_service_1 = require("./authentication.service");
|
|
@@ -18,24 +18,75 @@ const authentication_enum_1 = require("./authentication.enum");
|
|
|
18
18
|
const common_2 = require("@nestjs/common");
|
|
19
19
|
const core_1 = require("@nestjs/core");
|
|
20
20
|
const environment_service_1 = require("../../services/environment.service");
|
|
21
|
+
/**
|
|
22
|
+
* Authentication guard that verifies bearer tokens in incoming HTTP requests.
|
|
23
|
+
*
|
|
24
|
+
* @typeParam TEntity - Concrete `AuthEntity` used by the authentication service.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* @UseGuards(AuthenticationGuard)
|
|
29
|
+
* @Controller('account')
|
|
30
|
+
* export class AccountController {
|
|
31
|
+
* @Get()
|
|
32
|
+
* getProfile(@AuthParam() auth: IAuthParam) {
|
|
33
|
+
* return auth;
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
21
38
|
let AuthenticationGuard = AuthenticationGuard_1 = class AuthenticationGuard {
|
|
22
39
|
constructor(tokenService, authS, reflector) {
|
|
23
40
|
this.tokenService = tokenService;
|
|
24
41
|
this.authS = authS;
|
|
25
42
|
this.reflector = reflector;
|
|
43
|
+
/**
|
|
44
|
+
* Environment identifier at which authentication checks are skipped.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* guard.skipEnvironment = 'test';
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
26
51
|
this.skipEnvironment = 'dev';
|
|
27
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Verifies the provided authentication token.
|
|
55
|
+
*
|
|
56
|
+
* @param context - Current execution context.
|
|
57
|
+
* @param payload - Payload containing the bearer token.
|
|
58
|
+
* @returns Result of the authentication service verification.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const isValid = await guard.verifyAuthToken(context, payload);
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
28
65
|
verifyAuthToken(context, payload) {
|
|
29
66
|
return this.authS.verifyAuthToken(payload.token);
|
|
30
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Determines whether a request is allowed to proceed.
|
|
70
|
+
*
|
|
71
|
+
* @param context - Execution context containing the request.
|
|
72
|
+
* @returns Resolves with `true` when the request is authorized.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* const allowed = await guard.canActivate(context);
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
31
79
|
async canActivate(context) {
|
|
32
80
|
const isPublic = this.reflector.getAllAndOverride(IS_PUBLIC_KEY, [
|
|
33
81
|
context.getHandler(),
|
|
34
82
|
context.getClass(),
|
|
35
83
|
]);
|
|
84
|
+
const isQueryParamAuth = this.reflector.getAllAndOverride(IS_QUERY_PARAM_AUTH_KEY, [context.getHandler(), context.getClass()]);
|
|
36
85
|
// debugger;
|
|
37
86
|
const request = context.switchToHttp().getRequest();
|
|
38
|
-
const token =
|
|
87
|
+
const token = isQueryParamAuth
|
|
88
|
+
? this.extractTokenFromQueryParam(request)
|
|
89
|
+
: this.extractTokenFromHeader(request);
|
|
39
90
|
const skip = environment_service_1.evt.ENVIRONMENT == this.skipEnvironment;
|
|
40
91
|
// const skip = true;
|
|
41
92
|
// const d = evt.ENVIRONMENT;
|
|
@@ -68,13 +119,58 @@ let AuthenticationGuard = AuthenticationGuard_1 = class AuthenticationGuard {
|
|
|
68
119
|
? await this.extraCheck(context, payload, isPublic)
|
|
69
120
|
: true;
|
|
70
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Extracts the bearer token from the HTTP authorization header.
|
|
124
|
+
*
|
|
125
|
+
* @param request - Incoming HTTP request.
|
|
126
|
+
* @returns The bearer token if present; otherwise `undefined`.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* const token = guard['extractTokenFromHeader'](request);
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
71
133
|
extractTokenFromHeader(request) {
|
|
72
|
-
|
|
134
|
+
return this.extractTokenFromTokenString(request.headers.authorization);
|
|
135
|
+
}
|
|
136
|
+
extractTokenFromQueryParam(request) {
|
|
137
|
+
const authorization = request.query.authorization;
|
|
138
|
+
return typeof authorization != 'string'
|
|
139
|
+
? undefined
|
|
140
|
+
: this.extractTokenFromTokenString(authorization);
|
|
141
|
+
}
|
|
142
|
+
extractTokenFromTokenString(tokenString) {
|
|
143
|
+
const [type, token] = tokenString?.split(' ') ?? [];
|
|
73
144
|
return type === 'Bearer' ? token : undefined;
|
|
74
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Attaches the authentication payload to the request object.
|
|
148
|
+
*
|
|
149
|
+
* @param request - HTTP request being processed.
|
|
150
|
+
* @param payload - Decrypted authentication payload.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* await guard.requestPatcher(req, payload);
|
|
155
|
+
* console.log(req.user);
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
75
158
|
async requestPatcher(request, payload) {
|
|
76
159
|
request['user'] = payload || null;
|
|
77
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Provides the guard as an application-wide provider.
|
|
163
|
+
*
|
|
164
|
+
* @returns Provider definition for the guard.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* @Module({
|
|
169
|
+
* providers: [AuthenticationGuard.provideGuard()],
|
|
170
|
+
* })
|
|
171
|
+
* export class AppModule {}
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
78
174
|
static provideGuard() {
|
|
79
175
|
return {
|
|
80
176
|
provide: core_1.APP_GUARD,
|
|
@@ -90,7 +186,36 @@ exports.AuthenticationGuard = AuthenticationGuard = AuthenticationGuard_1 = __de
|
|
|
90
186
|
core_1.Reflector])
|
|
91
187
|
], AuthenticationGuard);
|
|
92
188
|
const IS_PUBLIC_KEY = 'isPublic';
|
|
189
|
+
/**
|
|
190
|
+
* Marks a route handler as public, bypassing authentication.
|
|
191
|
+
*
|
|
192
|
+
* @returns Metadata decorator indicating the handler is public.
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```ts
|
|
196
|
+
* @PublicAuth()
|
|
197
|
+
* @Get('status')
|
|
198
|
+
* status() {
|
|
199
|
+
* return 'ok';
|
|
200
|
+
* }
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
93
203
|
const PublicAuth = () => (0, common_2.SetMetadata)(IS_PUBLIC_KEY, true);
|
|
94
204
|
exports.PublicAuth = PublicAuth;
|
|
205
|
+
const IS_QUERY_PARAM_AUTH_KEY = 'IS_QUERY_PARAM_AUTH';
|
|
206
|
+
const QueryParamAuth = () => (0, common_2.SetMetadata)(IS_QUERY_PARAM_AUTH_KEY, true);
|
|
207
|
+
exports.QueryParamAuth = QueryParamAuth;
|
|
208
|
+
/**
|
|
209
|
+
* Retrieves the authentication payload from the request.
|
|
210
|
+
*
|
|
211
|
+
* @returns Extracted authentication parameter.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```ts
|
|
215
|
+
* someHandler(@AuthParam() auth) {
|
|
216
|
+
* console.log(auth.id);
|
|
217
|
+
* }
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
95
220
|
exports.AuthParam = (0, common_1.createParamDecorator)((data, req) => req.getArgByIndex(0).user);
|
|
96
221
|
//# sourceMappingURL=authentication.guard.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.guard.js","sourceRoot":"","sources":["../../../../../../libs/la-library/src/modules/authentication/authentication.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAMwB;AAExB,gEAA4D;AAC5D,qEAAiE;AACjE,+DAAuD;AACvD,2CAA6C;AAC7C,uCAAoD;AACpD,4EAAyD;
|
|
1
|
+
{"version":3,"file":"authentication.guard.js","sourceRoot":"","sources":["../../../../../../libs/la-library/src/modules/authentication/authentication.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAMwB;AAExB,gEAA4D;AAC5D,qEAAiE;AACjE,+DAAuD;AACvD,2CAA6C;AAC7C,uCAAoD;AACpD,4EAAyD;AAIzD;;;;;;;;;;;;;;;;GAgBG;AAEI,IAAM,mBAAmB,2BAAzB,MAAM,mBAAmB;IAY9B,YACY,YAA0B,EAC1B,KAAqC,EACrC,SAAoB;QAFpB,iBAAY,GAAZ,YAAY,CAAc;QAC1B,UAAK,GAAL,KAAK,CAAgC;QACrC,cAAS,GAAT,SAAS,CAAW;QAZhC;;;;;;;WAOG;QACH,oBAAe,GAA2B,KAAK,CAAC;IAK7C,CAAC;IAoBJ;;;;;;;;;;;OAWG;IACH,eAAe,CAAC,OAAyB,EAAE,OAAmB;QAC5D,OAAO,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACnD,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,WAAW,CAAC,OAAyB;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAU,aAAa,EAAE;YACxE,OAAO,CAAC,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