Browse Source

auto generate jwt token for channel preview (#1588)

pull/1589/head
Jason Dove 3 years ago committed by GitHub
parent
commit
d9bbe4df1b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      CHANGELOG.md
  2. 13
      ErsatzTV/JwtHelper.cs
  3. 5
      ErsatzTV/Pages/Channels.razor

6
CHANGELOG.md

@ -12,11 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Data protection keys will now be persisted under ErsatzTV's config folder instead of being recreated at startup - Data protection keys will now be persisted under ErsatzTV's config folder instead of being recreated at startup
- Fix bug updating/replacing Jellyfin movies - Fix bug updating/replacing Jellyfin movies
- A deep scan can be used to fix all movies, otherwise any future updates made to JF movies will correctly sync to ETV - A deep scan can be used to fix all movies, otherwise any future updates made to JF movies will correctly sync to ETV
- Automatically generate JWT tokens to allow channel previews of protected streams
### 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 ## [0.8.5-beta] - 2024-01-30
### Added ### Added

13
ErsatzTV/JwtHelper.cs

@ -1,3 +1,4 @@
using System.IdentityModel.Tokens.Jwt;
using System.Text; using System.Text;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
@ -17,4 +18,16 @@ public static class JwtHelper
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(issuerSigningKey!)); IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(issuerSigningKey!));
} }
} }
public static string GenerateToken()
{
var tokenHandler = new JwtSecurityTokenHandler();
var tokenDescriptor = new SecurityTokenDescriptor
{
Expires = DateTime.UtcNow.AddDays(1),
SigningCredentials = new SigningCredentials(IssuerSigningKey, SecurityAlgorithms.HmacSha256Signature)
};
SecurityToken token = tokenHandler.CreateToken(tokenDescriptor);
return tokenHandler.WriteToken(token);
}
} }

5
ErsatzTV/Pages/Channels.razor

@ -184,11 +184,10 @@
var uri = new UriBuilder(NavigationManager.ToAbsoluteUri(NavigationManager.Uri)); var uri = new UriBuilder(NavigationManager.ToAbsoluteUri(NavigationManager.Uri));
uri.Path = uri.Path.Replace("/channels", $"/iptv/channel/{channel.Number}.m3u8"); uri.Path = uri.Path.Replace("/channels", $"/iptv/channel/{channel.Number}.m3u8");
string query = uri.Query;
uri.Query = "?mode=segmenter"; uri.Query = "?mode=segmenter";
if (QueryHelpers.ParseQuery(query).TryGetValue("access_token", out StringValues token)) if (JwtHelper.IsEnabled)
{ {
uri.Query += $"&access_token={token.ToString()}"; uri.Query += $"&access_token={JwtHelper.GenerateToken()}";
} }
var parameters = new DialogParameters { { "StreamUri", uri.ToString() } }; var parameters = new DialogParameters { { "StreamUri", uri.ToString() } };

Loading…
Cancel
Save