New: Add authentication options to Webhook

This commit is contained in:
Qstick 2017-11-25 22:24:46 -05:00
parent 17eac6dac7
commit dd11f74073
3 changed files with 21 additions and 2 deletions

View File

@ -76,5 +76,12 @@ namespace NzbDrone.Common.Http
var encoding = HttpHeader.GetEncodingFromContentType(Headers.ContentType);
ContentData = encoding.GetBytes(data);
}
public void AddBasicAuthentication(string username, string password)
{
var authInfo = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes($"{username}:{password}"));
Headers.Set("Authorization", "Basic " + authInfo);
}
}
}
}

View File

@ -1,6 +1,7 @@
using NzbDrone.Common.Http;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Rest;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Core.Notifications.Webhook
{
@ -30,6 +31,11 @@ namespace NzbDrone.Core.Notifications.Webhook
request.Headers.ContentType = "application/json";
request.SetContent(body.ToJson());
if (settings.Username.IsNotNullOrWhiteSpace() || settings.Password.IsNotNullOrWhiteSpace())
{
request.AddBasicAuthentication(settings.Username, settings.Password);
}
_httpClient.Execute(request);
}
catch (RestException ex)

View File

@ -1,4 +1,4 @@
using System;
using System;
using FluentValidation;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
@ -29,6 +29,12 @@ namespace NzbDrone.Core.Notifications.Webhook
[FieldDefinition(1, Label = "Method", Type = FieldType.Select, SelectOptions = typeof(WebhookMethod), HelpText = "Which HTTP method to use submit to the Webservice")]
public int Method { get; set; }
[FieldDefinition(2, Label = "Username")]
public string Username { get; set; }
[FieldDefinition(3, Label = "Password", Type = FieldType.Password)]
public string Password { get; set; }
public NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));