From bb671a90d61310cbc35e765c637ee0cec04ee1e1 Mon Sep 17 00:00:00 2001 From: Marcos Rodrigues Date: Wed, 3 Dec 2025 15:20:41 -0300 Subject: [PATCH] FIX: change origin to host --- src/modules/auth/auth.service.ts | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/modules/auth/auth.service.ts b/src/modules/auth/auth.service.ts index 3229752..c1b85f6 100644 --- a/src/modules/auth/auth.service.ts +++ b/src/modules/auth/auth.service.ts @@ -3,7 +3,8 @@ import { Inject, Injectable, ForbiddenException, - UnauthorizedException, + HttpException, + HttpStatus, } from '@nestjs/common'; import { ClientGrpc } from '@nestjs/microservices'; import { DadosferaLogger } from '@dadosfera/dadosfera-logs'; @@ -12,7 +13,6 @@ import { lastValueFrom } from 'rxjs'; import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Duc'; import { AuthProtoService as AuthServiceInterface, - IdentityProviderProtoService, UsersProtoService, } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/write-service'; import { @@ -304,12 +304,12 @@ export class AuthClientService implements OnModuleInit { } } - public async validateUserSession(accessToken: any, originHeader: string) { + public async validateUserSession(accessToken: any, resourceHost: string) { const payload = await this.validateJwtToken(accessToken); const userDto = await this.getUserfromPayload(payload); - this.validateResourceAccess(originHeader, userDto); + this.validateResourceAccess(resourceHost, userDto); return userDto; } @@ -460,18 +460,30 @@ export class AuthClientService implements OnModuleInit { const domain = hostParts[0]; const isResouceStg = hostParts[1] === 'stg'; + const notFoundCustomerInDomain = !domain.includes('-') + + if (notFoundCustomerInDomain) { + this.logger.info(`Not found Customer Name in domain`); + return; + } + const domainParts = domain.split('-'); + const customerInDomain = domainParts[domainParts.length - 1]; if (isResouceStg && process.env.ENV !== 'stg') { - throw new ForbiddenException( - `Customer ${user.customer.name} cannot access ${origin}`, + this.logger.error(`Customer ${user.customer.name} cannot access ${host}`); + throw new HttpException( + `Customer ${user.customer.name} cannot access ${host}`, + HttpStatus.FORBIDDEN ); } if (customerInDomain != user.customer.name) { - throw new ForbiddenException( - `Customer ${user.customer.name} cannot access ${origin}`, + this.logger.error(`Customer ${user.customer.name} cannot access ${host}`); + throw new HttpException( + `Customer ${user.customer.name} cannot access ${host}`, + HttpStatus.FORBIDDEN ); }