From dc7f101d2d501230b52ac6b24c3a936d21875ec2 Mon Sep 17 00:00:00 2001 From: Yorick de Wid Date: Mon, 18 Dec 2023 13:16:46 +0100 Subject: [PATCH] Remove unnecessary code related to authentication --- .../Controllers/AuthController.cs | 6 ------ .../Controllers/AuthTests.cs | 15 ++++----------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/FunderMaps.Webservice/Controllers/AuthController.cs b/src/FunderMaps.Webservice/Controllers/AuthController.cs index 59ad40c1..80ac9213 100644 --- a/src/FunderMaps.Webservice/Controllers/AuthController.cs +++ b/src/FunderMaps.Webservice/Controllers/AuthController.cs @@ -2,8 +2,6 @@ using FunderMaps.Core.Controllers; using FunderMaps.Core.DataTransferObjects; using FunderMaps.Core.Services; -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -27,8 +25,6 @@ public async Task SignInAsync([FromBody] SignInDto input { var principal = await signInService.PasswordSignInAsync(input.Email, input.Password, "FunderMapsHybridAuth"); - await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal); - var tokenContext = tokenService.GetTokenContext(principal); return new SignInSecurityTokenDto() { @@ -51,8 +47,6 @@ public async Task RefreshSignInAsync() { var principal = await signInService.UserIdSignInAsync(UserId, "FunderMapsHybridAuth"); - await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal); - var tokenContext = tokenService.GetTokenContext(principal); return new SignInSecurityTokenDto() { diff --git a/tests/FunderMaps.Webservice.Tests/Controllers/AuthTests.cs b/tests/FunderMaps.Webservice.Tests/Controllers/AuthTests.cs index 7e189c0b..565658fa 100644 --- a/tests/FunderMaps.Webservice.Tests/Controllers/AuthTests.cs +++ b/tests/FunderMaps.Webservice.Tests/Controllers/AuthTests.cs @@ -24,7 +24,7 @@ public async Task SignInReturnSuccessAndToken(string email) { using var client = factory.CreateClient(); - var response = await client.PostAsJsonAsync("api/auth/signin", new SignInDto() + var response = await client.PostAsJsonAsync("api/auth/signin", new SignInDto { Email = email, Password = "fundermaps", @@ -44,7 +44,7 @@ public async Task RefreshSignInReturnSuccessAndToken() { using var client = factory.CreateClient(); - var authResponse = await client.PostAsJsonAsync("api/auth/signin", new SignInDto() + var authResponse = await client.PostAsJsonAsync("api/auth/signin", new SignInDto { Email = "lester@contoso.com", Password = "fundermaps", @@ -96,14 +96,8 @@ public async Task SignInInvalidCredentialsReturnError() Email = "lester@contoso.com", Password = new Randomizer().Password(64), }); - // var returnObject = await response.Content.ReadFromJsonAsync(); - - Assert.NotEqual(HttpStatusCode.OK, response.StatusCode); - // Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); - // Assert.NotNull(returnObject); - // Assert.Equal((short)HttpStatusCode.Unauthorized, returnObject.Status); - // Assert.Contains("Login", returnObject.Title, StringComparison.InvariantCultureIgnoreCase); + Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); } [Theory] @@ -130,7 +124,6 @@ public async Task RefreshSignInReturnUnauthorized() var response = await client.GetAsync("api/auth/token-refresh"); - // Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); - Assert.NotEqual(HttpStatusCode.OK, response.StatusCode); + Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); } }