mirror of
https://github.com/Lidarr/Lidarr
synced 2025-12-06 16:33:52 +01:00
Change authentication to Forms if set to Basic
(cherry picked from commit dfb6fdfbeb7ce85b287b41fed80f2511727353e5)
This commit is contained in:
parent
e83c9fb0d9
commit
bbf0d15758
3 changed files with 24 additions and 10 deletions
|
|
@ -30,7 +30,7 @@ public static AuthenticationBuilder AddExternal(this AuthenticationBuilder authe
|
|||
|
||||
public static AuthenticationBuilder AddAppAuthentication(this IServiceCollection services)
|
||||
{
|
||||
services.AddOptions<CookieAuthenticationOptions>(AuthenticationType.Forms.ToString())
|
||||
services.AddOptions<CookieAuthenticationOptions>(nameof(AuthenticationType.Forms))
|
||||
.Configure<IConfigFileProvider>((options, configFileProvider) =>
|
||||
{
|
||||
// Replace diacritics and replace non-word characters to ensure cookie name doesn't contain any valid URL characters not allowed in cookie names
|
||||
|
|
@ -47,12 +47,9 @@ public static AuthenticationBuilder AddAppAuthentication(this IServiceCollection
|
|||
});
|
||||
|
||||
return services.AddAuthentication()
|
||||
.AddNone(AuthenticationType.None.ToString())
|
||||
.AddExternal(AuthenticationType.External.ToString())
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
.AddCookie(AuthenticationType.Basic.ToString())
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
.AddCookie(AuthenticationType.Forms.ToString())
|
||||
.AddNone(nameof(AuthenticationType.None))
|
||||
.AddExternal(nameof(AuthenticationType.External))
|
||||
.AddCookie(nameof(AuthenticationType.Forms))
|
||||
.AddApiKey("API", options =>
|
||||
{
|
||||
options.HeaderName = "X-Api-Key";
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace NzbDrone.Http.Authentication
|
|||
{
|
||||
public class UiAuthorizationPolicyProvider : IAuthorizationPolicyProvider
|
||||
{
|
||||
private const string POLICY_NAME = "UI";
|
||||
private const string PolicyName = "UI";
|
||||
private readonly IConfigFileProvider _config;
|
||||
|
||||
public DefaultAuthorizationPolicyProvider FallbackPolicyProvider { get; }
|
||||
|
|
@ -26,7 +26,7 @@ public UiAuthorizationPolicyProvider(IOptions<AuthorizationOptions> options,
|
|||
|
||||
public Task<AuthorizationPolicy> GetPolicyAsync(string policyName)
|
||||
{
|
||||
if (policyName.Equals(POLICY_NAME, StringComparison.OrdinalIgnoreCase))
|
||||
if (policyName.Equals(PolicyName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var policy = new AuthorizationPolicyBuilder(_config.AuthenticationMethod.ToString())
|
||||
.AddRequirements(new BypassableDenyAnonymousAuthorizationRequirement());
|
||||
|
|
|
|||
|
|
@ -208,9 +208,20 @@ public AuthenticationType AuthenticationMethod
|
|||
return AuthenticationType.Forms;
|
||||
}
|
||||
|
||||
return Enum.TryParse<AuthenticationType>(_authOptions.Method, out var enumValue)
|
||||
var value = Enum.TryParse<AuthenticationType>(_authOptions.Method, out var enumValue)
|
||||
? enumValue
|
||||
: GetValueEnum("AuthenticationMethod", AuthenticationType.None);
|
||||
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
if (value == AuthenticationType.Basic)
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
{
|
||||
SetValue("AuthenticationMethod", AuthenticationType.Forms);
|
||||
|
||||
return AuthenticationType.Forms;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -385,6 +396,12 @@ public void MigrateConfigFile()
|
|||
{
|
||||
SetValue("EnableSsl", false);
|
||||
}
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
if (AuthenticationMethod == AuthenticationType.Basic)
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
{
|
||||
SetValue("AuthenticationMethod", AuthenticationType.Forms);
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteOldValues()
|
||||
|
|
|
|||
Loading…
Reference in a new issue