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;
|
||||||
using NzbDrone.Api.Extensions.Pipelines;
|
using NzbDrone.Api.Extensions.Pipelines;
|
||||||
using NzbDrone.Common;
|
using NzbDrone.Common;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
|
||||||
using NzbDrone.Core.Configuration;
|
using NzbDrone.Core.Configuration;
|
||||||
|
|
||||||
namespace NzbDrone.Api.Authentication
|
namespace NzbDrone.Api.Authentication
|
||||||
|
@ -28,9 +27,7 @@ namespace NzbDrone.Api.Authentication
|
||||||
{
|
{
|
||||||
Response response = null;
|
Response response = null;
|
||||||
|
|
||||||
var authorizationHeader = context.Request.Headers.Authorization;
|
var apiKey = GetApiKey(context);
|
||||||
var apiKeyHeader = context.Request.Headers["X-Api-Key"].FirstOrDefault();
|
|
||||||
var apiKey = apiKeyHeader.IsNullOrWhiteSpace() ? authorizationHeader : apiKeyHeader;
|
|
||||||
|
|
||||||
if (context.Request.IsApiRequest() && !ValidApiKey(apiKey))
|
if (context.Request.IsApiRequest() && !ValidApiKey(apiKey))
|
||||||
{
|
{
|
||||||
|
@ -46,5 +43,23 @@ namespace NzbDrone.Api.Authentication
|
||||||
|
|
||||||
return true;
|
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