From 6aa83462b30f58d78a7b32e14da1fcb4006e09f4 Mon Sep 17 00:00:00 2001 From: KDwevedi Date: Tue, 24 Dec 2024 08:12:38 +0530 Subject: [PATCH] added auth to identity --- .env.sample | 5 ++++- nest-cli.json | 6 +++++- src/identity/config.json | 25 ------------------------ src/identity/identity.controller.ts | 4 +++- src/identity/identity.service.ts | 30 +++++++++++++++++++++++++---- 5 files changed, 38 insertions(+), 32 deletions(-) delete mode 100644 src/identity/config.json diff --git a/.env.sample b/.env.sample index f2b4a36..18d1aa9 100644 --- a/.env.sample +++ b/.env.sample @@ -23,4 +23,7 @@ MINIO_ACCESS_KEY=minioadmin MINIO_USE_SSL=true # DB Config -C4GT_BFF_POSTGRES_BASE_URL=postgresql://postgres:password@localhost:5432/c4gtbff?schema=public \ No newline at end of file +C4GT_BFF_POSTGRES_BASE_URL=postgresql://postgres:password@localhost:5432/c4gtbff?schema=public + +# Auth +ADMIN_TOKEN=supersecretadmintoken \ No newline at end of file diff --git a/nest-cli.json b/nest-cli.json index 2566481..958e173 100644 --- a/nest-cli.json +++ b/nest-cli.json @@ -1,5 +1,9 @@ { "$schema": "https://json.schemastore.org/nest-cli", "collection": "@nestjs/schematics", - "sourceRoot": "src" + "sourceRoot": "src", + "compilerOptions": { + "assets": ["src/identity/config.json"], + "watchAssets": true + } } diff --git a/src/identity/config.json b/src/identity/config.json deleted file mode 100644 index 60604cb..0000000 --- a/src/identity/config.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "content": [ - { - "alsoKnownAs": [ - "C4GT", - "https://www.codeforgovtech.in/" - ], - "services": [ - { - "id": "C4GT", - "type": "IdentityHub", - "serviceEndpoint": { - "@context": "schema.c4gt.acknowledgment", - "@type": "UserServiceEndpoint", - "instance": [ - "https://www.codeforgovtech.in" - ] - } - } - ], - "method": "C4GT" - } - ] - } - \ No newline at end of file diff --git a/src/identity/identity.controller.ts b/src/identity/identity.controller.ts index 2bb7b3c..d7221fe 100644 --- a/src/identity/identity.controller.ts +++ b/src/identity/identity.controller.ts @@ -1,7 +1,9 @@ -import { Controller, Post, Get, Body, Param } from '@nestjs/common'; +import { Controller, Post, Get, Param, UseInterceptors } from '@nestjs/common'; +import { AdminTokenInterceptor } from 'src/auth/auth.interceptor'; import { IdentityService } from './identity.service'; @Controller('identity') +@UseInterceptors(AdminTokenInterceptor) export class IdentityController { constructor(private readonly identityService: IdentityService) {} diff --git a/src/identity/identity.service.ts b/src/identity/identity.service.ts index 5376dae..fb0db05 100644 --- a/src/identity/identity.service.ts +++ b/src/identity/identity.service.ts @@ -12,22 +12,44 @@ interface RCWIdentityConfig { @Injectable() export class IdentityService { private readonly config; + private didPayload; constructor( private readonly configService: ConfigService, private readonly httpService: HttpService ) { this.config = this.configService.get('identityService'); + this.didPayload = { + "content": [ + { + "alsoKnownAs": [ + "C4GT", + "https://www.codeforgovtech.in/" + ], + "services": [ + { + "id": "C4GT", + "type": "IdentityHub", + "serviceEndpoint": { + "@context": "schema.c4gt.acknowledgment", + "@type": "UserServiceEndpoint", + "instance": [ + "https://www.codeforgovtech.in" + ] + } + } + ], + "method": "C4GT" + } + ] + } } async generateIdentity() { try { - const configPath = path.resolve(__dirname, '../config.json'); - const requestBody = JSON.parse(fs.readFileSync(configPath, 'utf8')); - const generateUrl = `${this.config.baseUrl}/did/generate`; - const response = await this.httpService.axiosRef.post(generateUrl, requestBody, { + const response = await this.httpService.axiosRef.post(generateUrl, this.didPayload, { headers: { 'Content-Type': 'application/json' }, }); return response.data;