New: Support API Key via query string

This commit is contained in:
Mark McDowall 2014-04-21 18:04:23 -07:00
parent 8414890017
commit f104be6dd1
1 changed files with 19 additions and 4 deletions

View File

@ -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;
}
}
}