From 9321c25f2028101cee19f4bf90083aecb60bdba5 Mon Sep 17 00:00:00 2001 From: Ersei Saggi Date: Thu, 11 Jan 2024 09:56:45 -0500 Subject: [PATCH] feat: allow linking to work with new paths --- SSO-Auth/Api/SSOController.cs | 21 +++++++++++++++++++-- SSO-Auth/Config/PluginConfiguration.cs | 10 ++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/SSO-Auth/Api/SSOController.cs b/SSO-Auth/Api/SSOController.cs index 34fe22c..861ae74 100644 --- a/SSO-Auth/Api/SSOController.cs +++ b/SSO-Auth/Api/SSOController.cs @@ -288,12 +288,21 @@ public class SSOController : ControllerBase if (config.Enabled) { + bool newPath = config.NewPath; + if (!isLinking) + { + newPath = Request.Path.Value.Contains("/start/", StringComparison.InvariantCultureIgnoreCase); + config.NewPath = newPath; + } + + string redirectUri = GetRequestBase(config.SchemeOverride) + $"/sso/OID/{(newPath ? "redirect" : "r")}/" + provider; + var options = new OidcClientOptions { Authority = config.OidEndpoint?.Trim(), ClientId = config.OidClientId?.Trim(), ClientSecret = config.OidSecret?.Trim(), - RedirectUri = GetRequestBase(config.SchemeOverride) + $"/sso/OID/{(Request.Path.Value.Contains("/start/", StringComparison.InvariantCultureIgnoreCase) ? "redirect" : "r")}/" + provider, + RedirectUri = redirectUri, Scope = string.Join(" ", config.OidScopes.Prepend("openid profile")), }; options.Policy.Discovery.ValidateEndpoints = false; // For Google and other providers with different endpoints @@ -514,6 +523,14 @@ public class SSOController : ControllerBase if (config.Enabled) { + bool newPath = config.NewPath; + if (!isLinking) + { + newPath = Request.Path.Value.Contains("/start/", StringComparison.InvariantCultureIgnoreCase); + config.NewPath = newPath; + } + + string redirectUri = GetRequestBase(config.SchemeOverride) + $"/sso/SAML/{(newPath ? "post" : "p")}/" + provider; string relayState = null; if (isLinking) { @@ -522,7 +539,7 @@ public class SSOController : ControllerBase var request = new AuthRequest( config.SamlClientId.Trim(), - GetRequestBase(config.SchemeOverride) + $"/sso/SAML/{(Request.Path.Value.Contains("/start/", StringComparison.InvariantCultureIgnoreCase) ? "post" : "p")}/" + provider); + redirectUri); return Redirect(request.GetRedirectUrl(config.SamlEndpoint.Trim(), relayState)); } diff --git a/SSO-Auth/Config/PluginConfiguration.cs b/SSO-Auth/Config/PluginConfiguration.cs index 1a8650a..767ed2e 100644 --- a/SSO-Auth/Config/PluginConfiguration.cs +++ b/SSO-Auth/Config/PluginConfiguration.cs @@ -131,6 +131,11 @@ public class SamlConfig /// public string SchemeOverride { get; set; } + /// + /// Gets or sets a value indicating whether the new, more descriptive paths are to be used. + /// + public bool NewPath { get; set; } + /// /// Gets or sets a mapping of canonical names from the provider to jellyfin user ids. /// @@ -260,6 +265,11 @@ public class OidConfig /// public string SchemeOverride { get; set; } + /// + /// Gets or sets a value indicating whether the new, more descriptive paths are to be used. + /// + public bool NewPath { get; set; } + /// /// Gets or sets a mapping of canonical names from the provider to jellyfin user ids. ///