From 59c3ce7ed96f489b82e572d8384007cf784ab43c Mon Sep 17 00:00:00 2001 From: Gabriel Rosa Date: Fri, 16 Dec 2022 08:09:20 -0300 Subject: [PATCH] FIX: do not use User() on non-authenticated routes --- docsfera.json | 27 ++++++++++++++++++++++++++- src/modules/auth/auth.controller.ts | 13 ++++++++----- src/modules/auth/dtos/login.ts | 7 +++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/docsfera.json b/docsfera.json index 0701ee4..fef3b5a 100644 --- a/docsfera.json +++ b/docsfera.json @@ -79,6 +79,16 @@ } } ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/AuthRefreshAccessTokenReq" + } + } + } + }, "responses": { "200": { "description": "", @@ -3287,7 +3297,7 @@ } }, "info": { - "title": "Maestro - feat/update-connection", + "title": "Maestro - fix/refresh-token", "description": "Documentation for Maestro gateway", "version": "1.0.0", "contact": {} @@ -3473,6 +3483,21 @@ "mfaStatus" ] }, + "AuthRefreshAccessTokenReq": { + "type": "object", + "properties": { + "refreshToken": { + "type": "string" + }, + "customerName": { + "type": "string" + } + }, + "required": [ + "refreshToken", + "customerName" + ] + }, "CreateConnectorDto": { "type": "object", "properties": { diff --git a/src/modules/auth/auth.controller.ts b/src/modules/auth/auth.controller.ts index 2c85de5..16a9a52 100644 --- a/src/modules/auth/auth.controller.ts +++ b/src/modules/auth/auth.controller.ts @@ -11,7 +11,6 @@ import { } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { - AuthRefreshAccessTokenRequest, AuthChangePasswordRequest, AuthResetPasswordRequest, AuthVerifyResetPasswordCodeRequest, @@ -31,7 +30,11 @@ import { DadosferaLogger } from '@dadosfera/dadosfera-logs'; import { GrpcToHttpExceptionFilter } from '../../error/grpc-to-http-exception.filter'; import { RequestUser, User } from 'src/authentication/user.decorator'; import { Metadata } from '@grpc/grpc-js'; -import { AuthSignInReq, AuthSignInRes } from './dtos/login'; +import { + AuthRefreshAccessTokenReq, + AuthSignInReq, + AuthSignInRes, +} from './dtos/login'; import { PackTheMetadata } from 'src/utils/ PackTheMetadata'; @ApiTags('Auth') @@ -78,14 +81,14 @@ export class AuthController { @Post('refresh-access-token') @HttpCode(HttpStatus.OK) async refreshAccessToken( - @Body() { refreshToken }: AuthRefreshAccessTokenRequest, + @Body() + { refreshToken, customerName: customer_name }: AuthRefreshAccessTokenReq, @Headers('Dadosfera-Lang') language: string, - @User() user: RequestUser, ) { this.logger.info('/auth - RefreshAccessToken'); const metadata = PackTheMetadata({ - customer_name: user.customer_name, + customer_name, language, }); diff --git a/src/modules/auth/dtos/login.ts b/src/modules/auth/dtos/login.ts index 32e1885..1c9b1a3 100644 --- a/src/modules/auth/dtos/login.ts +++ b/src/modules/auth/dtos/login.ts @@ -97,3 +97,10 @@ export class AuthSignInRes implements AuthSignInResponse { @ApiPropertyOptional() termsOfUse?: TermsOfUseStatus; } + +export class AuthRefreshAccessTokenReq { + @ApiProperty() + refreshToken: string; + @ApiProperty() + customerName: string; +}