From 69c1802b379a91409f0703e8d9bd80ca2e9ab72e Mon Sep 17 00:00:00 2001 From: Tino Hager Date: Mon, 17 Jun 2024 11:12:19 +0200 Subject: [PATCH] Optimize api documentation --- .../Controllers/UserAccountController.cs | 12 ++++++++---- .../Dtos/MfaErrorResponseDto.cs | 7 +++++++ .../Nager.Authentication.AspNet.csproj | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 src/Nager.Authentication.AspNet/Dtos/MfaErrorResponseDto.cs diff --git a/src/Nager.Authentication.AspNet/Controllers/UserAccountController.cs b/src/Nager.Authentication.AspNet/Controllers/UserAccountController.cs index f889ac1..9c76ded 100644 --- a/src/Nager.Authentication.AspNet/Controllers/UserAccountController.cs +++ b/src/Nager.Authentication.AspNet/Controllers/UserAccountController.cs @@ -106,11 +106,13 @@ public async Task GetMfaActivationAsync( /// /// /// - /// Password changed + /// Mfa activated + /// Mfa workflow error /// Unexpected error [HttpPost] [Route("Mfa/Activate")] [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(MfaErrorResponseDto))] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task ActivateMfaAsync( [Required][FromBody] TimeBasedOneTimeTokenRequestDto request, @@ -135,7 +137,7 @@ public async Task ActivateMfaAsync( case MfaActivationResult.AlreadyActive: case MfaActivationResult.InvalidCode: - return StatusCode(StatusCodes.Status400BadRequest, new { error = mfaResult.ToString() }); + return StatusCode(StatusCodes.Status400BadRequest, new MfaErrorResponseDto { Error = mfaResult.ToString() }); default: return StatusCode(StatusCodes.Status500InternalServerError); @@ -148,11 +150,13 @@ public async Task ActivateMfaAsync( /// /// /// - /// Password changed + /// Mfa deactivated + /// Mfa workflow error /// Unexpected error [HttpPost] [Route("Mfa/Deactivate")] [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(MfaErrorResponseDto))] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task DeactivateMfaAsync( [Required][FromBody] TimeBasedOneTimeTokenRequestDto request, @@ -177,7 +181,7 @@ public async Task DeactivateMfaAsync( case MfaDeactivationResult.NotActive: case MfaDeactivationResult.InvalidCode: - return StatusCode(StatusCodes.Status400BadRequest, new { error = mfaResult.ToString() }); + return StatusCode(StatusCodes.Status400BadRequest, new MfaErrorResponseDto { Error = mfaResult.ToString() }); default: return StatusCode(StatusCodes.Status500InternalServerError); diff --git a/src/Nager.Authentication.AspNet/Dtos/MfaErrorResponseDto.cs b/src/Nager.Authentication.AspNet/Dtos/MfaErrorResponseDto.cs new file mode 100644 index 0000000..7b4b010 --- /dev/null +++ b/src/Nager.Authentication.AspNet/Dtos/MfaErrorResponseDto.cs @@ -0,0 +1,7 @@ +namespace Nager.Authentication.AspNet.Dtos +{ + public class MfaErrorResponseDto + { + public string Error { get; set; } + } +} diff --git a/src/Nager.Authentication.AspNet/Nager.Authentication.AspNet.csproj b/src/Nager.Authentication.AspNet/Nager.Authentication.AspNet.csproj index cad763a..c4eeb55 100644 --- a/src/Nager.Authentication.AspNet/Nager.Authentication.AspNet.csproj +++ b/src/Nager.Authentication.AspNet/Nager.Authentication.AspNet.csproj @@ -18,7 +18,7 @@ net8.0;net7.0;net6.0 enable - 2.0.1 + 2.0.2