auto generate jwt token for channel preview (#1588)

This commit is contained in:
Jason Dove
2024-01-31 15:08:23 -06:00
committed by GitHub
parent e0aa44d41b
commit d9bbe4df1b
3 changed files with 16 additions and 8 deletions
+1 -5
View File
@@ -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
- 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
### 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
- Automatically generate JWT tokens to allow channel previews of protected streams
## [0.8.5-beta] - 2024-01-30
### Added
+13
View File
@@ -1,3 +1,4 @@
using System.IdentityModel.Tokens.Jwt;
using System.Text;
using Microsoft.IdentityModel.Tokens;
@@ -17,4 +18,16 @@ public static class JwtHelper
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);
}
}
+2 -3
View File
@@ -184,11 +184,10 @@
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))
if (JwtHelper.IsEnabled)
{
uri.Query += $"&access_token={token.ToString()}";
uri.Query += $"&access_token={JwtHelper.GenerateToken()}";
}
var parameters = new DialogParameters { { "StreamUri", uri.ToString() } };