mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 10:47:08 -07:00
fixed authentication. at least locally. need to test remote.
This commit is contained in:
parent
d33e2dff58
commit
e538593c61
4 changed files with 55 additions and 6 deletions
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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue