Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't throw exception on unauthenticated requests #6837

Merged
merged 1 commit into from
Nov 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task<AuthorizationInfo> Authenticate(HttpRequest request)

if (!auth.HasToken)
{
throw new AuthenticationException("Request does not contain a token.");
return auth;
}

if (!auth.IsAuthenticated)
Expand Down
7 changes: 6 additions & 1 deletion Emby.Server.Implementations/HttpServer/WebSocketManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ public class WebSocketManager : IWebSocketManager
/// <inheritdoc />
public async Task WebSocketRequestHandler(HttpContext context)
{
_ = await _authService.Authenticate(context.Request).ConfigureAwait(false);
var authorizationInfo = await _authService.Authenticate(context.Request).ConfigureAwait(false);
if (!authorizationInfo.IsAuthenticated)
{
throw new SecurityException("Token is required");
}

try
{
_logger.LogInformation("WS {IP} request", context.Connection.RemoteIpAddress);
Expand Down
5 changes: 5 additions & 0 deletions Jellyfin.Api/Auth/CustomAuthenticationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
try
{
var authorizationInfo = await _authService.Authenticate(Request).ConfigureAwait(false);
if (!authorizationInfo.HasToken)
{
return AuthenticateResult.NoResult();
}

var role = UserRoles.User;
if (authorizationInfo.IsApiKey || authorizationInfo.User.HasPermission(PermissionKind.IsAdministrator))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ private AuthorizationInfo SetupUser(bool isAdmin = false)
authorizationInfo.User.AddDefaultPreferences();
authorizationInfo.User.SetPermission(PermissionKind.IsAdministrator, isAdmin);
authorizationInfo.IsApiKey = false;
authorizationInfo.HasToken = true;
authorizationInfo.Token = "fake-token";

_jellyfinAuthServiceMock.Setup(
a => a.Authenticate(
Expand Down