Bunch of OIDC fixes and one extra (#4126)

This commit is contained in:
Fesaa
2025-10-21 22:07:04 +02:00
committed by GitHub
parent 947ab758ca
commit bda2a4d50d
20 changed files with 140 additions and 93 deletions
+11 -8
View File
@@ -1,12 +1,10 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Threading.Tasks;
using API.Extensions;
using API.Services;
using Kavita.Common;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers;
@@ -19,6 +17,11 @@ public class OidcController: ControllerBase
[HttpGet("login")]
public IActionResult Login(string returnUrl = "/")
{
if (returnUrl == "/")
{
returnUrl = Configuration.BaseUrl;
}
var properties = new AuthenticationProperties { RedirectUri = returnUrl };
return Challenge(properties, IdentityServiceExtensions.OpenIdConnect);
}
@@ -29,18 +32,18 @@ public class OidcController: ControllerBase
if (!Request.Cookies.ContainsKey(OidcService.CookieName))
{
return Redirect("/");
return Redirect(Configuration.BaseUrl);
}
var res = await Request.HttpContext.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme);
if (!res.Succeeded || res.Properties == null || string.IsNullOrEmpty(res.Properties.GetString(OidcService.IdToken)))
if (!res.Succeeded || res.Properties == null || string.IsNullOrEmpty(res.Properties.GetTokenValue(OidcService.IdToken)))
{
HttpContext.Response.Cookies.Delete(OidcService.CookieName);
return Redirect("/");
return Redirect(Configuration.BaseUrl);
}
return SignOut(
new AuthenticationProperties { RedirectUri = "/login" },
new AuthenticationProperties { RedirectUri = Configuration.BaseUrl+"login" },
CookieAuthenticationDefaults.AuthenticationScheme,
IdentityServiceExtensions.OpenIdConnect);
}