mirror of https://github.com/lidarr/Lidarr
New: Support API Key via query string
This commit is contained in:
parent
8414890017
commit
f104be6dd1
|
@ -5,7 +5,6 @@ using Nancy.Bootstrapper;
|
|||
using NzbDrone.Api.Extensions;
|
||||
using NzbDrone.Api.Extensions.Pipelines;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Core.Configuration;
|
||||
|
||||
namespace NzbDrone.Api.Authentication
|
||||
|
@ -28,9 +27,7 @@ namespace NzbDrone.Api.Authentication
|
|||
{
|
||||
Response response = null;
|
||||
|
||||
var authorizationHeader = context.Request.Headers.Authorization;
|
||||
var apiKeyHeader = context.Request.Headers["X-Api-Key"].FirstOrDefault();
|
||||
var apiKey = apiKeyHeader.IsNullOrWhiteSpace() ? authorizationHeader : apiKeyHeader;
|
||||
var apiKey = GetApiKey(context);
|
||||
|
||||
if (context.Request.IsApiRequest() && !ValidApiKey(apiKey))
|
||||
{
|
||||
|
@ -46,5 +43,23 @@ namespace NzbDrone.Api.Authentication
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
private string GetApiKey(NancyContext context)
|
||||
{
|
||||
var apiKeyHeader = context.Request.Headers["X-Api-Key"].FirstOrDefault();
|
||||
var apiKeyQueryString = context.Request.Query["ApiKey"];
|
||||
|
||||
if (!apiKeyHeader.IsNullOrWhiteSpace())
|
||||
{
|
||||
return apiKeyHeader;
|
||||
}
|
||||
|
||||
if (apiKeyQueryString.HasValue)
|
||||
{
|
||||
return apiKeyQueryString.Value;
|
||||
}
|
||||
|
||||
return context.Request.Headers.Authorization;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue