mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-16 05:53:03 +03:00
fix: use HttpContext and ClaimsPrincipal instead of IAuthorizationContext
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Security.Claims;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Api.Extensions;
|
||||
using Jellyfin.Data.Entities;
|
||||
using Jellyfin.Data.Enums;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
@@ -15,7 +17,6 @@ using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.MediaEncoding;
|
||||
using MediaBrowser.Controller.Net;
|
||||
using MediaBrowser.Model.Dlna;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Entities;
|
||||
@@ -39,7 +40,6 @@ namespace Jellyfin.Api.Helpers
|
||||
private readonly ILogger<MediaInfoHelper> _logger;
|
||||
private readonly INetworkManager _networkManager;
|
||||
private readonly IDeviceManager _deviceManager;
|
||||
private readonly IAuthorizationContext _authContext;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MediaInfoHelper"/> class.
|
||||
@@ -52,7 +52,6 @@ namespace Jellyfin.Api.Helpers
|
||||
/// <param name="logger">Instance of the <see cref="ILogger{MediaInfoHelper}"/> interface.</param>
|
||||
/// <param name="networkManager">Instance of the <see cref="INetworkManager"/> interface.</param>
|
||||
/// <param name="deviceManager">Instance of the <see cref="IDeviceManager"/> interface.</param>
|
||||
/// <param name="authContext">Instance of the <see cref="IAuthorizationContext"/> interface.</param>
|
||||
public MediaInfoHelper(
|
||||
IUserManager userManager,
|
||||
ILibraryManager libraryManager,
|
||||
@@ -61,8 +60,7 @@ namespace Jellyfin.Api.Helpers
|
||||
IServerConfigurationManager serverConfigurationManager,
|
||||
ILogger<MediaInfoHelper> logger,
|
||||
INetworkManager networkManager,
|
||||
IDeviceManager deviceManager,
|
||||
IAuthorizationContext authContext)
|
||||
IDeviceManager deviceManager)
|
||||
{
|
||||
_userManager = userManager;
|
||||
_libraryManager = libraryManager;
|
||||
@@ -72,7 +70,6 @@ namespace Jellyfin.Api.Helpers
|
||||
_logger = logger;
|
||||
_networkManager = networkManager;
|
||||
_deviceManager = deviceManager;
|
||||
_authContext = authContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -147,7 +144,7 @@ namespace Jellyfin.Api.Helpers
|
||||
/// <param name="item">Item to set data for.</param>
|
||||
/// <param name="mediaSource">Media source info.</param>
|
||||
/// <param name="profile">Device profile.</param>
|
||||
/// <param name="auth">Authorization info.</param>
|
||||
/// <param name="claimsPrincipal">Current claims principal.</param>
|
||||
/// <param name="maxBitrate">Max bitrate.</param>
|
||||
/// <param name="startTimeTicks">Start time ticks.</param>
|
||||
/// <param name="mediaSourceId">Media source id.</param>
|
||||
@@ -166,7 +163,7 @@ namespace Jellyfin.Api.Helpers
|
||||
BaseItem item,
|
||||
MediaSourceInfo mediaSource,
|
||||
DeviceProfile profile,
|
||||
AuthorizationInfo auth,
|
||||
ClaimsPrincipal claimsPrincipal,
|
||||
int? maxBitrate,
|
||||
long startTimeTicks,
|
||||
string mediaSourceId,
|
||||
@@ -188,7 +185,7 @@ namespace Jellyfin.Api.Helpers
|
||||
{
|
||||
MediaSources = new[] { mediaSource },
|
||||
Context = EncodingContext.Streaming,
|
||||
DeviceId = auth.DeviceId,
|
||||
DeviceId = claimsPrincipal.GetDeviceId(),
|
||||
ItemId = item.Id,
|
||||
Profile = profile,
|
||||
MaxAudioChannels = maxAudioChannels,
|
||||
@@ -290,7 +287,7 @@ namespace Jellyfin.Api.Helpers
|
||||
mediaSource.SupportsDirectPlay = false;
|
||||
mediaSource.SupportsDirectStream = false;
|
||||
|
||||
mediaSource.TranscodingUrl = streamInfo.ToUrl("-", auth.Token).TrimStart('-');
|
||||
mediaSource.TranscodingUrl = streamInfo.ToUrl("-", claimsPrincipal.GetToken()).TrimStart('-');
|
||||
mediaSource.TranscodingUrl += "&allowVideoStreamCopy=false";
|
||||
mediaSource.TranscodingUrl += "&allowAudioStreamCopy=false";
|
||||
mediaSource.TranscodingContainer = streamInfo.Container;
|
||||
@@ -301,7 +298,7 @@ namespace Jellyfin.Api.Helpers
|
||||
if (!mediaSource.SupportsDirectPlay && (mediaSource.SupportsTranscoding || mediaSource.SupportsDirectStream))
|
||||
{
|
||||
streamInfo.PlayMethod = PlayMethod.Transcode;
|
||||
mediaSource.TranscodingUrl = streamInfo.ToUrl("-", auth.Token).TrimStart('-');
|
||||
mediaSource.TranscodingUrl = streamInfo.ToUrl("-", claimsPrincipal.GetToken()).TrimStart('-');
|
||||
|
||||
if (!allowVideoStreamCopy)
|
||||
{
|
||||
@@ -316,7 +313,7 @@ namespace Jellyfin.Api.Helpers
|
||||
}
|
||||
|
||||
// Do this after the above so that StartPositionTicks is set
|
||||
SetDeviceSpecificSubtitleInfo(streamInfo, mediaSource, auth.Token);
|
||||
SetDeviceSpecificSubtitleInfo(streamInfo, mediaSource, claimsPrincipal.GetToken());
|
||||
mediaSource.DefaultAudioStreamIndex = streamInfo.AudioStreamIndex;
|
||||
}
|
||||
|
||||
@@ -384,19 +381,17 @@ namespace Jellyfin.Api.Helpers
|
||||
/// <summary>
|
||||
/// Open media source.
|
||||
/// </summary>
|
||||
/// <param name="httpRequest">Http Request.</param>
|
||||
/// <param name="httpContext">Http Context.</param>
|
||||
/// <param name="request">Live stream request.</param>
|
||||
/// <returns>A <see cref="Task"/> containing the <see cref="LiveStreamResponse"/>.</returns>
|
||||
public async Task<LiveStreamResponse> OpenMediaSource(HttpRequest httpRequest, LiveStreamRequest request)
|
||||
public async Task<LiveStreamResponse> OpenMediaSource(HttpContext httpContext, LiveStreamRequest request)
|
||||
{
|
||||
var authInfo = await _authContext.GetAuthorizationInfo(httpRequest).ConfigureAwait(false);
|
||||
|
||||
var result = await _mediaSourceManager.OpenLiveStream(request, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
var profile = request.DeviceProfile;
|
||||
if (profile == null)
|
||||
{
|
||||
var clientCapabilities = _deviceManager.GetCapabilities(authInfo.DeviceId);
|
||||
var clientCapabilities = _deviceManager.GetCapabilities(httpContext.User.GetDeviceId());
|
||||
if (clientCapabilities != null)
|
||||
{
|
||||
profile = clientCapabilities.DeviceProfile;
|
||||
@@ -411,7 +406,7 @@ namespace Jellyfin.Api.Helpers
|
||||
item,
|
||||
result.MediaSource,
|
||||
profile,
|
||||
authInfo,
|
||||
httpContext.User,
|
||||
request.MaxStreamingBitrate,
|
||||
request.StartTimeTicks ?? 0,
|
||||
result.MediaSource.Id,
|
||||
@@ -425,7 +420,7 @@ namespace Jellyfin.Api.Helpers
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
httpRequest.HttpContext.GetNormalizedRemoteIp());
|
||||
httpContext.GetNormalizedRemoteIp());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user