aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua M. Boniface <joshua@boniface.me>2019-10-02 12:36:25 -0400
committerGitHub <noreply@github.com>2019-10-02 12:36:25 -0400
commit6b00cc1a06b99dab95784201ed42798dc45ad94f (patch)
tree3cad9ac44e74a71b9703457cbfcbf16cdb8fbb3b
parentb0ec5c527dc9c935441fbccca0631c4a3b5ea951 (diff)
parent80dccdef22dfebd1f411b779f30b5fea89e10486 (diff)
Merge pull request #1829 from thornbill/fix-sd-auth
Fix SchedulesDirect authentication
-rw-r--r--MediaBrowser.Api/LiveTv/LiveTvService.cs23
1 files changed, 23 insertions, 0 deletions
diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.cs
index 3a15c3776..b05e8c949 100644
--- a/MediaBrowser.Api/LiveTv/LiveTvService.cs
+++ b/MediaBrowser.Api/LiveTv/LiveTvService.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
+using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -24,6 +25,7 @@ using MediaBrowser.Model.LiveTv;
using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Services;
using Microsoft.Net.Http.Headers;
+using static MediaBrowser.Common.HexHelper;
namespace MediaBrowser.Api.LiveTv
{
@@ -599,6 +601,7 @@ namespace MediaBrowser.Api.LiveTv
{
public bool ValidateLogin { get; set; }
public bool ValidateListings { get; set; }
+ public string Pw { get; set; }
}
[Route("/LiveTv/ListingProviders", "DELETE", Summary = "Deletes a listing provider")]
@@ -866,10 +869,30 @@ namespace MediaBrowser.Api.LiveTv
public async Task<object> Post(AddListingProvider request)
{
+ if (request.Pw != null)
+ {
+ request.Password = GetHashedString(request.Pw);
+ }
+
+ request.Pw = null;
+
var result = await _liveTvManager.SaveListingProvider(request, request.ValidateLogin, request.ValidateListings).ConfigureAwait(false);
return ToOptimizedResult(result);
}
+ /// <summary>
+ /// Gets the hashed string.
+ /// </summary>
+ private string GetHashedString(string str)
+ {
+ // SchedulesDirect requires a SHA1 hash of the user's password
+ // https://github.com/SchedulesDirect/JSON-Service/wiki/API-20141201#obtain-a-token
+ using (SHA1 sha = SHA1.Create()) {
+ return ToHexString(
+ sha.ComputeHash(Encoding.UTF8.GetBytes(str)));
+ }
+ }
+
public void Delete(DeleteListingProvider request)
{
_liveTvManager.DeleteListingsProvider(request.Id);