New: Add authentication options to Webhook

Closes #2257
Frank Scholl 7 years ago committed by Mark McDowall
parent 3d8cd9616e
commit 442d49046d
No known key found for this signature in database
GPG Key ID: D4CEFA9A718052E0

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

@ -1,6 +1,7 @@
using NzbDrone.Common.Http;
using NzbDrone.Common.Http;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Rest;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Core.Notifications.Webhook
{
@ -30,6 +31,10 @@ 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)

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

Loading…
Cancel
Save