mirror of https://github.com/ErsatzTV/ErsatzTV.git
Browse Source
* JWT Auth * Standardized url variable additions * formatting and minor refactoring * this isn't needed * allow channel logos without auth * update changelog --------- Co-authored-by: Ministorm3 <4474921+Ministorm3@users.noreply.github.com>pull/1216/head
13 changed files with 188 additions and 31 deletions
@ -1,5 +1,5 @@ |
|||||||
using ErsatzTV.Core.Iptv; |
using ErsatzTV.Core.Iptv; |
||||||
|
|
||||||
namespace ErsatzTV.Application.Channels; |
namespace ErsatzTV.Application.Channels; |
||||||
|
|
||||||
public record GetChannelGuide(string Scheme, string Host, string BaseUrl) : IRequest<ChannelGuide>; |
public record GetChannelGuide(string Scheme, string Host, string BaseUrl, string AccessToken) : IRequest<ChannelGuide>; |
||||||
|
|||||||
@ -1,5 +1,5 @@ |
|||||||
using ErsatzTV.Core.Iptv; |
using ErsatzTV.Core.Iptv; |
||||||
|
|
||||||
namespace ErsatzTV.Application.Channels; |
namespace ErsatzTV.Application.Channels; |
||||||
|
|
||||||
public record GetChannelPlaylist(string Scheme, string Host, string BaseUrl, string Mode) : IRequest<ChannelPlaylist>; |
public record GetChannelPlaylist(string Scheme, string Host, string BaseUrl, string Mode, string AccessToken) : IRequest<ChannelPlaylist>; |
||||||
|
|||||||
@ -0,0 +1,25 @@ |
|||||||
|
using Microsoft.AspNetCore.Authorization; |
||||||
|
using Microsoft.AspNetCore.Mvc.Authorization; |
||||||
|
using Microsoft.AspNetCore.Mvc.Filters; |
||||||
|
|
||||||
|
namespace ErsatzTV.Filters; |
||||||
|
|
||||||
|
public class ConditionalIptvAuthorizeFilter : AuthorizeFilter |
||||||
|
{ |
||||||
|
public ConditionalIptvAuthorizeFilter(string policy) : base( |
||||||
|
new AuthorizationPolicyBuilder().RequireAuthenticatedUser().AddAuthenticationSchemes("jwt") |
||||||
|
.RequireAssertion(_ => JwtHelper.IsEnabled).Build()) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public override Task OnAuthorizationAsync(AuthorizationFilterContext context) |
||||||
|
{ |
||||||
|
// allow logos through without authorization, since they're also used in the management ui
|
||||||
|
if (JwtHelper.IsEnabled && !context.HttpContext.Request.Path.StartsWithSegments("/iptv/logos")) |
||||||
|
{ |
||||||
|
return base.OnAuthorizationAsync(context); |
||||||
|
} |
||||||
|
|
||||||
|
return Task.CompletedTask; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,20 @@ |
|||||||
|
using Microsoft.IdentityModel.Tokens; |
||||||
|
using System.Text; |
||||||
|
|
||||||
|
namespace ErsatzTV; |
||||||
|
|
||||||
|
public static class JwtHelper |
||||||
|
{ |
||||||
|
public static void Init(IConfiguration configuration) |
||||||
|
{ |
||||||
|
string issuerSigningKey = configuration["JWT:IssuerSigningKey"]; |
||||||
|
IsEnabled = !string.IsNullOrWhiteSpace(issuerSigningKey); |
||||||
|
if (IsEnabled) |
||||||
|
{ |
||||||
|
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(issuerSigningKey!)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static SymmetricSecurityKey IssuerSigningKey { get; private set; } |
||||||
|
public static bool IsEnabled { get; private set; } |
||||||
|
} |
||||||
Loading…
Reference in new issue