FIX: auth callback

This commit is contained in:
marcos-silva-rodrigues
2025-07-14 10:51:36 -03:00
parent d3040cd5a8
commit cbe5556ac9
3 changed files with 11 additions and 8 deletions
@@ -122,11 +122,14 @@ export class IdentityProviderController {
return await this.identityProviderService.updateIdentityProviders(id, body, metadata);
}
@Get('/callback')
@Post('/callback')
@HttpCode(HttpStatus.OK)
async callbackIdp(@Req() req: Request) {
async callbackIdp(@Req() req: Request, @Body() body: {
state: string,
code: string
}) {
this.logger.info('GET /identity-providers/callback');
const { code, state } = req.query;
const { code, state } = body;
if (!code) {
this.logger.error('No code received from IDP');
@@ -138,7 +141,7 @@ export class IdentityProviderController {
throw new Error(ErrorCodes.IDENTITY_PROVIDER.INVALID_RESPONSE);
}
return await this.identityProviderService.getTokenByIdp(req);
return await this.identityProviderService.getTokenByIdp(code, state);
}
@Get(':id')
@@ -95,8 +95,8 @@ export class IdentityProviderService implements OnModuleInit {
return COGNITO_ISSUER_URL;
}
async getTokenByIdp(req: Request) {
const ssoSign = await this.cacheService.get(req.query.state as string);
async getTokenByIdp(code: string, state: string) {
const ssoSign = await this.cacheService.get(state);
if (!ssoSign) {
throw new BadRequestException('SSO sign-in is expired or not found');
@@ -115,7 +115,7 @@ export class IdentityProviderService implements OnModuleInit {
throw new BadRequestException('SSO sign-in is expired or not found');
}
const params = client.callbackParams(req)
const params = client.callbackParams(`${callbackUrl}?code=${code}&state=${state}`);
const tokenSet = await client.callback(
callbackUrl,
params,