Skip to content

Commit 6aa8346

Browse files
committed
added auth to identity
1 parent fbd6173 commit 6aa8346

File tree

5 files changed

+38
-32
lines changed

5 files changed

+38
-32
lines changed

.env.sample

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ MINIO_ACCESS_KEY=minioadmin
2323
MINIO_USE_SSL=true
2424

2525
# DB Config
26-
C4GT_BFF_POSTGRES_BASE_URL=postgresql://postgres:password@localhost:5432/c4gtbff?schema=public
26+
C4GT_BFF_POSTGRES_BASE_URL=postgresql://postgres:password@localhost:5432/c4gtbff?schema=public
27+
28+
# Auth
29+
ADMIN_TOKEN=supersecretadmintoken

nest-cli.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"$schema": "https://json.schemastore.org/nest-cli",
33
"collection": "@nestjs/schematics",
4-
"sourceRoot": "src"
4+
"sourceRoot": "src",
5+
"compilerOptions": {
6+
"assets": ["src/identity/config.json"],
7+
"watchAssets": true
8+
}
59
}

src/identity/config.json

-25
This file was deleted.

src/identity/identity.controller.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { Controller, Post, Get, Body, Param } from '@nestjs/common';
1+
import { Controller, Post, Get, Param, UseInterceptors } from '@nestjs/common';
2+
import { AdminTokenInterceptor } from 'src/auth/auth.interceptor';
23
import { IdentityService } from './identity.service';
34

45
@Controller('identity')
6+
@UseInterceptors(AdminTokenInterceptor)
57
export class IdentityController {
68
constructor(private readonly identityService: IdentityService) {}
79

src/identity/identity.service.ts

+26-4
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,44 @@ interface RCWIdentityConfig {
1212
@Injectable()
1313
export class IdentityService {
1414
private readonly config;
15+
private didPayload;
1516

1617
constructor(
1718
private readonly configService: ConfigService,
1819
private readonly httpService: HttpService
1920
) {
2021
this.config = this.configService.get<RCWIdentityConfig>('identityService');
22+
this.didPayload = {
23+
"content": [
24+
{
25+
"alsoKnownAs": [
26+
"C4GT",
27+
"https://www.codeforgovtech.in/"
28+
],
29+
"services": [
30+
{
31+
"id": "C4GT",
32+
"type": "IdentityHub",
33+
"serviceEndpoint": {
34+
"@context": "schema.c4gt.acknowledgment",
35+
"@type": "UserServiceEndpoint",
36+
"instance": [
37+
"https://www.codeforgovtech.in"
38+
]
39+
}
40+
}
41+
],
42+
"method": "C4GT"
43+
}
44+
]
45+
}
2146
}
2247

2348
async generateIdentity() {
2449
try {
25-
const configPath = path.resolve(__dirname, '../config.json');
26-
const requestBody = JSON.parse(fs.readFileSync(configPath, 'utf8'));
27-
2850
const generateUrl = `${this.config.baseUrl}/did/generate`;
2951

30-
const response = await this.httpService.axiosRef.post(generateUrl, requestBody, {
52+
const response = await this.httpService.axiosRef.post(generateUrl, this.didPayload, {
3153
headers: { 'Content-Type': 'application/json' },
3254
});
3355
return response.data;

0 commit comments

Comments
 (0)