mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
fixed authentication. at least locally. need to test remote.
This commit is contained in:
parent
d33e2dff58
commit
e538593c61
@ -5,20 +5,32 @@
|
|||||||
|
|
||||||
namespace NzbDrone.Api.Authentication
|
namespace NzbDrone.Api.Authentication
|
||||||
{
|
{
|
||||||
public class AuthenticationValidator : IUserValidator
|
public interface IAuthenticationService : IUserValidator
|
||||||
|
{
|
||||||
|
AuthenticationType AuthenticationType { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AuthenticationService : IAuthenticationService
|
||||||
{
|
{
|
||||||
private readonly IConfigFileProvider _configFileProvider;
|
private readonly IConfigFileProvider _configFileProvider;
|
||||||
|
private static readonly NzbDroneUser AnonymousUser = new NzbDroneUser { UserName = "Anonymous" };
|
||||||
|
|
||||||
public AuthenticationValidator(IConfigFileProvider configFileProvider)
|
|
||||||
|
public AuthenticationService(IConfigFileProvider configFileProvider)
|
||||||
{
|
{
|
||||||
_configFileProvider = configFileProvider;
|
_configFileProvider = configFileProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AuthenticationType AuthenticationType
|
||||||
|
{
|
||||||
|
get { return _configFileProvider.AuthenticationType; }
|
||||||
|
}
|
||||||
|
|
||||||
public IUserIdentity Validate(string username, string password)
|
public IUserIdentity Validate(string username, string password)
|
||||||
{
|
{
|
||||||
if (_configFileProvider.AuthenticationType == AuthenticationType.Anonymous)
|
if (AuthenticationType == AuthenticationType.Anonymous)
|
||||||
{
|
{
|
||||||
return new NzbDroneUser { UserName = "Anonymous" };
|
return AnonymousUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_configFileProvider.BasicAuthUsername.Equals(username) &&
|
if (_configFileProvider.BasicAuthUsername.Equals(username) &&
|
39
NzbDrone.Api/Authentication/EnableBasicAuthInNancy.cs
Normal file
39
NzbDrone.Api/Authentication/EnableBasicAuthInNancy.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
using Nancy;
|
||||||
|
using Nancy.Authentication.Basic;
|
||||||
|
using Nancy.Bootstrapper;
|
||||||
|
using NzbDrone.Common.Model;
|
||||||
|
|
||||||
|
namespace NzbDrone.Api.Authentication
|
||||||
|
{
|
||||||
|
public interface IEnableBasicAuthInNancy
|
||||||
|
{
|
||||||
|
void Register(IPipelines pipelines);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EnableBasicAuthInNancy : IEnableBasicAuthInNancy
|
||||||
|
{
|
||||||
|
private readonly IAuthenticationService _authenticationService;
|
||||||
|
|
||||||
|
public EnableBasicAuthInNancy(IAuthenticationService authenticationService)
|
||||||
|
{
|
||||||
|
_authenticationService = authenticationService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Register(IPipelines pipelines)
|
||||||
|
{
|
||||||
|
pipelines.EnableBasicAuthentication(new BasicAuthenticationConfiguration(_authenticationService, "NzbDrone"));
|
||||||
|
pipelines.BeforeRequest.AddItemToEndOfPipeline(RequiresAuthentication);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Response RequiresAuthentication(NancyContext context)
|
||||||
|
{
|
||||||
|
Response response = null;
|
||||||
|
if (context.CurrentUser == null && _authenticationService.AuthenticationType != AuthenticationType.Anonymous)
|
||||||
|
{
|
||||||
|
response = new Response { StatusCode = HttpStatusCode.Unauthorized };
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,7 +8,6 @@ public class IndexModule : NancyModule
|
|||||||
{
|
{
|
||||||
public IndexModule()
|
public IndexModule()
|
||||||
{
|
{
|
||||||
this.RequiresAuthentication();
|
|
||||||
//Serve anything that doesn't have an extension
|
//Serve anything that doesn't have an extension
|
||||||
Get[@"/(.*)"] = x => Index();
|
Get[@"/(.*)"] = x => Index();
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ namespace NzbDrone.Api
|
|||||||
protected NzbDroneRestModule()
|
protected NzbDroneRestModule()
|
||||||
: this(new TResource().ResourceName)
|
: this(new TResource().ResourceName)
|
||||||
{
|
{
|
||||||
this.RequiresAuthentication();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected NzbDroneRestModule(string resource)
|
protected NzbDroneRestModule(string resource)
|
||||||
|
Loading…
Reference in New Issue
Block a user