diff --git a/SSO-Auth/Api/SSOController.cs b/SSO-Auth/Api/SSOController.cs index c0b47f6..74dff10 100644 --- a/SSO-Auth/Api/SSOController.cs +++ b/SSO-Auth/Api/SSOController.cs @@ -106,7 +106,7 @@ public class SSOController : ControllerBase 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 = GetRequestBase(config.SchemeOverride, config.PortOverride) + $"/sso/OID/{(Request.Path.Value.Contains("/start/", StringComparison.InvariantCultureIgnoreCase) ? "redirect" : "r")}/" + provider, Scope = string.Join(" ", scopes.Prepend("openid profile")), DisablePushedAuthorization = config.DisablePushedAuthorization, }; @@ -276,7 +276,7 @@ public class SSOController : ControllerBase if (StateManager[state].Valid) { _logger.LogInformation($"Is request linking: {isLinking}"); - return Content(WebResponse.Generator(data: state, provider: provider, baseUrl: GetRequestBase(config.SchemeOverride), mode: "OID", isLinking: isLinking), MediaTypeNames.Text.Html); + return Content(WebResponse.Generator(data: state, provider: provider, baseUrl: GetRequestBase(config.SchemeOverride, config.PortOverride), mode: "OID", isLinking: isLinking), MediaTypeNames.Text.Html); } else { @@ -324,7 +324,7 @@ public class SSOController : ControllerBase config.NewPath = newPath; } - string redirectUri = GetRequestBase(config.SchemeOverride) + $"/sso/OID/{(newPath ? "redirect" : "r")}/" + provider; + string redirectUri = GetRequestBase(config.SchemeOverride, config.PortOverride) + $"/sso/OID/{(newPath ? "redirect" : "r")}/" + provider; var options = new OidcClientOptions { @@ -524,7 +524,7 @@ public class SSOController : ControllerBase WebResponse.Generator( data: Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(samlResponse.Xml)), provider: provider, - baseUrl: GetRequestBase(config.SchemeOverride), + baseUrl: GetRequestBase(config.SchemeOverride, config.PortOverride), mode: "SAML", isLinking: isLinking), MediaTypeNames.Text.Html); @@ -570,7 +570,7 @@ public class SSOController : ControllerBase config.NewPath = newPath; } - string redirectUri = GetRequestBase(config.SchemeOverride) + $"/sso/SAML/{(newPath ? "post" : "p")}/" + provider; + string redirectUri = GetRequestBase(config.SchemeOverride, config.PortOverride) + $"/sso/SAML/{(newPath ? "post" : "p")}/" + provider; string relayState = null; if (isLinking) { @@ -1148,9 +1148,19 @@ public class SSOController : ControllerBase } } - private string GetRequestBase(string schemeOverride = null) + private string GetRequestBase(string schemeOverride = null, int? portOverride = null) + { + int requestPort; + + if (portOverride != null) { - int requestPort = Request.Host.Port ?? -1; + requestPort = portOverride.Value; + } + else + { + requestPort = Request.Host.Port ?? -1; + } + if ((requestPort == 80 && string.Equals(Request.Scheme, "http", StringComparison.OrdinalIgnoreCase)) || (requestPort == 443 && string.Equals(Request.Scheme, "https", StringComparison.OrdinalIgnoreCase))) { requestPort = -1; diff --git a/SSO-Auth/Config/PluginConfiguration.cs b/SSO-Auth/Config/PluginConfiguration.cs index fec1feb..b420492 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 the redirect port override. + /// + public int? PortOverride { get; set; } + /// /// Gets or sets a value indicating whether the new, more descriptive paths are to be used. /// @@ -265,6 +270,11 @@ public class OidConfig /// public string SchemeOverride { get; set; } + /// + /// Gets or sets the redirect port override. + /// + public int? PortOverride { get; set; } + /// /// Gets or sets a value indicating whether the new, more descriptive paths are to be used. /// diff --git a/SSO-Auth/Config/configPage.html b/SSO-Auth/Config/configPage.html index 55d2329..a192cf6 100644 --- a/SSO-Auth/Config/configPage.html +++ b/SSO-Auth/Config/configPage.html @@ -651,6 +651,18 @@ +
+ + +
+ If the plugin is redirecting to an incorrect port, set this to + the appropiate port +
+
+