feat: Manage Images using Minio Service
This commit is contained in:
parent
5e5ecb6cd1
commit
bdbbaeaa65
@ -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<string>('USER_SERVICE') || 'http://localhost:3001';
|
||||
|
||||
const keycloakUrl = this.configService.get<string>('KEYCLOAK_SERVER_URL');
|
||||
const keycloakRealm = this.configService.get<string>('KEYCLOAK_REALM');
|
||||
const clientId = this.configService.get<string>('KEYCLOAK_CLIENT_ID');
|
||||
const clientSecret = this.configService.get<string>('KEYCLOAK_CLIENT_SECRET');
|
||||
}
|
||||
|
||||
if (!keycloakUrl || !keycloakRealm || !clientId || !clientSecret) {
|
||||
throw new Error('Missing required Keycloak configuration');
|
||||
// === CONFIGURATION ===
|
||||
private getKeycloakConfig(): KeycloakConfig {
|
||||
const config = this.configService.get<KeycloakConfig>('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<string> {
|
||||
@ -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(), {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user