From 119041a425b270a7747a0e663d1212d64581542b Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Wed, 2 Oct 2019 01:35:28 -0400 Subject: [PATCH 1/2] Fix SchedulesDirect authentication --- MediaBrowser.Api/LiveTv/LiveTvService.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.cs index 3a15c3776f..07f9223933 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; @@ -599,6 +600,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 +868,30 @@ namespace MediaBrowser.Api.LiveTv public async Task 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); } + /// + /// Gets the hashed string. + /// + 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 + SHA1 sha = SHA1.Create(); + return BitConverter.ToString( + sha.ComputeHash(Encoding.UTF8.GetBytes(str))) + .Replace("-", string.Empty).ToLowerInvariant(); + } + public void Delete(DeleteListingProvider request) { _liveTvManager.DeleteListingsProvider(request.Id); From 80dccdef22dfebd1f411b779f30b5fea89e10486 Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Wed, 2 Oct 2019 09:51:53 -0400 Subject: [PATCH 2/2] Add using block and HexHelper --- MediaBrowser.Api/LiveTv/LiveTvService.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.cs index 07f9223933..b05e8c9495 100644 --- a/MediaBrowser.Api/LiveTv/LiveTvService.cs +++ b/MediaBrowser.Api/LiveTv/LiveTvService.cs @@ -25,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 { @@ -886,10 +887,10 @@ namespace MediaBrowser.Api.LiveTv { // SchedulesDirect requires a SHA1 hash of the user's password // https://github.com/SchedulesDirect/JSON-Service/wiki/API-20141201#obtain-a-token - SHA1 sha = SHA1.Create(); - return BitConverter.ToString( - sha.ComputeHash(Encoding.UTF8.GetBytes(str))) - .Replace("-", string.Empty).ToLowerInvariant(); + using (SHA1 sha = SHA1.Create()) { + return ToHexString( + sha.ComputeHash(Encoding.UTF8.GetBytes(str))); + } } public void Delete(DeleteListingProvider request)