aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Api/Auth
diff options
context:
space:
mode:
authorcvium <clausvium@gmail.com>2021-09-10 11:40:28 +0200
committercvium <clausvium@gmail.com>2021-09-10 11:40:28 +0200
commit8496d7638ab7823169c220b615289c401cefa9a0 (patch)
tree66134cb10250319dc4be0dc8abf6b2a6573e4cbf /Jellyfin.Api/Auth
parentfb7587dd84784afb7c64aadf1fc2d0bab5251814 (diff)
parentb96dbbf553820861eab9d1a453adcc8ce8a9ef05 (diff)
Merge branch 'master' into NetworkAccessPolicy
Diffstat (limited to 'Jellyfin.Api/Auth')
-rw-r--r--Jellyfin.Api/Auth/BaseAuthorizationHandler.cs5
-rw-r--r--Jellyfin.Api/Auth/CustomAuthenticationHandler.cs10
2 files changed, 8 insertions, 7 deletions
diff --git a/Jellyfin.Api/Auth/BaseAuthorizationHandler.cs b/Jellyfin.Api/Auth/BaseAuthorizationHandler.cs
index 456f45d97..62d590b18 100644
--- a/Jellyfin.Api/Auth/BaseAuthorizationHandler.cs
+++ b/Jellyfin.Api/Auth/BaseAuthorizationHandler.cs
@@ -87,8 +87,9 @@ namespace Jellyfin.Api.Auth
return false;
}
- var ip = _httpContextAccessor.HttpContext.GetNormalizedRemoteIp();
- var isInLocalNetwork = _networkManager.IsInLocalNetwork(ip);
+ var isInLocalNetwork = _httpContextAccessor.HttpContext != null
+ && _networkManager.IsInLocalNetwork(_httpContextAccessor.HttpContext.GetNormalizedRemoteIp());
+
// User cannot access remotely and user is remote
if (!user.HasPermission(PermissionKind.EnableRemoteAccess) && !isInLocalNetwork)
{
diff --git a/Jellyfin.Api/Auth/CustomAuthenticationHandler.cs b/Jellyfin.Api/Auth/CustomAuthenticationHandler.cs
index c56233794..369e846ae 100644
--- a/Jellyfin.Api/Auth/CustomAuthenticationHandler.cs
+++ b/Jellyfin.Api/Auth/CustomAuthenticationHandler.cs
@@ -40,11 +40,11 @@ namespace Jellyfin.Api.Auth
}
/// <inheritdoc />
- protected override Task<AuthenticateResult> HandleAuthenticateAsync()
+ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
{
try
{
- var authorizationInfo = _authService.Authenticate(Request);
+ var authorizationInfo = await _authService.Authenticate(Request).ConfigureAwait(false);
var role = UserRoles.User;
if (authorizationInfo.IsApiKey || authorizationInfo.User.HasPermission(PermissionKind.IsAdministrator))
{
@@ -68,16 +68,16 @@ namespace Jellyfin.Api.Auth
var principal = new ClaimsPrincipal(identity);
var ticket = new AuthenticationTicket(principal, Scheme.Name);
- return Task.FromResult(AuthenticateResult.Success(ticket));
+ return AuthenticateResult.Success(ticket);
}
catch (AuthenticationException ex)
{
_logger.LogDebug(ex, "Error authenticating with {Handler}", nameof(CustomAuthenticationHandler));
- return Task.FromResult(AuthenticateResult.NoResult());
+ return AuthenticateResult.NoResult();
}
catch (SecurityException ex)
{
- return Task.FromResult(AuthenticateResult.Fail(ex));
+ return AuthenticateResult.Fail(ex);
}
}
}