Browse Source

Fix internal server error caused by invalid device id in biometric authentication

pull/7915/head
Thomas Kaul 4 weeks ago
parent
commit
9333135ca5
  1. 3
      apps/api/src/app/auth/auth.controller.ts
  2. 6
      apps/api/src/app/auth/generate-authentication-options.dto.ts
  3. 5
      apps/api/src/app/auth/web-auth.service.ts

3
apps/api/src/app/auth/auth.controller.ts

@ -28,6 +28,7 @@ import { Request, Response } from 'express';
import { getReasonPhrase, StatusCodes } from 'http-status-codes'; import { getReasonPhrase, StatusCodes } from 'http-status-codes';
import { AuthService } from './auth.service'; import { AuthService } from './auth.service';
import { GenerateAuthenticationOptionsDto } from './generate-authentication-options.dto';
@AllowDuringImpersonation() @AllowDuringImpersonation()
@Controller('auth') @Controller('auth')
@ -122,7 +123,7 @@ export class AuthController {
@Post('webauthn/generate-authentication-options') @Post('webauthn/generate-authentication-options')
@UseGuards(CustomThrottlerGuard) @UseGuards(CustomThrottlerGuard)
public async generateAuthenticationOptions( public async generateAuthenticationOptions(
@Body() body: { deviceId: string } @Body() body: GenerateAuthenticationOptionsDto
) { ) {
return this.webAuthService.generateAuthenticationOptions(body.deviceId); return this.webAuthService.generateAuthenticationOptions(body.deviceId);
} }

6
apps/api/src/app/auth/generate-authentication-options.dto.ts

@ -0,0 +1,6 @@
import { IsUUID } from 'class-validator';
export class GenerateAuthenticationOptionsDto {
@IsUUID()
deviceId: string;
}

5
apps/api/src/app/auth/web-auth.service.ts

@ -21,7 +21,8 @@ import {
Inject, Inject,
Injectable, Injectable,
InternalServerErrorException, InternalServerErrorException,
Logger Logger,
NotFoundException
} from '@nestjs/common'; } from '@nestjs/common';
import { REQUEST } from '@nestjs/core'; import { REQUEST } from '@nestjs/core';
import { JwtService } from '@nestjs/jwt'; import { JwtService } from '@nestjs/jwt';
@ -170,7 +171,7 @@ export class WebAuthService {
const device = await this.deviceService.authDevice({ id: deviceId }); const device = await this.deviceService.authDevice({ id: deviceId });
if (!device) { if (!device) {
throw new Error('Device not found'); throw new NotFoundException('Device not found');
} }
// Compute in the background during the biometric authentication // Compute in the background during the biometric authentication

Loading…
Cancel
Save