Provide NoResult instead of Fail in CustomAuthenticationHandler
This commit is contained in:
parent
0a35f35311
commit
38b3b4f867
|
@ -1,4 +1,5 @@
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -7,6 +8,7 @@ using Jellyfin.Data.Enums;
|
||||||
using MediaBrowser.Controller.Authentication;
|
using MediaBrowser.Controller.Authentication;
|
||||||
using MediaBrowser.Controller.Net;
|
using MediaBrowser.Controller.Net;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
|
@ -18,6 +20,7 @@ namespace Jellyfin.Api.Auth
|
||||||
public class CustomAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions>
|
public class CustomAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions>
|
||||||
{
|
{
|
||||||
private readonly IAuthService _authService;
|
private readonly IAuthService _authService;
|
||||||
|
private readonly ILogger<CustomAuthenticationHandler> _logger;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="CustomAuthenticationHandler" /> class.
|
/// Initializes a new instance of the <see cref="CustomAuthenticationHandler" /> class.
|
||||||
|
@ -35,6 +38,7 @@ namespace Jellyfin.Api.Auth
|
||||||
ISystemClock clock) : base(options, logger, encoder, clock)
|
ISystemClock clock) : base(options, logger, encoder, clock)
|
||||||
{
|
{
|
||||||
_authService = authService;
|
_authService = authService;
|
||||||
|
_logger = logger.CreateLogger<CustomAuthenticationHandler>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@ -70,11 +74,13 @@ namespace Jellyfin.Api.Auth
|
||||||
}
|
}
|
||||||
catch (AuthenticationException ex)
|
catch (AuthenticationException ex)
|
||||||
{
|
{
|
||||||
return Task.FromResult(AuthenticateResult.Fail(ex));
|
_logger.LogDebug(ex, "Error authenticating with {Handler}", nameof(CustomAuthenticationHandler));
|
||||||
|
return Task.FromResult(AuthenticateResult.NoResult());
|
||||||
}
|
}
|
||||||
catch (SecurityException ex)
|
catch (SecurityException ex)
|
||||||
{
|
{
|
||||||
return Task.FromResult(AuthenticateResult.Fail(ex));
|
_logger.LogDebug(ex, "Error authenticating with {Handler}", nameof(CustomAuthenticationHandler));
|
||||||
|
return Task.FromResult(AuthenticateResult.NoResult());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ namespace Jellyfin.Api.Tests.Auth
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task HandleAuthenticateAsyncShouldFailOnAuthenticationException()
|
public async Task HandleAuthenticateAsyncShouldProvideNoResultOnAuthenticationException()
|
||||||
{
|
{
|
||||||
var errorMessage = _fixture.Create<string>();
|
var errorMessage = _fixture.Create<string>();
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ namespace Jellyfin.Api.Tests.Auth
|
||||||
var authenticateResult = await _sut.AuthenticateAsync();
|
var authenticateResult = await _sut.AuthenticateAsync();
|
||||||
|
|
||||||
Assert.False(authenticateResult.Succeeded);
|
Assert.False(authenticateResult.Succeeded);
|
||||||
Assert.Equal(errorMessage, authenticateResult.Failure?.Message);
|
Assert.True(authenticateResult.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user