Skip to content

Commit

Permalink
added auth to identity
Browse files Browse the repository at this point in the history
  • Loading branch information
KDwevedi committed Dec 24, 2024
1 parent fbd6173 commit 6aa8346
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 32 deletions.
5 changes: 4 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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
C4GT_BFF_POSTGRES_BASE_URL=postgresql://postgres:password@localhost:5432/c4gtbff?schema=public

# Auth
ADMIN_TOKEN=supersecretadmintoken
6 changes: 5 additions & 1 deletion nest-cli.json
Original file line number Diff line number Diff line change
@@ -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
}
}
25 changes: 0 additions & 25 deletions src/identity/config.json

This file was deleted.

4 changes: 3 additions & 1 deletion src/identity/identity.controller.ts
Original file line number Diff line number Diff line change
@@ -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) {}

Expand Down
30 changes: 26 additions & 4 deletions src/identity/identity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RCWIdentityConfig>('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;
Expand Down

0 comments on commit 6aa8346

Please sign in to comment.