Merge pull request #4629 from crobibero/auth-handler

Provide NoResult instead of Fail in CustomAuthenticationHandler
This commit is contained in:
Claus Vium
2020-12-01 23:44:52 +01:00
committed by GitHub
5 changed files with 22 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
#pragma warning disable CS1591
using System;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Authentication;
using MediaBrowser.Controller.Net;
@@ -20,9 +21,15 @@ namespace Emby.Server.Implementations.HttpServer.Security
public AuthorizationInfo Authenticate(HttpRequest request)
{
var auth = _authorizationContext.GetAuthorizationInfo(request);
if (!auth.HasToken)
{
throw new AuthenticationException("Request does not contain a token.");
}
if (!auth.IsAuthenticated)
{
throw new AuthenticationException("Invalid token.");
throw new SecurityException("Invalid token.");
}
if (auth.User?.HasPermission(PermissionKind.IsDisabled) ?? false)

View File

@@ -102,7 +102,8 @@ namespace Emby.Server.Implementations.HttpServer.Security
DeviceId = deviceId,
Version = version,
Token = token,
IsAuthenticated = false
IsAuthenticated = false,
HasToken = false
};
if (string.IsNullOrWhiteSpace(token))
@@ -111,6 +112,7 @@ namespace Emby.Server.Implementations.HttpServer.Security
return authInfo;
}
authInfo.HasToken = true;
var result = _authRepo.Get(new AuthenticationInfoQuery
{
AccessToken = token