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
20555cc360
commit
ea60b28693
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)
|
public static AuthenticationBuilder AddAppAuthentication(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddOptions<CookieAuthenticationOptions>(AuthenticationType.Forms.ToString())
|
services.AddOptions<CookieAuthenticationOptions>(nameof(AuthenticationType.Forms))
|
||||||
.Configure<IConfigFileProvider>((options, configFileProvider) =>
|
.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
|
// 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()
|
return services.AddAuthentication()
|
||||||
.AddNone(AuthenticationType.None.ToString())
|
.AddNone(nameof(AuthenticationType.None))
|
||||||
.AddExternal(AuthenticationType.External.ToString())
|
.AddExternal(nameof(AuthenticationType.External))
|
||||||
#pragma warning disable CS0618 // Type or member is obsolete
|
.AddCookie(nameof(AuthenticationType.Forms))
|
||||||
.AddCookie(AuthenticationType.Basic.ToString())
|
|
||||||
#pragma warning restore CS0618 // Type or member is obsolete
|
|
||||||
.AddCookie(AuthenticationType.Forms.ToString())
|
|
||||||
.AddApiKey("API", options =>
|
.AddApiKey("API", options =>
|
||||||
{
|
{
|
||||||
options.HeaderName = "X-Api-Key";
|
options.HeaderName = "X-Api-Key";
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ namespace NzbDrone.Http.Authentication
|
||||||
{
|
{
|
||||||
public class UiAuthorizationPolicyProvider : IAuthorizationPolicyProvider
|
public class UiAuthorizationPolicyProvider : IAuthorizationPolicyProvider
|
||||||
{
|
{
|
||||||
private const string POLICY_NAME = "UI";
|
private const string PolicyName = "UI";
|
||||||
private readonly IConfigFileProvider _config;
|
private readonly IConfigFileProvider _config;
|
||||||
|
|
||||||
public DefaultAuthorizationPolicyProvider FallbackPolicyProvider { get; }
|
public DefaultAuthorizationPolicyProvider FallbackPolicyProvider { get; }
|
||||||
|
|
@ -26,7 +26,7 @@ public UiAuthorizationPolicyProvider(IOptions<AuthorizationOptions> options,
|
||||||
|
|
||||||
public Task<AuthorizationPolicy> GetPolicyAsync(string policyName)
|
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())
|
var policy = new AuthorizationPolicyBuilder(_config.AuthenticationMethod.ToString())
|
||||||
.AddRequirements(new BypassableDenyAnonymousAuthorizationRequirement());
|
.AddRequirements(new BypassableDenyAnonymousAuthorizationRequirement());
|
||||||
|
|
|
||||||
|
|
@ -208,9 +208,20 @@ public AuthenticationType AuthenticationMethod
|
||||||
return AuthenticationType.Forms;
|
return AuthenticationType.Forms;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Enum.TryParse<AuthenticationType>(_authOptions.Method, out var enumValue)
|
var value = Enum.TryParse<AuthenticationType>(_authOptions.Method, out var enumValue)
|
||||||
? enumValue
|
? enumValue
|
||||||
: GetValueEnum("AuthenticationMethod", AuthenticationType.None);
|
: 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);
|
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()
|
private void DeleteOldValues()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue