@simitgroup/simpleapp-generator 1.6.6-a-alpha → 1.6.6-c-alpha
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/ReleaseNote.md
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2024-06-21
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
7
|
+
import {
|
|
8
|
+
Injectable,
|
|
9
|
+
CanActivate,
|
|
10
|
+
ExecutionContext,
|
|
11
|
+
UnauthorizedException,
|
|
12
|
+
} from '@nestjs/common';
|
|
13
|
+
import { Reflector } from '@nestjs/core';
|
|
14
|
+
import { ResourceGuard } from 'nest-keycloak-connect';
|
|
15
|
+
|
|
16
|
+
@Injectable()
|
|
17
|
+
export class CustomKeycloakGuard implements CanActivate {
|
|
18
|
+
constructor(
|
|
19
|
+
private reflector: Reflector,
|
|
20
|
+
private resourceGuard: ResourceGuard,
|
|
21
|
+
) {}
|
|
22
|
+
|
|
23
|
+
async canActivate(context: ExecutionContext): Promise<boolean> {
|
|
24
|
+
const request = context.switchToHttp().getRequest();
|
|
25
|
+
|
|
26
|
+
//graphql no http request, exclude from capability of x-apikey
|
|
27
|
+
if (request?.headers) {
|
|
28
|
+
const apiKey = request.headers['x-apikey'];
|
|
29
|
+
const apiSecret = request.headers['x-apisecret'];
|
|
30
|
+
// validate apikey and apisecret at middleware level, reach here mean approved as robot
|
|
31
|
+
if (apiKey && apiSecret) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// If API key is not present, fall back to Keycloak authentication
|
|
37
|
+
try {
|
|
38
|
+
const canActivate = await this.resourceGuard.canActivate(context);
|
|
39
|
+
return canActivate as boolean;
|
|
40
|
+
} catch (error) {
|
|
41
|
+
throw new UnauthorizedException('Invalid API key or Keycloak token');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// private validateApiKey(apiKey: string, apiSecret: string): boolean {
|
|
46
|
+
// // Implement your API key and secret validation logic here
|
|
47
|
+
// // This is just a simple example
|
|
48
|
+
// return apiKey === 'your-valid-api-key' && apiSecret === 'your-valid-api-secret';
|
|
49
|
+
// }
|
|
50
|
+
}
|
|
51
|
+
|
|
@@ -1084,7 +1084,7 @@ export class SimpleAppService<T extends { _id?: string; __v?: number }> {
|
|
|
1084
1084
|
});
|
|
1085
1085
|
pipelines.push({ $sort: sortobj });
|
|
1086
1086
|
}
|
|
1087
|
-
this.logger.warn( pipelines,'pipelinespipelinespipelines',);
|
|
1087
|
+
//this.logger.warn( pipelines,'pipelinespipelinespipelines',);
|
|
1088
1088
|
|
|
1089
1089
|
return pipelines;
|
|
1090
1090
|
}
|