aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server.Implementations/Security/AuthorizationContext.cs
diff options
context:
space:
mode:
authorPatrick Barron <barronpm@gmail.com>2021-05-21 00:09:11 -0400
committerPatrick Barron <barronpm@gmail.com>2021-05-21 00:19:07 -0400
commitb6446c06eeddae46e4ee1d6ec65182a53cd74e51 (patch)
tree3a18cb940e04cf2c2412fc52da63b5b4d0009f4c /Jellyfin.Server.Implementations/Security/AuthorizationContext.cs
parenta0c6f7276211ac0429877fafa400368aba1430a9 (diff)
parenta937a854f2582a8770d9ada7c24375065a21f7a5 (diff)
Merge branch 'master' into authenticationdb-efcore
# Conflicts: # Emby.Server.Implementations/Security/AuthenticationRepository.cs # Jellyfin.Server.Implementations/Security/AuthorizationContext.cs # MediaBrowser.Controller/Devices/IDeviceManager.cs
Diffstat (limited to 'Jellyfin.Server.Implementations/Security/AuthorizationContext.cs')
-rw-r--r--Jellyfin.Server.Implementations/Security/AuthorizationContext.cs40
1 files changed, 18 insertions, 22 deletions
diff --git a/Jellyfin.Server.Implementations/Security/AuthorizationContext.cs b/Jellyfin.Server.Implementations/Security/AuthorizationContext.cs
index 775edafc2..688ff7168 100644
--- a/Jellyfin.Server.Implementations/Security/AuthorizationContext.cs
+++ b/Jellyfin.Server.Implementations/Security/AuthorizationContext.cs
@@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
+using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net;
using Microsoft.AspNetCore.Http;
@@ -207,7 +208,7 @@ namespace Jellyfin.Server.Implementations.Security
auth = httpReq.Request.Headers[HeaderNames.Authorization];
}
- return GetAuthorization(auth);
+ return auth.Count > 0 ? GetAuthorization(auth[0]) : null;
}
/// <summary>
@@ -224,7 +225,7 @@ namespace Jellyfin.Server.Implementations.Security
auth = httpReq.Headers[HeaderNames.Authorization];
}
- return GetAuthorization(auth);
+ return auth.Count > 0 ? GetAuthorization(auth[0]) : null;
}
/// <summary>
@@ -232,43 +233,38 @@ namespace Jellyfin.Server.Implementations.Security
/// </summary>
/// <param name="authorizationHeader">The authorization header.</param>
/// <returns>Dictionary{System.StringSystem.String}.</returns>
- private Dictionary<string, string>? GetAuthorization(string? authorizationHeader)
+ private Dictionary<string, string>? GetAuthorization(ReadOnlySpan<char> authorizationHeader)
{
- if (authorizationHeader == null)
- {
- return null;
- }
-
- var parts = authorizationHeader.Split(' ', 2);
+ var firstSpace = authorizationHeader.IndexOf(' ');
- // There should be at least to parts
- if (parts.Length != 2)
+ // There should be at least two parts
+ if (firstSpace == -1)
{
return null;
}
- var acceptedNames = new[] { "MediaBrowser", "Emby" };
+ var name = authorizationHeader[..firstSpace];
- // It has to be a digest request
- if (!acceptedNames.Contains(parts[0], StringComparer.OrdinalIgnoreCase))
+ if (!name.Equals("MediaBrowser", StringComparison.OrdinalIgnoreCase)
+ && !name.Equals("Emby", StringComparison.OrdinalIgnoreCase))
{
return null;
}
- // Remove uptil the first space
- authorizationHeader = parts[1];
- parts = authorizationHeader.Split(',');
+ authorizationHeader = authorizationHeader[(firstSpace + 1)..];
var result = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
- foreach (var item in parts)
+ foreach (var item in authorizationHeader.Split(','))
{
- var param = item.Trim().Split('=', 2);
+ var trimmedItem = item.Trim();
+ var firstEqualsSign = trimmedItem.IndexOf('=');
- if (param.Length == 2)
+ if (firstEqualsSign > 0)
{
- var value = NormalizeValue(param[1].Trim('"'));
- result[param[0]] = value;
+ var key = trimmedItem[..firstEqualsSign].ToString();
+ var value = NormalizeValue(trimmedItem[(firstEqualsSign + 1)..].Trim('"').ToString());
+ result[key] = value;
}
}