From f08578bfdb2117d0ad7e05c82f3a744bf1fe862f Mon Sep 17 00:00:00 2001 From: D4VID Date: Fri, 1 Mar 2024 14:14:12 +0100 Subject: [PATCH] Login redirect --- OAuthServer/Controllers/LoginController.cs | 27 ++++++++++++++++++++-- OAuthServer/Program.cs | 3 +++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/OAuthServer/Controllers/LoginController.cs b/OAuthServer/Controllers/LoginController.cs index 22e53e8..3189cce 100644 --- a/OAuthServer/Controllers/LoginController.cs +++ b/OAuthServer/Controllers/LoginController.cs @@ -44,19 +44,42 @@ public class LoginController : ControllerBase return Ok("Registered"); } + [HttpGet] + [Route("login")] + public ContentResult Login() + { + return Content(""" + + + + Login + + + +
+ + + +
+ + + """, + "text/html" + ); + } public record LoginRequest(string Username, [StringLength(1024)] string Password); [HttpPost] [Route("login")] - public async Task Login([FromBody] LoginRequest loginRequest) + public async Task Login([FromForm] LoginRequest loginRequest, string? returnUrl) { SignInResult result = await _signInManager.PasswordSignInAsync(loginRequest.Username, loginRequest.Password, isPersistent: true, lockoutOnFailure: false); if (result.Succeeded) { - return Ok(); + return Redirect(returnUrl ?? ""); } if (result.IsLockedOut) diff --git a/OAuthServer/Program.cs b/OAuthServer/Program.cs index b954b5c..98a9046 100644 --- a/OAuthServer/Program.cs +++ b/OAuthServer/Program.cs @@ -52,6 +52,9 @@ builder.Services.ConfigureApplicationCookie(options => options.ExpireTimeSpan = TimeSpan.FromHours(24); options.SlidingExpiration = true; + + options.LoginPath = "/login"; + options.LogoutPath = "/logout"; }); // Force Identity's security stamp to be validated every minute.