From 3d99c2593d6ef7d00d1da674abe09845150c1b74 Mon Sep 17 00:00:00 2001 From: Jason Dove <1695733+jasongdove@users.noreply.github.com> Date: Wed, 31 Jan 2024 12:03:04 -0600 Subject: [PATCH] allow previewing jwt channels (#1586) --- CHANGELOG.md | 5 +++++ ErsatzTV/Pages/Channels.razor | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1aca02a59..132e5ed77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fix antiforgery error caused by reusing existing browser tabs across docker container restarts - Data protection keys will now be persisted under ErsatzTV's config folder instead of being recreated at startup +### Changed +- Pass through `access_token` query param from `Channels` page url to streaming endpoints + - This parameter isn't normally needed on the `Channels` page, since the web UI is not protected with JWT + - Its only purpose is to allow playback of authenticated channels in the web UI + ## [0.8.5-beta] - 2024-01-30 ### Added - Respect browser's `Accept-Language` header for date time display diff --git a/ErsatzTV/Pages/Channels.razor b/ErsatzTV/Pages/Channels.razor index 1d4dab39f..4df526c01 100644 --- a/ErsatzTV/Pages/Channels.razor +++ b/ErsatzTV/Pages/Channels.razor @@ -4,6 +4,8 @@ @using ErsatzTV.Application.FFmpegProfiles @using System.Globalization @using ErsatzTV.Core.Interfaces.FFmpeg +@using Microsoft.AspNetCore.WebUtilities +@using Microsoft.Extensions.Primitives @implements IDisposable @inject IDialogService Dialog @inject IMediator Mediator @@ -179,11 +181,17 @@ { return; } - - string currentUri = NavigationManager.Uri; - string streamUri = currentUri.Replace("/channels", $"/iptv/channel/{channel.Number}.m3u8?mode=segmenter"); - var parameters = new DialogParameters { { "StreamUri", streamUri } }; + var uri = new UriBuilder(NavigationManager.ToAbsoluteUri(NavigationManager.Uri)); + uri.Path = uri.Path.Replace("/channels", $"/iptv/channel/{channel.Number}.m3u8"); + string query = uri.Query; + uri.Query = "?mode=segmenter"; + if (QueryHelpers.ParseQuery(query).TryGetValue("access_token", out StringValues token)) + { + uri.Query += $"&access_token={token.ToString()}"; + } + + var parameters = new DialogParameters { { "StreamUri", uri.ToString() } }; var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraLarge }; await Dialog.ShowAsync("Channel Preview", parameters, options); }