From bdbbaeaa65ef99952316ef9b1281aa3e0de2e8a1 Mon Sep 17 00:00:00 2001 From: diallolatoile Date: Tue, 13 Jan 2026 04:00:22 +0000 Subject: [PATCH] feat: Manage Images using Minio Service --- src/merchant/services/user.service.client.ts | 32 ++++++++------------ 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/merchant/services/user.service.client.ts b/src/merchant/services/user.service.client.ts index 3b3f6a8..42eb6aa 100644 --- a/src/merchant/services/user.service.client.ts +++ b/src/merchant/services/user.service.client.ts @@ -3,14 +3,12 @@ import { HttpService } from '@nestjs/axios'; import { ConfigService } from '@nestjs/config'; import { firstValueFrom } from 'rxjs'; import { UserInfo, UserServiceClient } from '../interfaces/user.service.interface'; +import { KeycloakConfig } from 'src/config/keycloak.config'; @Injectable() export class HttpUserServiceClient implements UserServiceClient { private readonly baseUrl: string; - private readonly keycloakUrl: string; - private readonly keycloakRealm: string; - private readonly clientId: string; - private readonly clientSecret: string; + private readonly keycloakConfig: KeycloakConfig; private accessToken: string | null = null; private tokenExpiry: number = 0; @@ -19,21 +17,17 @@ export class HttpUserServiceClient implements UserServiceClient { private readonly httpService: HttpService, private readonly configService: ConfigService, ) { + this.keycloakConfig = this.getKeycloakConfig(); this.baseUrl = this.configService.get('USER_SERVICE') || 'http://localhost:3001'; - - const keycloakUrl = this.configService.get('KEYCLOAK_SERVER_URL'); - const keycloakRealm = this.configService.get('KEYCLOAK_REALM'); - const clientId = this.configService.get('KEYCLOAK_CLIENT_ID'); - const clientSecret = this.configService.get('KEYCLOAK_CLIENT_SECRET'); + } - if (!keycloakUrl || !keycloakRealm || !clientId || !clientSecret) { - throw new Error('Missing required Keycloak configuration'); + // === CONFIGURATION === + private getKeycloakConfig(): KeycloakConfig { + const config = this.configService.get('keycloak'); + if (!config) { + throw new Error('Keycloak configuration not found'); } - - this.keycloakUrl = keycloakUrl; - this.keycloakRealm = keycloakRealm; - this.clientId = clientId; - this.clientSecret = clientSecret; + return config; } private async getAccessToken(): Promise { @@ -43,12 +37,12 @@ export class HttpUserServiceClient implements UserServiceClient { } try { - const tokenUrl = `${this.keycloakUrl}/realms/${this.keycloakRealm}/protocol/openid-connect/token`; + const tokenUrl = `${this.keycloakConfig.serverUrl}/realms/${this.keycloakConfig.realm}/protocol/openid-connect/token`; const params = new URLSearchParams(); params.append('grant_type', 'client_credentials'); - params.append('client_id', this.clientId); - params.append('client_secret', this.clientSecret); + params.append('client_id', this.keycloakConfig.authClientId); + params.append('client_secret', this.keycloakConfig.authClientSecret); const response = await firstValueFrom( this.httpService.post(tokenUrl, params.toString(), {