Merge pull request #244 from bdovaz/replace-oidc-dependency

Allow to disable pushed authorization
This commit is contained in:
9p4
2025-03-26 11:11:31 -04:00
committed by GitHub
4 changed files with 33 additions and 5 deletions
+12 -3
View File
@@ -5,7 +5,7 @@ using System.Net.Mime;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using IdentityModel.OidcClient;
using Duende.IdentityModel.OidcClient;
using Jellyfin.Data.Entities;
using Jellyfin.Data.Enums;
using Jellyfin.Plugin.SSO_Auth.Config;
@@ -92,6 +92,7 @@ public class SSOController : ControllerBase
ClientSecret = config.OidSecret?.Trim(),
RedirectUri = GetRequestBase(config.SchemeOverride) + $"/sso/OID/{(Request.Path.Value.Contains("/start/", StringComparison.InvariantCultureIgnoreCase) ? "redirect" : "r")}/" + provider,
Scope = string.Join(" ", scopes.Prepend("openid profile")),
DisablePushedAuthorization = config.DisablePushedAuthorization,
};
var oidEndpointUri = new Uri(config.OidEndpoint?.Trim());
options.Policy.Discovery.AdditionalEndpointBaseAddresses.Add(oidEndpointUri.GetLeftPart(UriPartial.Authority));
@@ -101,9 +102,10 @@ public class SSOController : ControllerBase
var oidcClient = new OidcClient(options);
var currentState = StateManager[state].State;
var result = await oidcClient.ProcessResponseAsync(Request.QueryString.Value, currentState).ConfigureAwait(false);
if (result.IsError)
{
return ReturnError(StatusCodes.Status400BadRequest, result.Error + " Try logging in again.");
return ReturnError(StatusCodes.Status400BadRequest, $"Error logging in: {result.Error} - {result.ErrorDescription}");
}
if (!config.EnableFolderRoles && config.EnabledFolders != null)
@@ -308,6 +310,7 @@ public class SSOController : ControllerBase
ClientSecret = config.OidSecret?.Trim(),
RedirectUri = redirectUri,
Scope = string.Join(" ", config.OidScopes.Prepend("openid profile")),
DisablePushedAuthorization = config.DisablePushedAuthorization,
};
var oidEndpointUri = new Uri(config.OidEndpoint?.Trim());
options.Policy.Discovery.AdditionalEndpointBaseAddresses.Add(oidEndpointUri.GetLeftPart(UriPartial.Authority));
@@ -316,6 +319,12 @@ public class SSOController : ControllerBase
options.Policy.Discovery.ValidateIssuerName = !config.DoNotValidateIssuerName;
var oidcClient = new OidcClient(options);
var state = await oidcClient.PrepareLoginAsync().ConfigureAwait(false);
if (state.IsError)
{
return ReturnError(StatusCodes.Status400BadRequest, $"Error preparing login: {state.Error} - {state.ErrorDescription}");
}
StateManager.Add(state.State, new TimedAuthorizeState(state, DateTime.Now));
// Track whether this is a linking request or not.
@@ -1072,7 +1081,7 @@ public class SSOController : ControllerBase
}
private string GetRequestBase(string schemeOverride = null)
{
{
int requestPort = Request.Host.Port ?? -1;
if ((requestPort == 80 && string.Equals(Request.Scheme, "http", StringComparison.OrdinalIgnoreCase)) || (requestPort == 443 && string.Equals(Request.Scheme, "https", StringComparison.OrdinalIgnoreCase)))
{
+6 -1
View File
@@ -296,7 +296,12 @@ public class OidConfig
/// <summary>
/// Gets or sets a value indicating whether HTTPS in the discovery endpoint is required.
/// </summary>
public bool DisableHttps { get; set; }
public bool DisableHttps { get; set; }
/// <summary>
/// Gets or sets a value indicating whether pushed authorization is required.
/// </summary>
public bool DisablePushedAuthorization { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the OpenID endpoints are validated.
+14
View File
@@ -573,6 +573,20 @@
<div class="fieldDescription checkboxFieldDescription"></div>
</div>
<div class="checkboxContainer">
<label>
<input
is="emby-checkbox"
id="DisablePushedAuthorization"
name="DisablePushedAuthorization"
type="checkbox"
class="sso-toggle"
/>
<span>Disable Pushed Authorization (Insecure)</span>
</label>
<div class="fieldDescription checkboxFieldDescription"></div>
</div>
<div
class="checkboxContainer checkboxContainer-withDescription"
>
+1 -1
View File
@@ -29,7 +29,7 @@
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="IdentityModel.OidcClient" Version="5.2.1" />
<PackageReference Include="Duende.IdentityModel.OidcClient" Version="6.0.1" />
<PackageReference Include="Jellyfin.Controller" Version="10.*-*" />
<PackageReference Include="Jellyfin.Model" Version="10.*-*" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />