diff --git a/Web/Controllers/AuthenticationController.cs b/Web/Controllers/AuthenticationController.cs index 0b27813..7ec6f44 100644 --- a/Web/Controllers/AuthenticationController.cs +++ b/Web/Controllers/AuthenticationController.cs @@ -2,13 +2,14 @@ using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore.Query; +using System.IO; namespace CliveBot.Web.Controllers { /// /// Creates redirect urls and challanges, and signing out /// - public class AuthenticationController : Controller + public class AuthenticationController(IConfiguration config) : Controller { /// /// Signing in to the application trough Cookie @@ -18,10 +19,19 @@ public class AuthenticationController : Controller [HttpGet("~/signin")] public IActionResult SignIn(string? redirect) { + var frontEndUrl = config.GetValue("FrontendUrl"); + var redirectUri = "/"; - if(IsLocalUrl(redirect)) + if (frontEndUrl != null) + { + redirectUri = frontEndUrl; + } + + if (IsLocalUrl(redirect) && frontEndUrl != null) { - redirectUri = redirect; + Uri newUri = new(new(frontEndUrl), redirect); + + redirectUri = newUri.AbsoluteUri; } return Challenge(new AuthenticationProperties { RedirectUri = redirectUri }, "Discord"); @@ -48,13 +58,31 @@ private static bool IsLocalUrl(string? url) /// [HttpGet("~/signout")] [HttpPost("~/signout")] - public IActionResult SignOutCurrentUser() + public IActionResult SignOutCurrentUser(string redirect) { // Instruct the cookies middleware to delete the local cookie created // when the user agent is redirected from the external identity provider // after a successful authentication flow (e.g Google or Facebook). - return SignOut(new AuthenticationProperties { RedirectUri = "/" }, - CookieAuthenticationDefaults.AuthenticationScheme); + + var frontEndUrl = config.GetValue("FrontendUrl"); + + var redirectUri = "/"; + if (frontEndUrl != null) + { + redirectUri = frontEndUrl; + } + + if (IsLocalUrl(redirect) && frontEndUrl != null) + { + Uri newUri = new(new(frontEndUrl), redirect); + + redirectUri = newUri.AbsoluteUri; + } + + return SignOut( + new AuthenticationProperties { RedirectUri = redirectUri }, + CookieAuthenticationDefaults.AuthenticationScheme + ); } } } diff --git a/Web/Controllers/CharacterController.cs b/Web/Controllers/CharacterController.cs index 9cadbae..9efe9e2 100644 --- a/Web/Controllers/CharacterController.cs +++ b/Web/Controllers/CharacterController.cs @@ -6,6 +6,7 @@ using CliveBot.Web.Policies; using MediatR; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Authorization; namespace CliveBot.Web.Controllers { @@ -20,6 +21,8 @@ public class CharacterController : ApiBaseController /// /// List of Characters [HttpGet] + + [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ActionResult>))] public async Task> GetAllCharacters() { @@ -27,6 +30,8 @@ public async Task> GetAllCharacters() } [HttpGet("{id}")] + + [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ActionResult))] public async Task GetCharacter(int id) { @@ -98,6 +103,8 @@ public async Task> UpdateVariantPreviewImage(i // Notes [HttpGet("{characterId}/notes")] + + [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ActionResult>))] public async Task> CreateNote(int characterId, CharacterNoteList.Query query) { diff --git a/Web/Controllers/SkillController.cs b/Web/Controllers/SkillController.cs index 775a8c3..d91306b 100644 --- a/Web/Controllers/SkillController.cs +++ b/Web/Controllers/SkillController.cs @@ -60,7 +60,7 @@ public async Task> SearchSkill(string skillName) [HttpPost] [ModAuthorize(ManageSkills: true)] [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(SkillDto))] - public async Task> EditSkill(SkillCreate.Command skill) + public async Task> CreateSkill(SkillCreate.Command skill) { return await Mediator.Send(skill); } @@ -83,6 +83,7 @@ public async Task> EditSkill(int id, SkillEdit.Command sk } [HttpGet("{id}/languages")] + [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(List))] [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task> GetSkillLanguages(int id) diff --git a/Web/Program.cs b/Web/Program.cs index fe41988..a49cf32 100644 --- a/Web/Program.cs +++ b/Web/Program.cs @@ -76,7 +76,6 @@ options.AccessDeniedPath = "/error/accessdenied"; options.ClientId = discordClientId; options.ClientSecret = discordClientSecret; - }) .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, (options) => { @@ -89,23 +88,6 @@ { options.Cookie.Domain = cookieDomain; } - options.Events.OnSignedIn = (ctx) => { - if (string.IsNullOrEmpty(frontendUrl)) - { - return Task.CompletedTask; - } - ctx.Response.Redirect(frontendUrl); - return Task.CompletedTask; - }; - - options.Events.OnSigningOut = (ctx) => { - if (string.IsNullOrEmpty(frontendUrl)) - { - return Task.CompletedTask; - } - ctx.Response.Redirect(frontendUrl); - return Task.CompletedTask; - }; }); //.AddBearerToken();